Need help correcting code

 
I'm new to this code writing so there might be some things wrong with this code. However, what I'm trying to do is modify stop orders (long and shorts) that can move at the same time regardles of where price is going. As of right now on the open of the candle if will change both. But say, when it goes up one pip it will adjust above only and when it goes down past the open it will adj below and so on. Is there a way make it change and keep the same distance above and below regarldes of where the price is going? I hope I'm making sense.


Any help greatly appreciated

 
int start()
  {
   
   int    cmd,total,error;
   
   double h,l,ho,lo,sp;
   
   
   h=iHigh(NULL,PERIOD_M1,0);
   l=iLow(NULL,PERIOD_M1,0);
   sp=Ask-Bid;
  
   
   
//----
 
   total=OrdersTotal();
   
//----
   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         //---- print selected order
         OrderPrint();
         cmd=OrderType();
         //---- buy or sell orders are considered
         if(cmd==OP_BUYSTOP || cmd==OP_SELLSTOP)
           
             
               if(cmd==OP_BUYSTOP)  ho=h+sp+10*Point;
                 { 
                  OrderModify(OrderTicket(),ho,0,0,0,Red);
                  error=GetLastError();
                  Print("error(",error,"): ",ErrorDescription(error));
                  Sleep(1000);
                 }
              
               if(cmd==OP_SELLSTOP) lo=l-10*Point;
                 { 
                  OrderModify(OrderTicket(),lo,0,0,0,Red);
                  error=GetLastError();
                  Print("error(",error,"): ",ErrorDescription(error));
                  Sleep(1000);
                 }
                 
        }
            
     }
//----
   return(0);
  }
 
saunga2nd:
I'm new to this code writing so there might be some things wrong with this code. However, what I'm trying to do is modify stop orders (long and shorts) that can move at the same time regardles of where price is going. As of right now on the open of the candle if will change both. But say, when it goes up one pip it will adjust above only and when it goes down past the open it will adj below and so on. Is there a way make it change and keep the same distance above and below regarldes of where the price is going? I hope I'm making sense.


keeping always the same distance from above and below? it doesn't make sense. If you have a pending order above 10 pips from high and below 10 pips from low then what is the point of it? it never hits because it is always running away...
if you want to change a buy-stop as price makes new low and bring it down a little, this is different story and must programmed a little bit different as your code above...

And think why is your code changing pending orders at open a new trade -- maybe because at first moment high=low=open=close??
 
Sorry for the delay. It's supposed to be a breakout ea and it's missing the variable for the time of day. The purpose of this ea is not to wander with price.

What do you mean by "... maybe because at first moment high=low=open=close??"

Do you know how to acomplish what I described?
 

The way your code is structured it is kind of incomprehensible.

Maybe you meant to say:

if(cmd==OP_BUYSTOP || cmd==OP_SELLSTOP)

{
if(cmd==OP_BUYSTOP)
{
ho=h+sp+10*Point;
OrderModify(OrderTicket(),ho,0,0,0,Red);
error=GetLastError();
Print("error(",error,"): ",ErrorDescription(error));
Sleep(1000);
}

if(cmd==OP_SELLSTOP)
{
lo=l-10*Point;
OrderModify(OrderTicket(),lo,0,0,0,Red);
error=GetLastError();
Print("error(",error,"): ",ErrorDescription(error));
Sleep(1000);
}
}

Reason: