MQL4: OrderModifiy() return 130

MQL4: OrderModifiy() return 130

Manage alerts

Loading saved threads...

comandante993fp · External communityPost link
External question — Stack Overflow Stack Exchange Author: comandante993fp Original post: https://stackoverflow.com/questions/69179720 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. OrderModify 130 returns to me on the backtest, but I have not found a way to fix it, what is it due to? Log: 2021.09.14 16:27:56.485 2021.01.13 05:00:00 XXXX XAUUSD,H4: OrderModify error 130 2021.09.14 16:27:56.485 2021.01.13 05:00:00 XXX XAUUSD,H4: open #17 buy 1.17 XAUUSD at 1859.80 ok 2021.09.14 16:27:56.485 2021.01.13 05:00:00 XX XAUUSD,H4: lots:1.172578644923699,mod:0.01 2021.09.14 16:27:56.485 2021.01.13 05:00:00 XXXX XAUUSD,H4: lots:0.0,Last_Position_Size:1.160968955369999,Lot_Size_Mod:1.0 2021.09.14 16:27:56.485 2021.01.13 05:00:00 XXX XAUUSD,H4: BUY entry, Nearest_Up_Level:1855.3,Close[2]:1855.21,Close[1]:1859.73 void OpenTrade(string sym, int tmode, double tsize){ int err = 0, ticket = 0; double TP = 0, SL = 0; if(!IsTradeAllowed()){ while(true){ if(IsTradeAllowed()) break; Sleep(100); } } RefreshRates(); if (tmode == OP_BUY){ err = 1; while(err > 0){ RefreshRates(); //if (TakeProfit > 0) TP = Ask + TakeProfit * Point * mp; //else TP = 0; TP = BUY_TP_Price; //Print("Current TP distance:", (TP - Ask) / Point / mp); if ((TP - Ask) / Point / mp < Min_TP_Distance) TP = Next_BUY_TP_Price; if (Stop_Loss > 0) SL = Ask - Stop_Loss * Point * mp; else SL = 0; ticket = OrderSend(sym, OP_BUY, tsize, Ask, 0, 0, 0, "", Magic_Number, 0, Green); err = GetLastError(); // Print(sym+" Buy open, err:",err); if (err == 3 || err == 64 || err == 65 || err == 130 || err == 131 || err == 133 || err == 134 || err == 148 || err == 4110 || err == 143 ) err = 0; if (err != 0) Sleep(1000); } if (ticket > 0 && (TP > 0 || SL > 0)){ if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) bool result = OrderModify(ticket, OrderOpenPrice(), SL*_Point, TP*_Point, 0, CLR_NONE); } } if (tmode == OP_SELL){ err = 1; while(err > 0){ RefreshRates(); //if (TakeProfit > 0) TP = Bid - TakeProfit * Point * mp; //else TP = 0; TP = SELL_TP_Price; Print("Current TP distance:", (Bid - TP) / Point / mp, ",TP:",TP); if ((Bid - TP) / Point / mp < Min_TP_Distance) TP = Next_SELL_TP_Price; if (Stop_Loss > 0) SL = Bid + Stop_Loss * Point * mp; else SL = 0; ticket= OrderSend(sym, OP_SELL, tsize, Bid, 0, 0, 0, "", Magic_Number, 0, Red); err = GetLastError(); //Print(sym+" Sell open, err:",err); if (err == 3 || err == 64 || err == 65 || err == 130 || err == 131 || err == 133 || err == 134 || err == 148 || err == 4111) err = 0; if (err != 0) Sleep(1000); } if (ticket > 0 && (TP > 0 || SL > 0)){ if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) bool result = OrderModify(ticket, OrderOpenPrice(), SL*_Point, TP*_Point, 0, CLR_NONE); } } }
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange Author: PaulB Original post: https://stackoverflow.com/a/69180438 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Error code 130 is ERR_INVALID_STOPS (see Error Codes ). This is specifically caused because you are using OrderModify incorrectly. Stop Loss and Take Profit should be Levels not Pips . Modify your code to the following: bool result; if(OrderType()==OP_BUY) result=OrderModify(ticket, OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-SL*_Point, Digits), NormalizeDouble(OrderOpenPrice()+TP*_Point, Digits), 0, CLR_NONE); else result=OrderModify(ticket, OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+SL*_Point, Digits), NormalizeDouble(OrderOpenPrice()-TP*_Point, Digits), 0, CLR_NONE); It is good practice to Normalise your levels to Digits also which I have included in the code above.
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: PaulB Source score (net votes, not local likes): 1 Original post: https://stackoverflow.com/a/69180438 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Error code 130 is ERR_INVALID_STOPS (see Error Codes ). This is specifically caused because you are using OrderModify incorrectly. Stop Loss and Take Profit should be Levels not Pips . Modify your code to the following: bool result; if(OrderType()==OP_BUY) result=OrderModify(ticket, OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()-SL*_Point, Digits), NormalizeDouble(OrderOpenPrice()+TP*_Point, Digits), 0, CLR_NONE); else result=OrderModify(ticket, OrderOpenPrice(), NormalizeDouble(OrderOpenPrice()+SL*_Point, Digits), NormalizeDouble(OrderOpenPrice()-TP*_Point, Digits), 0, CLR_NONE); It is good practice to Normalise your levels to Digits also which I have included in the code above.

Cancel quote

Checking account access…