Need help coding

 

Hi, i am trying to code a simple EA but i am learning and i would like some help. The problem is that i want the stop loss to be updated to "stop" value each new bar. I have tried this, but i dont understand well how orderselect and ordermodify works very well yet.


The idea is when price == entry it will open 3 orders. 1- with tp1 and stop value sl, 2- with tp2 and stop value sl, 3- with no tp and stop value sl. Now each bar i want those 3 orders Stop loss to be updated to "stop" parameter value.



void OnTick()
  {

      double entry = iCustom(NULL,0,"entry",11,0);
      double stop = iCustom(NULL,0,"stop",1,0);
      double tp1 = iCustom(NULL,0,"tp1",7,0);
      double tp2 = iCustom(NULL,0,"tp2",9,0);
      
      if (Ask == entry && OrdersTotal() == 0)
      int buyticket = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,tp1, NULL, 0, 0, Green);
         
      if (Ask == entry && OrdersTotal() == 1)
      int buyticket2 = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,tp2, NULL, 0, 0, Green);   
      
      if (Ask == entry && OrdersTotal() == 2)
      int buyticket3 = OrderSend
         (Symbol(), OP_BUY, 0.01, Ask, 3,stop,0, NULL, 0, 0, Green);  
         

      for (int i = OrdersTotal() - 1; i >= 0; i--);
      {
      // Select an order by index i, selecting by position and from the pool of market trades.
      // If the selection is successful, proceed with the update.
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
          
         // Check if the order is for the current chart's currency pair.
         if (OrderSymbol() == Symbol())
            double OpenPrice = entry;
            double StopLossPrice = stop; //new stop loss
            
            
            // Order expiration is a required parameter, so pass the current value via OrderExpiration() function.
           if(OrdersTotal() > 0)
           OrderModify(OrderTicket(), OpenPrice, stop, 0, OrderExpiration())
        
        }
    }


    

 
iberhack:

Hi, i am trying to code a simple EA but i am learning and i would like some help. The problem is that i want the stop loss to be updated to "stop" value each new bar. I have tried this, but i dont understand well how orderselect and ordermodify works very well yet.


The idea is when price == entry it will open 3 orders. 1- with tp1 and stop value sl, 2- with tp2 and stop value sl, 3- with no tp and stop value sl. Now each bar i want those 3 orders Stop loss to be updated to "stop" parameter value.




    

With OrderMagicNumber, it is possible to see whether orders exist or not, and in a separate function, new bar formation and stop updates can be made.

Reason: