sean.gummer
New member
Background: I am trying to customize a trailing stop for when price is 3% profitable, set a 1% trailing stop (Short SELL in this example).
I am trying to set a variable and retain it's value. Use case is once price moves 3% (down for short sell) I want to retain that specific LOW value.
CODE:
input trailDelay = 0.03;
def trailDelayMult = 1 - trailDelay;
def lowPrice = entryPrice * trailDelayMult;
def Alpha = if low <= lowPrice then low else 0;
def Bravo = if low < Alpha then low else Alpha;
I get the LOW value for the first bar that is <= entryPrice * (1-0.03), but then it resets in the proceeding bars to their low values (the ones that are below 3% profitable). I know that the code above is resetting at each bar when parameters are met.
I can not figure out how to set a variable and retain it's value until a position is closed. Any help would be appreciated!
I am trying to set a variable and retain it's value. Use case is once price moves 3% (down for short sell) I want to retain that specific LOW value.
CODE:
input trailDelay = 0.03;
def trailDelayMult = 1 - trailDelay;
def lowPrice = entryPrice * trailDelayMult;
def Alpha = if low <= lowPrice then low else 0;
def Bravo = if low < Alpha then low else Alpha;
I get the LOW value for the first bar that is <= entryPrice * (1-0.03), but then it resets in the proceeding bars to their low values (the ones that are below 3% profitable). I know that the code above is resetting at each bar when parameters are met.
I can not figure out how to set a variable and retain it's value until a position is closed. Any help would be appreciated!