You can't modify OrderOpenPrice.
What is OrderCommandBid's value?
Where is the value for BidStopLoss calculated?
You can't modify OrderOpenPrice.
What is OrderCommandBid's value?
Where is the value for BidStopLoss calculated?
Hi, Thank you for your reply,
The OrderCommandBid's value is OP_BUYLIMIT
The BidStopLoss=NormalizeDouble(iHigh(NULL,0,iHighest(NULL,0,MODE,PastPeriod,1))-iATR(NULL,0,ATRperiod,0)*ATRMultiplier,4);
i am getting the error when i go long.
The code are attached below:
Is this the issue? A limitation for market order modification is the minimum allowed distance between the stop order and the market price, set by the dealing center (see Order Characteristics andRequirements and Limitations in Making Trades). If the program tries to change the position of a stop order in such a way that it is placed closer to the market than the allowed minimum distance, such trade request will be rejected by the client terminal and the execution of the function OrderModify() will fail (error 130). This is why you should provide a special block in your program, which will consider this limitation.
It has the same error code but my issue is in the orderopen price and stoploss, not current price and stoploss. Am i understanding it wrongly?
//+------------------------------------------------------------------+//| Parameters |//+------------------------------------------------------------------+double BidOpen = 0;double BidStopLoss = 0;double BidTakeProfit = 0;double OfferOpen = 0;double OfferStopLoss = 0;double OfferTakeProfit = 0;double ATR=0;int r=0;int i=0;//--- MA modificationextern int MA1period=50;extern int MA1shift=0;extern int MA1method=1;extern int MA1price=0;extern int MA1shift2=0;extern int MA2period=100;extern int MA2shift=0;extern int MA2method=1;extern int MA2price=0;extern int MA2shift2=0;//--- High modificationextern int PastPeriod=50;extern int MODE=MODE_CLOSE;//--- Bid modificationextern int OrderCommandBid=OP_BUYLIMIT;extern int OrderCommandOffer=OP_SELLLIMIT;extern double LotSize = 0.1;//--- StopLoss modificationextern int ATRperiod=20;extern int ATRMultiplier=3;//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+int OnInit() {//---//--- return(INIT_SUCCEEDED); }//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+void OnDeinit(const int reason) {//--- }//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+void OnTick() {//--- Calculating entry and exit BidOpen=NormalizeDouble((Close[0]-Low[0])/2+Low[0],4); BidStopLoss=NormalizeDouble(iHigh(NULL,0,iHighest(NULL,0,MODE,PastPeriod,1))-iATR(NULL,0,ATRperiod,0)*ATRMultiplier,4); OfferOpen=NormalizeDouble((Close[0]-High[0])/2+High[0],4); OfferStopLoss=NormalizeDouble(iLow(NULL,0,iLowest(NULL,0,MODE,PastPeriod,1))+iATR(NULL,0,ATRperiod,0)*ATRMultiplier,4);//--- Check Position r=OrdersTotal()-1; int count_trades=0; for (r == OrdersTotal()-1;r>=0;r--) { if(OrderSelect(r,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==2) { count_trades++; } }//---//--- If No Order/Position if(count_trades ==0) { //--- MA difference if(iMA(NULL,0,MA1period,MA1shift,MA1method,MA1price,MA1shift2)>iMA(NULL,0,MA2period,MA2shift,MA2method,MA2price,MA2shift2)) { //--- Close higher than past highest if(Close[0]>iHigh(NULL,0,iHighest(NULL,0,MODE,PastPeriod,1))) { int buy=OrderSend(Symbol(),OrderCommandBid,LotSize,BidOpen,1,BidStopLoss,0,"BUY",2,0,clrGreen); } } if(iMA(NULL,0,MA1period,MA1shift,MA1method,MA1price,MA1shift2)<iMA(NULL,0,MA2period,MA2shift,MA2method,MA2price,MA2shift2)) { //--- Close higher than past highest if(Close[0]<iLow(NULL,0,iLowest(NULL,0,MODE,PastPeriod,1))) { int sell=OrderSend(Symbol(),OrderCommandOffer,LotSize,OfferOpen,1,OfferStopLoss,0,"SELL",2,0,clrGreen); } } } if(count_trades == 1) { i=OrdersTotal()-1; for (i == OrdersTotal()-1;i>=0; i--) //Cycle for all orders.. { //--- Selecting of Open Order if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()== 2) { //--- If a long position was triggered if(OrderType()==OrderCommandBid) { if(BidStopLoss > OrderStopLoss()) { if(!OrderModify(OrderTicket(), OrderOpenPrice(),BidStopLoss,OrderTakeProfit(), 0, Pink)) { Print("(OrderModify Error)"); } } } //--- If a short position was triggered if(OrderType()==OrderCommandOffer) { if(BidStopLoss > OrderStopLoss()) { Print(BidStopLoss,OrderStopLoss()); OrderModify(OrderTicket(),OrderOpenPrice(),OfferStopLoss,0,0,clrGreen); } } } } }//+-----------end }//+------------------------------------------------------------------+
-
Play videoPlease edit your post.
For large amounts of code, attach it.
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it.
It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- Where do you check that (Close[0]-Low[0])/2+Low[0] < Ask - MarketInfo(_Symbol, MODE_STOPLEVEL)*Point) ? Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
- I never got pending orders to work when I once tried. I thought it was comparing stops to current market rather than pending price. Try opening first and then set stops.
- There is no need for pending orders in a EA. Humans need them because they can't watch the screen every second; EAs can. Wait for price to reach trigger and open.
Play videoPlease edit your post.
For large amounts of code, attach it.- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it.It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.)(On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum)and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- Where do you check that (Close[0]-Low[0])/2+Low[0] < Ask - MarketInfo(_Symbol, MODE_STOPLEVEL)*Point) ? Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
- I never got pending orders to work when I once tried. I thought it was comparing stops to current market rather than pending price. Try opening first and then set stops.
- There is no need for pending orders in a EA. Humans need them because they can't watch the screen every second; EAs can. Wait for price to reach trigger and open.
Thanks for the reply WHRoeder! I will test and go through them throughly when i get home from my military camp in the weekend.
But in the mean while, what do you mean by point 3? what do i have to check for? The ticksize or something else?
- I posted exactly what you must check for and a link to why.
- You must have a SL in place in case of news, loss of connection, loss of power, etc.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, i have been trying to figure out why my trailing would not work.
When a trade is executed, i would like to change the stoploss accordingly like a trailing stop. I used an OrderModify to modify the stoploss as per seen below but always ended up in an error. After some testing, i suspect that my Stoploss cannot be more than the OrderOpenPrice() and was giving me an error 130. (when i am long)
I have tried replacing the OrderOpenPrice() with different values like 0, < or > than stoploss but it doesnt seem to work.
Is my suspicion correct that the issue is that i am trying to modify the opening and stoploss prices, such that the stoploss value is higher than the opening price?
Or am i not suppose to use OrderModify in such situation? possibly an alternative way to change my stoploss?
is there other value i could possibly use to replace OrderOpenPrice() that would solve this issue?
Thank you