Problem with OrderClose() - page 2

 
drkenyi:

Yes you're right, but only in that case if the position, recalculated by the broker is works, the way you think it works(it is not documented). If the developers of MQL4 made some recalculation somehow else way, then it's a little bit questionable.

I don't understand exactly what u r trying to say, but this method is documented and it works (and there is no question about it).

 

Thank you very much for the help guys, now everything with orderclose works, but i have a new problem :)

i try to enter trailling stop, i created one function that sould put trailling stop on long or short position, but of course it doesn't works :( i paste here this code and i hope you could help me. :)

The function returns me error code 130.

void AddTrailingStop()
 {
   if(TrailingStop>0)  
      { 
    for(int cnt=(OrdersTotal()-1);cnt>=0;cnt--)
            {
             if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false)
             {
             Print("Problem with order select :",cnt);
      
              continue;

             }
                if(OrderType()==OP_BUY && OrderSymbol()==Symbol())   // long position is opened
                  {           
                      if(Bid-OrderOpenPrice()>Point*TrailingStop)
                        {
                         if(OrderStopLoss()<Bid-Point*TrailingStop)
                           {
                            OrderModify(OrderTicket(),OrderOpenPrice(),(Bid-Point*TrailingStop),OrderTakeProfit(),0,Green);
                            return(1);//Returns 1 if function is succeed for short position
                           }
                        }
                     }
                  else if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
                  { 
                      if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                        {
                         if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                           {
                            OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+Point*TrailingStop),OrderTakeProfit(),0,Red);
                            return(2);//Returns 2 if function is succeed for short position
                           }
                        }
                  }
               }
            }
    return(0);     
 }
 
HLA wrote >>

Thank you very much for the help guys, now everything with orderclose works, but i have a new problem :)

i try to enter trailling stop, i created one function that sould put trailling stop on long or short position, but of course it doesn't works :( i paste here this code and i hope you could help me. :)

The function returns me error code 130.

ERR_INVALID_STOPS

Trailingstop is greater then STOP_LEVEL (see MarketInfo)?

 

Yes i found where is the problem, just variable Point has value 0.00001 and in my case TrailingStop was equal to 30, and 30*0.00001 = 3 pips this too small number for OrderModify!!! I saw it in one from examples in the site :( https://www.mql5.com/en/articles/1527

Once again thank you for the help, and i hope that you'll be so helpful next time when i have a question abot MQL :)

Have good night ;)