Invalid S/L or T/P on MT4, for Market orders... Any Price... Cant place any order.

 
Hello. I've just started using a new MT4 demo. I'm getting an invalid S/L or T/P error on any Market order I try to place, and I receive "invalid parameters" on any Pending order I try to place. Anybody know why???
 
Are you using a demo account through your broker, or is it a Metaquotes demo feed? I'm guessing it has something to do with price precision, 4 digits or 5. Either that, or you are using an ECN broker that requires you to place an order, and the separately modify the S/L and T/P.
 
EA must adjust TP, SL, AND slippage for 5 digit brokers. EA must open order and THEN set TP, SL on ECN brokers
//++++ 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
 

WHRoeder I'm beginning to think you have that code sitting in a text document on your desktop, always ready for copy and paste. ;) I use it myself, although I have changed it. I place it in my init() function, followed by...

TP *= pips2dbl; SL *= pips2dbl; slip *= pips2dbl;
...and I don't use the Digits.pips.
 
  1. Anomalous:
    WHRoeder I'm beginning to think you have that code sitting in a text document on your desktop, always ready for copy and paste.
    Actually I do, straight out of my EA as I watch the tester in visual mode.
  2. Anomalous:
    I use it myself, although I have changed it. I place it in my init() function, followed by...
    TP *= pips2dbl; SL *= pips2dbl; slip *= pips2dbl;
    I assume TP, SL are global (extern) variables. That will not work. Every parameter/TF/pair change or a chart refresh will perform an deinit/init cycle. So the slip will go 3, 30, 300, 3000...

    TP/SL are prices (pips2dbl,) slippage is in points (pips2points.) What? Huh? Duh! Code correction:

    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    

  3. Anomalous:
    ... and I don't use the Digits.pips.
    Only used for printing
    string  PriceToStr(double p){
        return(DoubleToStr(p, Digits);                                             }
    string  DeltaToPips(double d){
        if (d > 0)  string sign = "+";  else    sign = "";
        double pips = d / pips2dbl;
        return(sign + DoubleToStr(pips, Digits.pips));                             }
    
    Print("TP=",PriceToStr(TP)," (",DeltaToPips(TP-Bid),")");
    

 

Gotcha. Thanks for the tips. So far my only experience is with the tester, so my code was working as I expected it to.

When you talk about this...

Every parameter/TF/pair change or a chart refresh will perform an deinit/init cycle.

...I realize there are some important things I don't understand about MT4. How does a chart refresh happen? And how do the first 3 events you mention occur without the EA being unloaded and reloaded? Are there circumstances where globals go out of scope but externs do not?

Thanks

 

Refresh happens via right click-> refresh. Possibly after a lost connection/relogin.

The events do NOT reload the EA, they only call deInit/init. To reload an EA you must remove it from the chart and reattach. That resets the globals.

If you close and restart the terminal, you are reloading the EA so the globals are reset, the externs will be reset to the last saved values (GUI set values, not internal modifications.)

 
So I think I have some bad coding practices then. I declare my globals, well, globally. But I initialize them in init(). I should be assigning my globals their initial values at the same time I declare them then?
 

What's the point in a global with a constant value. Use #define instead.

A global with a calculated value must be initialized. In init if constant, in start if not. "Global *= 10;" is not an initialization, it is a modification.

Externs are set with their initial values prior to init, make them read only, do not modify them.

 
WHRoeder:

What's the point in a global with a constant value. Use #define instead.

A global with a calculated value must be initialized. In init if constant, in start if not. "Global *= 10;" is not an initialization, it is a modification.

Externs are set with their initial values prior to init, make them read only, do not modify them.


Well I don't use globals for constants. To clarify my question:

int global = 0;

or

int global;

init() { global = 0; }

Which is safer for an EA when we have to make sure we don't lose track of state information in the event of chart refreshes and such? Or does it matter?
Reason: