monkey dolphin
New member
Im trying to edit the ATR Trailing Stop indicator to input a tick value instead of a ATR value, Im only using it in /NQ, I dont know coding, but I managed to change it a bit but the stop does not trigger unless the bar is completely over the stop line, is there a way so the stop loss reverses as soon as the price touches the stop loss line? Here is the code I edited, any help will be appreciated thanks.
Code:
input trailType = {default modified, unmodified};
input ReversalInTicks = 120;
input firstTrade = {default long, short};
input averageType = AverageType.WILDERS;
def loss = reversalInTicks/4;
def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = high - loss;
case short:
state = state.short;
trail = low + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (high > trail[1]) {
state = state.long;
trail = max(trail[1], high - loss);
} else {
state = state.short;
trail = high + loss;
}
case short:
if (low < trail[1]) {
state = state.short;
trail = Min(trail[1], low + loss);
} else {
state = state.long;
trail = low - loss;
}
}
def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);
plot TrailingStop = trail;
TrailingStop.SetPaintingStrategy(PaintingStrategy.line);
TrailingStop.DefineColor("Buy", Color.green);
TrailingStop.DefineColor("Sell", Color.green);
TrailingStop.AssignValueColor(if state == state.long
then TrailingStop.Color("Sell")
else TrailingStop.Color("Buy"));