Hi all, having probs with ECN broker..

 

Hello, Just want to say this board rocks! I have gained so much knowledge just from reading the posts that I have been able to program my own ea! Thanks to all those who freely give their time on here... Kudos!

I have moved over to an ECN broker, and naturally I cant enter the stop and target on the OrderSend() command. I realize I need use OrderModify() to change these parameters.. What I have done is added an external variable 'extern bool ECNbroker = true'. that way i can use with either ECN or Non ECN broker. The problem is I am still getting the Error 130 Invalid Stops and I am not getting entered in the first place, needless to say not even getting to the OrderModify() function..  Could anyone see where I am messing up??

extern bool ECNbroker = true;

double BreakoutStop = 100;
double BreakoutTarget = 150;  //5 digit brokers 
int slip = 2;
string breakout = "Breakout ";

void EnterBreakoutLong()
 { 
 double stop,target,newstop,newtarget; 
 if (ECNbroker == true)  
   {
   stop = 0; 	//if ECN then use these values to open trade
   target = 0;
   }
   else stop = Ask-BreakoutStop*Point;
        target = Ask+BreakoutTarget*Point;
                 
 ticketBreakout=OrderSend(Symbol(),OP_BUY,lots,Ask,slip,stop,target,"BreakoutLong",Magic,0,Green);
   if(ticketBreakout>0)
    {
    if(OrderSelect(ticketBreakout,SELECT_BY_TICKET,MODE_TRADES))
        {
        Print("Long - Breakout Trade entered:",OrderOpenPrice());
        if(ECNbroker == true)
         {
         newstop = OrderOpenPrice()-BreakoutStop*Point;
         newtarget = OrderOpenPrice()+BreakoutTarget*Point;

         ModifyForECN(newstop,newtarget,breakout); //call function to modify open trade
         }
        return;
        }
    }
    else {Print("Error opening Long 1m Trend trade:",GetLastError());return;}
  }  

//---Function to modify open trade for ECN
void ModifyForECN(double stoploss,double takeprofit, string setup)
         {
         if (OrderModify(OrderTicket(),OrderOpenPrice(),stoploss, takeprofit,0,Red))
                    {                 
                    Print(setup," from ",OrderOpenPrice(),"Stop and Target Placed");
                    } 
                    else Print("Error modifying ", setup," trade:",GetLastError());
         }           

 QUESTION: Is it my use of the variables 'stop' and 'target'? can variables be used for an OrderSend() that opens a trade for ECN even if they are valued at 0? Or does it need to be an ACTUAL "0"?

 

Any help would be GREATLY appreciated.. Thanks!

 

Sam 

 

Also, Is there a way for the EA to detect if it is ECN? that way could bypass the external variable...

 

Thanks again.

Sam 

 
sammy515:

Hello, Just want to say this board rocks! I have gained so much knowledge just from reading the posts that I have been able to program my own ea! Thanks to all those who freely give their time on here... Kudos!

I have moved over to an ECN broker, and naturally I cant enter the stop and target on the OrderSend() command. I realize I need use OrderModify() to change these parameters.. What I have done is added an external variable 'extern bool ECNbroker = true'. that way i can use with either ECN or Non ECN broker. The problem is I am still getting the Error 130 Invalid Stops and I am not getting entered in the first place, needless to say not even getting to the OrderModify() function..  Could anyone see where I am messing up??

 QUESTION: Is it my use of the variables 'stop' and 'target'? can variables be used for an OrderSend() that opens a trade for ECN even if they are valued at 0? Or does it need to be an ACTUAL "0"?

You can use a variable that equals 0.0  it's just the same as using 0.0

What was the spread at the time ?  what are your STOP and FREEZE levels ?    have you read this ?  Requirements and Limitations in Making Trades

 
sammy515:

Also, Is there a way for the EA to detect if it is ECN? that way could bypass the external variable...

Not with 100% reliability . . as far as I know.
 
RaptorUK:

You can use a variable that equals 0.0  it's just the same as using 0.0

What was the spread at the time ?  what are your STOP and FREEZE levels ?    have you read this ?  Requirements and Limitations in Making Trades

Thanks for your quick reply Raptor!


so I should make the variable = 0.0 and NOT 0?

also my stop and freeze levels are both 0.. according to your resource link (thanks, btw) if i am reading it right, it says order cannot be modified if  

 

Buy
Modification is prohibited  Bid-SL ≥ StopLevelTP-Bid ≥ StopLevel
Sell
Modification is prohibitedSL-Ask ≥ StopLevelAsk-TP ≥ StopLevel

 

according to these formulas it seems I can NEVER modify trade because Bid-SL will always be more than 0.. Am i missing something?

 
RaptorUK:
Not with 100% reliability . . as far as I know.

ok thanks, would be nice if there was..

 

also, does rest of code i posted above look right? or at least looks like it will work?

sam 

 

RaptorUK:


What was the spread at the time ? 


spread was pretty normal about 1.5-2.5 pips

 
//++++ These are adjusted for 5 digit brokers.
int      pips2points;                  // slippage  3 pips  3=points 30=points
double   pips2dbl;                     // Stoploss 15 pips  0.0015   0.00150
int      Digits.pips;                  // DoubleToStr(dbl/pips2dbl, Digits.pips)
int      init(){                                            OptInitialization();
    if(Digits % 2 == 1){   // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
            pips2dbl = Point*10;    pips2points = 10;    Digits.pips = 1;
   } else { pips2dbl = Point;       pips2points =  1;    Digits.pips = 0;     }
   // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
   //{On ECN brokers you must open first and THEN set stops
   // int      ticket = OrderSend(..., 0,0,...)
   // if(      ticket < 0)
   //    Alert("OrderSend failed: ", GetLastError());
   // else  if(!OrderSelect(ticket, SELECT_BY_TICKET))
   //    Alert("OrderSelect failed: ", GetLastError());
   // else  if(!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0))
   //    Alert("OrderModify failed: ", GetLastError());
   //}
 
sammy515:

Thanks for your quick reply Raptor!


so I should make the variable = 0.0 and NOT 0?

also my stop and freeze levels are both 0.. according to your resource link (thanks, btw) if i am reading it right, it says order cannot be modified if  

 

Buy
Modification is prohibited  Bid-SL ≥ StopLevelTP-Bid ≥ StopLevel
Sell
Modification is prohibitedSL-Ask ≥ StopLevelAsk-TP ≥ StopLevel

 

according to these formulas it seems I can NEVER modify trade because Bid-SL will always be more than 0.. Am i missing something?

 

For a double 0 == 0.0 

Modification of the Open Price is prohibited . . . look at the column headers. 

 
sammy515:


spread was pretty normal about 1.5-2.5 pips

 

Not approx.  what was it in actuality ?  when you get an error you need to print out all the relevant info you need to debug the issue . . .  it's no good guessing after the event.  Print the Bid, Ask, etc.  and with the correct number of digits using  DoubleToString()
 

This is your issue . . .

   else stop = Ask-BreakoutStop*Point;


        target = Ask+BreakoutTarget*Point;

  . . .  if you had printed the SL and TP values as part of your error reporting you would have seen this yourself.

Reason: