MQL4 why I am getting error 130 on OrderModify as my SL should be perfect?

MQL4 why I am getting error 130 on OrderModify as my SL should be perfect?

Manage alerts

Loading saved threads...

auxtionist · External communityPost link
External question — Stack Overflow Stack Exchange Author: auxtionist Original post: https://stackoverflow.com/questions/67961865 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Can someone please tell me why the SL is not moving, I am getting error 130 (ERR_INVALID_STOPS , invalid stops) and i have run Print( "Minimum Stop Level=", minstoplevel, " points" ); in my code and got "10" and tried running the code even with 11 and still same error. Can someone please take a look and let me know, I barely have any hair left of trying all possibilities. Much appreciated ... //+------------------------------------------------------------------+ //| Emotality EA.mq4 | //| Daniel Fourie | //| https://www.emotality.com/ | //+------------------------------------------------------------------+ #property copyright "Daniel Fourie" #property link "https://www.emotality.com/" #property version "1.00" #property strict #property script_show_inputs extern int takeProfitPoints = 100; extern int maxPipStopLoss = 11; extern double volumeSize = 0.01; extern double maxSlippageAllowed = 0.1; int orderID; int magicNB = 1337; int trailingStop = 110; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // Create an empty string for the signal string signal = ""; // Calculate the two Fractal values double UpperFractalsValue = iFractals(NULL, PERIOD_M5, MODE_UPPER, 2); double LowerFractalsValue = iFractals(NULL, PERIOD_M5, MODE_LOWER, 2); // Buy Signal //When it is going up if (LowerFractalsValue != 0) { if (LowerFractalsValue < Low[1]) { signal = "buy"; } } //When it is going down if (UpperFractalsValue != 0) { if (UpperFractalsValue > High[1]) { signal = "sell"; } } // If we have a buy signal and no positions if (signal == "buy" && CheckIfOpenOrdersByMagicNB(magicNB) == false) //need to see if the argument is correct that new orders will open if other ones is open //Send a buy order int orderID = OrderSend(_Symbol, OP_BUY, volumeSize, Ask, maxSlippageAllowed, Ask - maxPipStopLoss, Ask + takeProfitPoints, NULL, magicNB); int openOrders = OrdersTotal(); for (int i = 0; i < openOrders; i++) { if (OrderSelect(i, SELECT_BY_POS) == true) { if (OrderMagicNumber() == magicNB) if (OrderType() == 0) { if (UpperFractalsValue != 0) { OrderClose(OrderTicket(), volumeSize, Ask, 5); } } } } int newSl = Bid - NormalizeDouble(trailingStop * Point,Digits); Print(newSl); for (int i = 0; i < openOrders; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber() == magicNB) { if (OrderType() == 0) { if(Bid - OrderOpenPrice() > trailingStop * Point && OrderStopLoss() < Bid - trailingStop * Point){ if(newSl < Bid) { OrderModify(OrderTicket(), OrderOpenPrice(),newSl , takeProfitPoints, 0); } } } } } } // If we have a sell signal and no positions if (signal == "sell" && CheckIfOpenOrdersByMagicNB(magicNB) == false) //need to see if the argument is correct that new orders will open if other ones is open //Send a sell order int orderID = OrderSend(_Symbol, OP_SELL, volumeSize, Ask, maxSlippageAllowed, Bid + maxPipStopLoss, Bid - takeProfitPoints, NULL, magicNB); for (int i = 0; i < openOrders; i++) { if (OrderSelect(i, SELECT_BY_POS) == true) { if (OrderMagicNumber() == magicNB) if (OrderType() == 1) { if (LowerFractalsValue != 0) { OrderClose(OrderTicket(), volumeSize, Ask, 5); } } } } Comment( "Upper Fractals Value: ", UpperFractalsValue, "\n", "Lower Fractals Value: ", LowerFractalsValue, "\n", "The current signal is:", signal ); } //+------------------------------------------------------------------+ bool CheckIfOpenOrdersByMagicNB(int magicNM) { int openOrders = OrdersTotal(); for(int i = 0; i < openOrders; i++) { if(OrderSelect(i,SELECT_BY_POS)==true) { if(OrderMagicNumber() == magicNB) { return true; } } } return false; } //+------------------------------------------------------------------+ ...
Quote
Report
tomgny · External communityPost link
External answer — Stack Overflow Stack Exchange Author: tomgny Original post: https://stackoverflow.com/a/67969073 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Your newSL variable should be a type of double , not int . Additionally, when you send order with type OP_SELL , use Bid price instead of Ask . Docs : At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price.
Quote
Report

Post Reply

Checking account access…