changing stop loss

 
Hi, I'm having trouble creating a script that will change the stop loss of my orders. I keep getting error number 4109. Here is the part of the script that is giving me trouble.

for (i = 0; i < ordersTotal; i++)
         {
            //select the order 
            if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES))
            {
               //get the right order 
               if(OrderSymbol() ==  Symbol())
               {
                  //remember the old stop loss.                  
                  originalSP = OrderStopLoss();
                  //update the stop loss
                  if(OrderType() == OP_BUY)
                  {
                     newSP = Bid-(Point * 30);
                     if(originalSP > newSP)
                     {
                        newSP = originalSP;                        
                     }
                  }else if(OrderType() == OP_SELL)
                  {
                     newSP = Bid+(Point * 30);
                     if(originalSP < newSP)
                     {
                        newSP = originalSP;
                     }
                  }
                  Print("new stop loss for ",Symbol(), " at ", newSP);
                  if(!OrderModify(OrderTicket(), 0,newSP, 0, 0, 0))
                  {
                     Print("OrderModify returned the error of ",GetLastError());
                  }
                  //exit the loop
                  break;                  
               }            
            }else{
               Print("OrderSelect returned the error of ",GetLastError());   
            }                      
         }
I hope someone can point out my mistake.
 
OrderModify(OrderTicket(), 0,newSP, 0, 0, 0)
OrderOpenPrice is set to zero... this is something you can't probably do... that's why you have error - trading not allowed...
try
OrderModify(OrderTicket(), OrderOpenPrice(),newSP, 0, 0, 0)

hope this is the error!

zolero
 
turns out I had to enable allow live trades in the expert advisor properties menu. Thanks for you're help zolero
 
mmnoname wrote >>
Hi, I'm having trouble creating a script that will change the stop loss of my orders. I keep getting error number 4109. Here is the part of the script that is giving me trouble.

I hope someone can point out my mistake.

Hi,

Unfortunately I can't help you fix yours but I found a great little very reasonably priced and flexible and effective commercial utility that has a 2 stage Trailing Stop Loss (TSL) that you can use either on its own or in conjunction with other AEs (it overrides the TSL in other AEs). It is from PipBoxer.Com: look for PBTS. Like all TSL, you have to have a profit that is equal to or greater than the amount of your TSL before it kicks in. Being a commercial product it is only available in compiled format of course.

Good luck with it.

…………………(8 >) Prosperous Trading (< 8)

DougRH4x

.

PS: I’m looking for someone to splice an adjustable (Trailing &) Stop Loss into the Martingale based program: PipMaker. Overcoming this one downfall of this program will make it VERY profitable!

 
DougRH4x wrote >>

Hi,

Unfortunately I can't help you fix yours but I found a great little very reasonably priced and flexible and effective commercial utility that has a 2 stage Trailing Stop Loss (TSL) that you can use either on its own or in conjunction with other AEs (it overrides the TSL in other AEs). It is from PipBoxer.Com: look for PBTS. Like all TSL, you have to have a profit that is equal to or greater than the amount of your TSL before it kicks in. Being a commercial product it is only available in compiled format of course.

Good luck with it.

…………………(8 >) Prosperous Trading (< 8)

DougRH4x

.

PS: I’m looking for someone to splice an adjustable (Trailing &) Stop Loss into the Martingale based program: PipMaker. Overcoming this one downfall of this program will make it VERY profitable!

 
I wasn't 'SPAMing'. I have no connection with nor gain anything if someone gets this little utility that I spoke of. I only mentioned it here as a way that would perhaps help someone overcome a ForEx trading problem.

 
 }else if(OrderType() == OP_SELL)
                  {
                     newSP = Bid+(Point * 30);

For sells, stops are relative to the ASK.

Also you should auto adjust pips (30) for 5 digit brokers, TP, SL, and slippage

//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
Reason: