OrderModify(OrderTicket(), OrderOpenPrice(), Bid + (SellTrailingStop*Point), OrderTakeProfit(), 0, Red); //i think OrderModify(OrderTicket(), OrderOpenPrice(), SellTrailingStop, OrderTakeProfit(), 0, Red); //didn't even checked
on second thought
i dont c Where you define this 3 var. (Length,Deviation,MoneyRisk)
what error u get?
Can you compile it?
R
You are confusing a Points gap with a price level - something like this might work
void CheckForClose() { double BuyTrailingStop= iCustom(Symbol(),0,"BBands_Stop_v2",Length,Deviation,MoneyRisk,4,0); double SellTrailingStop= iCustom(Symbol(),0,"BBands_Stop_v2",Length,Deviation,MoneyRisk,5,0); //----- for(int cnt=0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()==OP_SELL && // check for opened SELL position OrderSymbol()==Symbol()) // check for symbol { if (OrderStopLoss()==0) { if (SellTrailingStop < OrderOpenPrice()) OrderModify(OrderTicket(), OrderOpenPrice(), SellTrailingStop, OrderTakeProfit(), 0, Red); } else { if (SellTrailingStop < OrderStopLoss()) OrderModify(OrderTicket(), OrderOpenPrice(), SellTrailingStop, OrderTakeProfit(), 0, Red); } } else { Print("Error closing order : ",(GetLastError())); } if(OrderType()==OP_BUY && // check for opened BUY position OrderSymbol()==Symbol()) // check for symbol { if (OrderStopLoss()==0) { if (BuyTrailingStop > OrderOpenPrice()) OrderModify(OrderTicket(), OrderOpenPrice(), BuyTrailingStop, OrderTakeProfit(), 0, Green); } else { if (BuyTrailingStop > OrderStopLoss()) OrderModify(OrderTicket(), OrderOpenPrice(), BuyTrailingStop, OrderTakeProfit(), 0, Green); } } else { Print("Error closing order : ",(GetLastError())); } } }
Good Luck
-BB-
on second thought
i dont c Where you define this 3 var. (Length,Deviation,MoneyRisk)
what error u get?
Can you compile it?
I can compile it. It is on the top of the expert (external).
Thanks for your help. Always trying to help me out with my mistakes.
The BarrowBoy is correct, and his formula worked well. I will study it to understand better. Thanks a lot BarrowBoy for your help.
I can compile it. It is on the top of the expert (external).
Thanks for your help. Always trying to help me out with my mistakes.
The BarrowBoy is correct, and his formula worked well. I will study it to understand better. Thanks a lot BarrowBoy for your help.
Look at my first suggestion
Look at my first suggestion
Yeah, I saw it. But I already tried it before and it did not work. For this reason I insert the “Point” on the formula (which was a mistake).
- 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 was implementing a trailing stop on an expert. I did it based on an indicator called " BBands_Stop_v2 " (I will post the code below). When a backtest the expert in a visual mode I can see the trailing stop line, but it never works, never closes my positions.
I would love if someone could tell me where I'm doing a mistake in the code.
Indicator code -
my Expert Code: