why add position's strategy is fail?

 

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.

 

no body could help?

 

Well, I couldn't understand the code. What's m1? m3?

if after return? probably never gets executed

TS function defined inside if block? are these code fragments pasted together?

If a poster won't spend the time giving me all the help they can, I'm not inclined to spend my time guessing what they meant

 
brewmanz:

Well, I couldn't understand the code. What's m1? m3?

if after return? probably never gets executed

TS function defined inside if block? are these code fragments pasted together?

If a poster won't spend the time giving me all the help they can, I'm not inclined to spend my time guessing what they meant


These are some parts of the whole code,m1/m3 are indicators,the whold code is no error,no warning.the basic problem is add lots strategy as follows couldn't take effects.

if(Ask>OrderOpenPrice()+300*Point)
{ticket2=OrderSend(Symbol(),OP_SELL,1,Bid,5,Ask+1050*Point,0,"SELL#2",MAGICMA,0,Green); return; }
and TS() also only run after close one close under" CalculateCurrentOrders(Symbol())<2",but if modify it into"CalculateCurrentOrders(Symbol())<1" the TS() also couldn't work.

PLS,gurus help,TKS!

Reason: