Hi gurus here,my ea couldn't add position correctly,before it run add positon's code, it would close the former order,
//here is my sell condition
if (m1<m3-0.00005)
{
ticket1=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+1050*Point,0,"SELL#1",MAGICMA,0,Red);return;
/*it will open continuously 2 orders under "CalculateCurrentOrders(Symbol())<2" but the add position code (as follow)seems don't take effect */
if(Ask>OrderOpenPrice()+300*Point)
{ticket2=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+1050*Point,0,"SELL#2",MAGICMA,0,Green); return; }
//and the TS() as follow : also only run after close one order under "CalculateCurrentOrders(Symbol())<2"
void TS(double ts=550)
{
bool res = false;
int total = OrdersTotal();
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--)
{
if (OrderSelect(pos, SELECT_BY_POS,MODE_TRADES)
&& OrderMagicNumber() == MAGICMA
&& OrderSymbol() == Symbol() )
{
if(OrderType()==OP_BUY)
{
if(Bid-Point*ts>OrderOpenPrice() &&
Bid-Point*ts>OrderStopLoss())
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*ts,OrderTakeProfit(),0);
}
}
else if(OrderType()==OP_SELL)
{
if(Ask+Point*ts<OrderOpenPrice() &&
Ask+Point*ts<OrderStopLoss())
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*ts,OrderTakeProfit(),0);
}
}
}
}
}
and the my TS() function would appear similar state only take effect after close one order.
I guess this error is connect with the cycle control,but I am not sure for it .guys who can help me,appreciating.
//here is my sell condition
if (m1<m3-0.00005)
{
ticket1=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+1050*Point,0,"SELL#1",MAGICMA,0,Red);return;
/*it will open continuously 2 orders under "CalculateCurrentOrders(Symbol())<2" but the add position code (as follow)seems don't take effect */
if(Ask>OrderOpenPrice()+300*Point)
{ticket2=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+1050*Point,0,"SELL#2",MAGICMA,0,Green); return; }
//and the TS() as follow : also only run after close one order under "CalculateCurrentOrders(Symbol())<2"
void TS(double ts=550)
{
bool res = false;
int total = OrdersTotal();
for(int pos = OrdersTotal()-1; pos >= 0 ; pos--)
{
if (OrderSelect(pos, SELECT_BY_POS,MODE_TRADES)
&& OrderMagicNumber() == MAGICMA
&& OrderSymbol() == Symbol() )
{
if(OrderType()==OP_BUY)
{
if(Bid-Point*ts>OrderOpenPrice() &&
Bid-Point*ts>OrderStopLoss())
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*ts,OrderTakeProfit(),0);
}
}
else if(OrderType()==OP_SELL)
{
if(Ask+Point*ts<OrderOpenPrice() &&
Ask+Point*ts<OrderStopLoss())
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*ts,OrderTakeProfit(),0);
}
}
}
}
}
and the my TS() function would appear similar state only take effect after close one order.
I guess this error is connect with the cycle control,but I am not sure for it .guys who can help me,appreciating.