Hi All
I want to use trail my buy stop and sell stop orders but I encounter invalid price error when using the code below.
Plus I get failed to modify error for no changes
Why is it that when I've checked my freeze levels no orders don't open?
bool CheckFreeze(ulong Ticket) bool Freeze=false; double PriceOpen=OrderGetDouble(ORDER_PRICE_OPEN); ENUM_ORDER_TYPE Type=(ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE); switch(Type) { case ORDER_TYPE_BUY_STOP:Freeze=PriceOpen-Ask>FreezeLevel*Pips();break; case ORDER_TYPE_SELL_STOP:Freeze=Bid-PriceOpen>FreezeLevel*Pips();break; } return(false); }
void OnTick() { trade.SetExpertMagicNumber(MagicNumber); if(CheckFreeze(m_order.Ticket())) if(CountPending()<1){BuyPending();} if(CheckFreeze(m_order.Ticket())) if(CountPending()<1){SellPending();} }
Tried a different approach but I still get invalid price:
void BuyPending() { double TPBuy=Bid+TakeProfit*Pips(); double SLBuy=Bid-StopLoss*Pips(); double PriceOpen=OrderGetDouble(ORDER_PRICE_OPEN); double BuyPrice=Bid+PendingStopTrail*Pips(); Filter=3*Pips(); double open=iOpen(Symbol(),0,0); double Range=MathAbs(open-Bid); MqlRates Candle[]; ArraySetAsSeries(Candle,true); int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle); if(Candle[0].close>Candle[0].open) { if(Direction!=1) { Direction=1; if(PriceOpen+Ask>StopLevel||PriceOpen+Ask>FreezeLevel||Bid-StopLoss>StopLevel*Pips()||TakeProfit-Bid>StopLevel*Pips()) { trade.BuyStop(0.01,BuyPrice,Symbol(),0,0,0,0,"Test"); } } } } void SellPending() { double TPSell=Bid-TakeProfit*Pips(); double SLSell=Bid+StopLoss*Pips(); double PriceOpen=OrderGetDouble(ORDER_PRICE_OPEN); double SellPrice=Bid-PendingStopTrail*Pips(); Filter=3*Pips(); double open=iOpen(Symbol(),0,0); double Range=MathAbs(open-Bid); MqlRates Candle[]; ArraySetAsSeries(Candle,true); int rates=CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),Candle); if(Candle[0].close<Candle[0].open) { if(Direction!=-1) { Direction=-1; if(Bid-PriceOpen>StopLevel||Bid-PriceOpen>FreezeLevel||StopLoss-Ask>StopLevel*Pips()||Ask-TakeProfit>StopLevel*Pips()) { trade.SellStop(0.01,SellPrice,Symbol(),0,0,0,0,"Test"); } } } }
Hi All
I want to use trail my buy stop and sell stop orders but I encounter invalid price error when using the code below.
Plus I get failed to modify error for no changes
i see you have used bid price when I would think you should be using Ask. but i only took quick look. i could be wrong.
Maybe your SL or TP is too close to the price. The broker is usually not accepting tight SLs and TPs. Try larger values, or a broker that accept scalping strategies.
before posting that I need assistance with the invalid price error I disabled my TP'S and SL's but it's the still the same outcome, I will try a different broker
input double TakeProfit=5; input double StopLoss=2; input double PendingStopTrail=2;The values are too small in all cases. As soon as the trade is open, it will close instantly. And for the pending trade, it will not open. I think you have seen it already ;)
The values are too small in all cases. As soon as the trade is open, it will close instantly. And for the pending trade, it will not open. I think you have seen it already ;)
You actually right I've noticed a difference no more invalid prices, I just wanted my EA to use a stop loss of 2 pips I'll change it though
Thanks for the help :)
The values are too small in all cases. As soon as the trade is open, it will close instantly. And for the pending trade, it will not open. I think you have seen it already ;)
I've currently using MqlTick function for ask and bid I don't encounter invalid stops anymore even if I use the values that are too close to the price.
input double TakeProfit=5; input double StopLoss=2; input double PendingStopTrail=2;
MqlTick Tick; SymbolInfoTick(Symbol(),Tick); double NewAsk=Tick.ask; double NewBid=Tick.bid; double NewBuyTP=NewAsk+TakeProfit*Pips(); double NewBuySL=NewAsk-StopLoss*Pips(); double NewAsk=Tick.ask; double NewBid=Tick.bid; double NewSellTP=NewBid-TakeProfit*Pips(); double NewSellSL=NewBid+StopLoss*Pips();
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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 All
I want to use trail my buy stop and sell stop orders but I encounter invalid price error when using the code below.
Plus I get failed to modify error for no changes