ModifyOrder Error 4051 & 4108 - page 2

 
Keith Watford:

I have deleted your new topic.

If you can't resolve your problems here, starting a new topic will not bring any different results.

Okay Keith, I posted my code for whroeder1 but he didn't respond. Could you possibly help me?
 
C0mput3r:
Okay Keith, I posted my code for whroeder1 but he didn't respond. Could you possibly help me?
This is where I am stuck at the moment, I'm not sure why code won't move my SL to breakeven once it passes my TrailingStop mark.
//************************************************************  
//EXECUTE SELL CONDITION
//************************************************************
        {                              
        if( sell_condition_1 && sell_condition_2 && sell_condition_3 && sell_condition_4 && sell_condition_5 && sell_condition_6 && sell_condition_7)
        {
        
            double ShortStopLoss =  Bid + (StopLoss * Point*10);
            double ShortTakeProfit = Bid - (TakeProfit * Point*10);
                                      
      //-------------------------------------------------------------------------------------------------------------------  
      //-------------------------------------------------------------------------------------------------------------------
      ShortTicket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,ShortStopLoss,ShortTakeProfit,"Sell Order",MagicNumber,0,Red);
      //-------------------------------------------------------------------------------------------------------------------        
      //-------------------------------------------------------------------------------------------------------------------            
                          
                           double ShortOpen = OrderOpenPrice();
                          
                           for(int S = OrdersTotal()-1; S >= 0; S--)
                          
                           OrderSelect(S,SELECT_BY_POS, MODE_TRADES);
                          
                           {
                           if((ShortOpen-Ask)>TrailingStop*Point*10)
            {
              
              int res=OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+(Point*(TrailingStop)*10)),OrderTakeProfit(),0,Blue);
              if(!res)
                    Print("Error in OrderModify. Error code=",GetLastError());
              else
                    Print("Order modified successfully.");
            }
                      
                      }
 

Your formatting is a total mess. What are you trying to do, make it pretty or something?

IF you remove all that crap and format it sensibly


   if(sell_condition_1 && sell_condition_2 && sell_condition_3 && sell_condition_4 && sell_condition_5 && sell_condition_6 && sell_condition_7)
     {
      double ShortStopLoss=Bid+(StopLoss*Point*10);
      double ShortTakeProfit=Bid -(TakeProfit*Point*10);

      ShortTicket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,ShortStopLoss,ShortTakeProfit,"Sell Order",MagicNumber,0,Red);     

      double ShortOpen=OrderOpenPrice();

      for(int S=OrdersTotal()-1; S>=0; S--)
         OrderSelect(S,SELECT_BY_POS,MODE_TRADES);
        {
         if((ShortOpen-Ask)>TrailingStop*Point*10)
           {

            int res=OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+(Point*(TrailingStop)*10)),OrderTakeProfit(),0,Blue);
            if(!res)
               Print("Error in OrderModify. Error code=",GetLastError());
            else
               Print("Order modified successfully.");
           }
        }


you find exactly as WHRoeder has already told you.

The whole block of code is reliant on the very first if, so the break even will only be checked immediatley after the order is opened.

 
C0mput3r: Okay Keith, I posted my code for whroeder1 but he didn't respond. Could you possibly help me?
This isn't a service desk, people have to sleep.
  1. Asked and answered. #8/Item 5/Last line: You check your conditions, open an order, and immediately try to trail it.
  2. The trail code must not be inside condition.
  3. Had you printed your variable like I suggested, you would have know the trailing code isn't being called.