Topic: Limit the number of open positions.
Hi,
i am using counting deals on portfolio ea on mql4 this code
void OpenOrdersResults()
{
//------------------------------------------------------
SumOrders=0;
BuyOrders=0;
SellOrders=0;
TypeLastOrder=-1;
PipsBuyOrders=0;
PipsSellOrders=0;
PipsLastBuyOrders=0;
PipsLastSellOrders=0;
ProfitBuyOrders=0;
ProfitSellOrders=0;
SumFloating=0;
//---
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
const int magicNumber = OrderMagicNumber();
if(OrderSymbol()==Symbol() && (magicsize * Magic <= magicNumber && magicNumber < (magicsize * Magic + strategiesCount)))
{
TypeLastOrder=OrderType();
if(OrderType()==OP_BUY)
{
// PipsLastBuyOrders=(Bid-OrderOpenPrice())/pip;
// PipsBuyOrders+=(Bid-OrderOpenPrice())/pip;
// ProfitBuyOrders+=OrderProfit()+OrderCommission()+OrderSwap();
BuyOrders++;
}
if(OrderType()==OP_SELL)
{
// PipsLastSellOrders=(OrderOpenPrice()-Ask)/pip;
// PipsSellOrders+=(OrderOpenPrice()-Ask)/pip;
// ProfitSellOrders+=OrderProfit()+OrderCommission()+OrderSwap();
SellOrders++;
}
SumOrders++;
SumFloating+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
now i am struggling to get this code in mql5 for new portfolio ea..
i need this cause i am managing the open orders..
EnableMaxPositionsPerBar = false;
MaxPositionsPerBar = 2; // Set Max Open Position per Bar
EnableMaxBuyPositions = false;
MaxBuyPositions = 6; // Set Max Open Long Positions
EnableMaxSellPositions = false;
MaxSellPositions = 7; // Set Max Open Short Positions
EnableTotalPositions = false;
TotalPositions = 10; // Set Max Open Positions
so i need it so i can change during running the ea that he not open more thax x posi at same time or only open longs or open short and at on bar ea porfolio can open x positions per bar..sometimes if portfolio is big ea opens 20-30 positions at once.