Using a MA Cross as an event to update variable values?

krazymatty

New member
The ATR is a constantly changing value. What I want to do is set a Variable = ATR and not change until a MA Cross happens.

I don't want my Plots that use the ATR Value in their expression to change until a MA Cross Event.
Example:
Code:
def ATR;

if fastEMA > slowEMA and fastEMA[1] <= slowEMA[1] then {
    ATR = MovingAverage(AverageType.WILDERS, TrueRange(high, close, low), 14);

} else {
    ATR = ATR[1]
}

My issue is when the event isn't triggered the ATR is never initially set.
 

generic

Active member
@RickAns Try the script out. It sets data to 1 until the bar number reaches 500+ and after that it'll change to close-MA.
Code:
declare lower;
plot data = compoundValue(500, close - MovingAverage(data = close), 1);
 

RickAns

Active member
Thanks, @generic. That helps.

I guess the use of a bar number in the CompoundValue example at tlc.thinkorswim was confusing me on why it had to be there. Was not looking to have a number counter going on. Maybe I can set bar number to zero if a condition is false and some positive number when condition is true. In order to 'lock in' an ATR value to be plotted horizontally.

edited.
 
Last edited:

RickAns

Active member
@krazymatty when you get this sorted out could you post this part please? I would like to see how you have done it. I have made a little progress from generic's help but still not quite there. Got it to plot my first ATR value at the start of the signal but not continue plotting that value for each next day.
 

krazymatty

New member
@krazymatty when you get this sorted out could you post this part please? I would like to see how you have done it. I have made a little progress from generic's help but still not quite there. Got it to plot my first ATR value at the start of the signal but not continue plotting that value for each next day.
Is your ATR bouncing around each day?
 

Similar threads

Top