if(OrderStopLoss()< OrderOpenPrice()-35*_Point)
Why would the SL be below the open price unless you have already moved it?
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
if(OrderStopLoss()< OrderOpenPrice()-35*_Point)
This condition :
Okay so I switched it back to your suggestion and now it doesnt execute the SL at all
for(int s=OrdersTotal()-1; s>=0; s--) { if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderType()==OP_SELL) if(OrderOpenPrice()-Ask > 50*_Point) if(Ask < OrderStopLoss()-35*_Point) OrderModify( OrderTicket(), OrderOpenPrice(), Ask+35*_Point, OrderTakeProfit(), 0, clrGray ); }
for(int s=OrdersTotal()-1; s>=0; s--) { if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderType()==OP_SELL) if(OrderOpenPrice()-Ask > 500*_Point) { bool result = OrderModify( OrderTicket(), OrderOpenPrice(), Ask+350*_Point, OrderTakeProfit(), 0, clrGray ); } }
Okay so I switched it back to your suggestion and now it doesnt execute the SL at all
for(int s=OrdersTotal()-1; s>=0; s--) { if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderType()==OP_SELL) if(OrderOpenPrice()-Ask > 50*_Point) if(Ask < OrderStopLoss()-35*_Point) OrderModify( OrderTicket(), OrderOpenPrice(), Ask+35*_Point, OrderTakeProfit(), 0, clrGray ); }
Your code misses one very important check which may or may not be relevant and that is if the initial order is opened without a stoploss.
if(Ask < OrderStopLoss()-35*_Point || OrderStopLoss()==0) { }
Daniel Cioca #:
for(int s=OrdersTotal()-1; s>=0; s--) { if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderType()==OP_SELL) if(OrderOpenPrice()-Ask > 500*_Point) { bool result = OrderModify( OrderTicket(), OrderOpenPrice(), Ask+350*_Point, OrderTakeProfit(), 0, clrGray ); } }
Your code is not really a trailing stop as it will only ever close the trade at 150 points profit.
The trade may go 10,000 points in profit but if the Ask rises, The stoploss will rise again.
You should always check the the new SL is better than the existing SL.
Your code misses one very important check which may or may not be relevant and that is if the initial order is opened without a stoploss.
Your code misses one very important check which may or may not be relevant and that is if the initial order is opened without a stoploss.
No… it will start to trail at 500 point in profit … and it will stay behind 350 points… trail… off course… this is a minim code… many other things should be checked
Why have you quoted and responded to my comment about David Maza's post? It had nothing to do with your code.
Your code misses one very important check which may or may not be relevant and that is if the initial order is opened without a stoploss.
if(Ask < OrderStopLoss()-35*_Point || OrderStopLoss()==0) { }
Okay so I tried that out and im still getting no trailing stop. Maybe I'm testing wrong?
Here's how im testing it to see if the sell trailing stop goes through
void OnTick() { if(OrdersTotal()==0) { int buyticket = OrderSend(Symbol(),OP_SELL,0.10,Bid,3,0,0,NULL,0,0,clrGreen); } if(OrdersTotal()>0) { for(int s=OrdersTotal()-1; s>=0; s--) { //--- Select open order by position b relative to the previous counter if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES)) //--- Check if order beloings to the current chart if(OrderSymbol()==Symbol()) //--- If its a buy order if(OrderType()==OP_SELL) { //--- If the stop loss is above Open if((OrderOpenPrice()-Ask) > 50*_Point || OrderStopLoss()==0) if(Ask < (OrderOpenPrice()-50*_Point)) OrderModify( OrderTicket(), OrderOpenPrice(), Ask+35*_Point, OrderTakeProfit(), 0, clrGray ); } } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So ive been trying to code a trailing stop after some profit for my sell positions, Ive been able to successfully code this for my buy positions, but for some reason the trailing stop for my Sell's also move opposite profit and dont just follow the profit
Here's the code: