Your stops are to close to the current price. You need to find out minimum stops required by your broker.
See this answer for details and example: https://www.mql5.com/en/forum/151846
You need to NormaliseDouble() to Digits(), these caclulations:
OrderOpenPrice() - ((OrderStopLoss() - OrderOpenPrice())*3) OrderOpenPrice() + ((OrderOpenPrice() - OrderStopLoss())*3)
@SDC: Doesn't work.. :-(
I also changed OrderOpenPrice(), OrderStopLoss() and TakeProfit to absolute values to test it. And that doesn't work, too.
How can that be so complicated? It is a simple break-to-even-stop. But I don't understand why the stop is always invalid..
It works! You know what the problem was? For testing purposes I had to use a buy limit order and this order was never executed because of the very large weekend-spread. I have not paid any attention to that. But on the other hand I use OrderOpenTime() and TimeCurrent() as a filter if there is a running order. Could it be that OrderOpenTime() is the time where the order was created instead of executed? I didn't find anything about that in the MQL4-docs.
So how do I know if there is an already executed order or if the order is still pending? OrderProfit() could be a possibility, or is there any other?
- mar: move my stop to breakeven when the trade is the same amount of pips in profit. That's all. And whatever I try, I always get error 130. I don't understand why this is an invalid SL?First problem is once you make the modification, your OrderOpenPrice() vs OrderStopLoss() now fails, either it succeeds when it shouldn't or the opposite direction IF succeeds. You want to test the order type, so do it if (OrderType() == OP_BUY && ...
if (OrderOpenPrice() > OrderStopLoss() && (Bid - OrderOpenPrice() >= OrderOpenPrice() - OrderStopLoss())) { SLtoBE = OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice(), OrderOpenPrice() + ((OrderOpenPrice() - OrderStopLoss())*3), 0, clrNONE);
- Second, is you are also modifying the TP. Once you modify the order, the next time you will be trying to set the TP equal to OOP and get 130. You don't want to move the TP, so don't do it.
if (OrderType() == OP_BUY && (Bid - OrderOpenPrice() >= OrderOpenPrice() - OrderStopLoss())) { SLtoBE = OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit() , 0, clrNONE);
- Third, once you move, to break even, your test will still succeed (Bid - OOP >= 0) and you will start getting Error 1 . Test and avoid.
if (OrderType() == OP_BUY && OrderOpenPrice() - OrderStopLoss() > _Point / 2. && (Bid - OrderOpenPrice() >= OrderOpenPrice() - OrderStopLoss() ) { SLtoBE = OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + _Point, OrderTakeProfit() , 0, clrNONE);
- finally, test your return code. What are Function return values ? How do I use them ? - MQL4 forum
- SDC: You need to NormaliseDouble() to Digits(), these caclulations:
Do not use NormalizeDouble ever. The == operand. - MQL4 forum
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
I want to do a simple thing.. Just move my stop to breakeven when the trade is the same amount of pips in profit. That's all. And whatever I try, I always get error 130. I don't understand why this is an invalid SL? Can anyone help?