modify stop loss not working - page 2

 
micobez:

yea its only for buy orders,

And the issue it has is it modifies the order immediately without meeting conditions and when it modifies it only removes the stop loss for some reason

The only way that I see that is possible is if profit,profit2 are both zero.

Check their values.

 
double profit=MathAbs(bot-MathMax(close1,open1))+open;
double profit2=open+2*MathAbs(open-bot);

Thats what they are 

open is open 0 

bot is the bottom value of a trend

they are both dynamic and are set as the distance of start trade from the original stoploss*2 
 
micobez:

Do not double post.

I have deleted the new topic.

 
Keith Watford:

The only way that I see that is possible is if profit,profit2 are both zero.

Check their values.

Have you actually checked their values?

I don't mean check the calculations, I mean print their actual values to the log as I believe that they are being calculated to zero.

Are you calculating with ints and expecting the result to be a double?

Always use 

#property strict

as the earlier code will not compile with it as it is missing some braces.

   for(int x=0; x<=OrdersTotal()-1; x++)
     {
      if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderClosePrice()>OrderOpenPrice()+0.6*MathMax(profit,profit2))
           {
            double nSL=OrderOpenPrice()+0.5*MathMax(profit,profit2);
            if(nSL-OrderStopLoss()>=_Point)
               if(!OrderModify(OrderTicket(),OrderOpenPrice(),nSL,OrderTakeProfit(),0,Blue))
                  Print("Modifying SL on Ticket #",OrderTicket()," failed. Error Code ",GetLastError());
           }
        }
     }
Reason: