Hi There,
I've been playing around with forex generator, just getting into coding. For some reason I can't make a trailing stop work with their inbult trailing stop flex block. So I'd like some help changing this code.
I'd like to change this to move the trailing stop to the Low[1] or High[1] respectivly.... Can someone please advise me if it's possible to change this simply, and possibly what code would need to be changed. I'm just a beginner at this
Thanks in advance!
I've been playing around with forex generator, just getting into coding. For some reason I can't make a trailing stop work with their inbult trailing stop flex block. So I'd like some help changing this code.
QuoteDislikedvoid TrailingStop18()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
double takeprofit = OrderTakeProfit();
if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop18*PipValue*Point)
{
if (OrderStopLoss() < Ask-(TrailingStop18+TrailingGap18)*PipValue*Point)
{
if (NewTakeProfit18 != 0) takeprofit = Ask+(NewTakeProfit18 + TrailingStop18)*PipValue*Point;
bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask-TrailingStop18*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret1 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TrailingStop18*PipValue*Point)
{
if (OrderStopLoss() > Bid+(TrailingStop18+TrailingGap18)*PipValue*Point)
{
if (NewTakeProfit18 != 0) takeprofit = Bid-(NewTakeProfit18 + TrailingStop18)*PipValue*Point;
bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(), Bid+TrailingStop18*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret2 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
}
}
else
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
Thanks in advance!