Yet another Error 130 problem on OrderSend after Compensation on 5 digit

 

Any assistance would be greatly appreciated.

I have read up on this Error 130 and have tested my EA on the strategy tester wit success... but when trying to run it on a Demo account it gives me error 130 on OP_BUY and OP_SELL:

OrderSend(Symbol(),OP_BUY,StartLots,Ask,3,Ask-StopLoss*Point*10,Ask+TakeProfit*Point*10,"",MAGICMA,0,Blue);

My Demo account is with IBFX and as you can see I have tried to compensate for the 5 digit quote system by multiplying by 10.

When I run the line: Print("Current StopLevel: ", MarketInfo(Symbol(), MODE_STOPLEVEL)); It reports the StopLevel as: 0

Please help

 
send order without TP & SL then use OrderModify()
 

Thanks, I'll try this..

Would the OrderModify() look something like this then?

OrderModify(i,OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point*10,OrderOpenPrice()+TakeProfit*Point*10,0,Blue);

Once again, thanks for the assistance. :-)

 

Whoops, I think I made a mistake in the previous code example.

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point*10,OrderOpenPrice()+TakeProfit*Point*10,0,Blue);

 
ebenv:

Whoops, I think I made a mistake in the previous code example.

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point*10,OrderOpenPrice()+TakeProfit*Point*10,0,Blue);

Looks OK to me.
 

Got it working thanks... All...

The last code sample that I posted was fine. Weird how you cant open the order from start with the SL and TP already there.... Does anyone know why? Is this the case with some brokers? If so then it might be best method to open do the order with OrderSend without SL and TP and then modify it later as part of standard code practice for compatibility reasons between brokers..... I don't know....

 
ebenv:

Got it working thanks... All...

The last code sample that I posted was fine. Weird how you cant open the order from start with the SL and TP already there.... Does anyone know why? Is this the case with some brokers? If so then it might be best method to open do the order with OrderSend without SL and TP and then modify it later as part of standard code practice for compatibility reasons between brokers..... I don't know....

It's how it is for ECN Brokers, plenty has been written about it . . take a look at some of these links: http://crum.be/ecn
 
RaptorUK:
It's how it is for ECN Brokers, plenty has been written about it . . take a look at some of these links: /go?link=http://lmgtfy.com/?q=mql4+can't+set+sl+and+tp


Thanks Raptor,

I am quite new to MQL4.

 
  1. EAs must adjust for 4/5 digit brokers, TP, SL AND slippage. For ECN brokers you must open first and THEN set stops
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                    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(...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_TICKET))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket()...)
           Alert("OrderModify failed: ", GetLastError());
         */
    

  2. OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-StopLoss*Point*10
                                                 OrderOpenPrice()+TakeProfit*Point*10, 0,Blue);
    Isn't exactly correct. On a Buy you open at the Ask and sell (stop) at the Bid. The above code would be using the original Ask making your stops shorter and TP longer than specified by the amount of the spread. Use the OrderClosePrice() +/- X for your stops.
 
WHRoeder:
  1. EAs must adjust for 4/5 digit brokers, TP, SL AND slippage. For ECN brokers you must open first and THEN set stops
  2. Isn't exactly correct. On a Buy you open at the Ask and sell (stop) at the Bid. The above code would be using the original Ask making your stops shorter and TP longer than specified by the amount of the spread. Use the OrderClosePrice() +/- X for your stops.

Hi;

This is my solution for OrderSend function error 130 due to the 5 digit problem. I tried it and it works .

int mydig=MarketInfo(Symbol(),MODE_DIGITS);
double mypoint=MarketInfo( Symbol(),MODE_POINT);
if (mydig==5){mypoint=mypoint*10;}
Slippage=Slippage*mypoint;

Sample OrderSend Functions for Market, Stop and limit Orders.

double BigLot =0.02;

int StopLoss =1000;

int UPBUYTP =38;

OrderSend(Symbol(),OP_BUY,
NormalizeDouble(BigLot,2),
NormalizeDouble(Ask,Digits),Slippage,
NormalizeDouble(Ask-StopLoss*mypoint,Digits),
NormalizeDouble(Ask+UPBUYTP*mypoint,Digits),
OrderStr,MagicNumber,0,Yellow);

OrderSend(Symbol(),OP_BUYSTOP,
NormalizeDouble(BigLot,2),
NormalizeDouble(Ask+j*Step*mypoint,Digits),Slippage,
NormalizeDouble(Ask-(StopLoss-j*Step)*mypoint,Digits),
NormalizeDouble(Ask+j*Step*mypoint+UPBUYTP*mypoint,Digits),
OrderStr,MagicNumber,0,Lime);

OrderSend(Symbol(),OP_BUYLIMIT,
NormalizeDouble(BigLot,2), //LotSize
NormalizeDouble(Ask-j*StepLIMIT*mypoint,Digits),//OrderOpenPrice()

Slippage,
NormalizeDouble(Ask-(StopLoss+j*StepLIMIT)*mypoint,Digits), //StopLoss

NormalizeDouble(Ask-j*StepLIMIT*mypoint+UPBUYTP*mypoint,Digits), //TakeProfit

OrderStr,MagicNumber,0,Lime);

This is the demo account output for the orders above.

Date Type Ticket Price StopLoss TakeProfit Balance

2011.11.09 02:00 buy 1 0.02 1.38323 1.28323 1.38703 5000.00
2011.11.09 02:00 buy stop 2 0.02 1.38723 1.28723 1.39103 5000.00
2011.11.09 02:00 buy limit 22 0.02 1.37923 1.27923 1.38303 5000.00

 
Whisper:

Hi;

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.