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.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Could you explain more on this please, @generic? On how to use a CompoundValue. I am in the process of trying to do something similar in one of my projects.
 
@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);
 
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 by a moderator:
@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 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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
349 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top