Newbe Help Request: Order Processing.

 

Hello MQL Community.

I am a really new user of the MetaTrader and MQL4.

I have been following the tutorial when I came across this problem.

Data provided by Pastebin.com - Download Raw
  1. //+------------------------------------------------------------------+
  2. //| Test Order.mq4 |
  3. //| Copyright © 2011, MetaQuotes Software Corp. |
  4. //| http://www.metaquotes.net |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright © 2011, MetaQuotes Software Corp."
  7. #property link "http://www.metaquotes.net"
  8. //+------------------------------------------------------------------+
  9. //| script program start function |
  10. //+------------------------------------------------------------------+
  11. //--------------------------------------------------------------------
  12. //--------------------------------------------------------------------------
  13. // confined.mq4
  14. // The code should be used for educational purpose only.
  15. //--------------------------------------------------------------------------
  16. int start() // Special function start
  17. {
  18. int offset = 300; // Opening BUY
  19. Alert("Buy :",Ask);
  20. Alert("Offset :",offset*Point);
  21. Alert("Stop Loss: ", Ask-(offset*Point));
  22. Alert("Take Profits: ", Ask+(offset*Point));
  23. OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-(offset*Point),Ask+(offset*Point));
  24. Alert (GetLastError()); // Error message
  25. return; // Exit start()
  26. }
  27. //-----

And Alerts looks like this:

I am testing this code on MT4 from Oanda on EURUSD.

Why am I getting error code 130?

Any assistance is greatly appreciated.

 
  1. EA's should adjust TP, SL, AND slippage for 5 digit brokers. On ECN brokers you must open the order 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.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
    


  2. Print/Alert defaults to 4 digits. Try Alert(PriceToStr(p))
    string  PriceToStr(double p){
        string pFrc = DoubleToStr(p, Digits);       if(Digits.pips==0) return(pFrc);
        string pPip = DoubleToStr(p, Digits-1);
        if (pPip+"0" == pFrc)       return(pPip);           return(pFrc);          }
    

 

Yes, ECN brokers require that you use the OrderSend() without a stop loss or take profit then you must modify the trade once it is open.

int OrderSend(

string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

https://docs.mql4.com/trading/OrderSend

bool OrderModify(

int ticket, double price, double stoploss, double takeprofit, datetime expiration, color arrow_color=CLR_NONE)

https://docs.mql4.com/trading/OrderModify

 
Thank you.
Reason: