Swing Exposure Indicator Request

trendr

Member
Lower Study Based on this:


If the price of $IWM $SPY or $QQQ is BELOW 50dma, I want to limit my exposure to a maximum due to an elevated risk of rollover.

So Labels:
  • Price < 50sma & Price < 5sma = 0% exposure max OR Short
  • Price < 50sma & Price > 5sma = 20% exposure
  • Price < 50sma & Price > 21sma = 40% exposure

If the price of $IWM $SPY or $QQQ is ABOVE 50dma, I want to begin increasing my exposure and be more aggressive as conditions improve.

So Labels:
  • Price > 50sma = 60% exposure max
  • Price > 50sma & Price > 21sma = 80%
  • Price > 50sma & Price > 21sma & Price > 10sma = 100%

I think something like this would benefit the community and myself of course. I saw someone on Twitter post these rules and found them interesting considering the market we are currently in.
 
Last edited:
Lower Study Based on this:


If the price of $IWM $SPY or $QQQ is BELOW 50dma, I want to limit my exposure to a maximum due to an elevated risk of rollover.

So Labels:
  • Price < 50dma & Price < 5dma = 0% exposure max OR Short
  • Price < 50dma & Price > 5dma = 20% exposure
  • Price < 50dma & Price > 21dma = 40% exposure

If the price of $IWM $SPY or $QQQ is ABOVE 50dma, I want to begin increasing my exposure and be more aggressive as conditions improve.

So Labels:
  • Price > 50dma = 60% exposure max
  • Price > 50dma & Price > 21dma = 80%
  • Price > 50dma & Price > 21dma & Price > 10dma = 100%

I think something like this would benefit the community and myself of course. I saw someone on twitter post these rules found them interesting considering the market we are currently in.

what is dma?
displaced average?
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/C-D/DMA
 
Reply sorry it can just be SMA.
DailySMA = Average(fundamental(price, period = aggregationPeriod)[-displace], length);

i think will do what you want

Code:
input avg1_type = AverageType.SIMPLE;
input avg1_price = close;
input avg1_len = 5;
def ma1 = MovingAverage(avg1_type, avg1_price, avg1_len);

input avg2_type = AverageType.SIMPLE;
input avg2_price = close;
input avg2_len = 21;
def ma2 = MovingAverage(avg2_type, avg2_price, avg2_len);

input avg3_type = AverageType.SIMPLE;
input avg3_price = close;
input avg3_len = 50;
def ma3 = MovingAverage(avg3_type, avg3_price, avg3_len);

def per;
def level;
if close < ma3 and close < ma1 then {
# Price < 50sma & Price < 5sma = 0% exposure max OR Short
# red
  per = 0;
  level = 1;

} else if close < ma3 and close > ma1 then {
# Price < 50sma & Price > 5sma = 20% exposure
# magenta
  per = 20;
  level = 2;

} else if close < ma3 and close > ma2 then {
# Price < 50sma & Price > 21sma = 40% exposure
# orange
  per = 40;
  level = 3;

} else if close > ma3 and close > ma2 and close > ma1 then {
# Price > 50sma & Price > 21sma & Price > 10sma = 100%
# green
  per = 100;
  level = 7;

} else if close > ma3 and close > ma2 then {
# Price > 50sma & Price > 21sma = 80%
# cyan
  per = 80;
  level = 6;

} else if close > ma3 then {
# Price > 50sma = 60% exposure max
# yellow
  per = 60;
  level = 5;

} else {
# gray
  per = 50;
  level = 4;
}

addlabel(1,
(per + "%"),
(if level == 1 then color.red
else if level == 2 then color.magenta
else if level == 3 then color.orange
else if level == 5 then color.yellow
else if level == 6 then color.cyan
else if level == 7 then color.green
else color.gray));
#

untested, hopefully no typos...
 
this is great!

@halcyonguy is it possible to be able to choose the index that you want to compare to so that regardless of the equity you may be looking at on your screen, your able to look at the indicator below to get a sense of what the index is doing according to the aforementioned indicator? (i.e. don't want to keep pulling up the index)
 
this is great!

@halcyonguy is it possible to be able to choose the index that you want to compare to so that regardless of the equity you may be looking at on your screen, your able to look at the indicator below to get a sense of what the index is doing according to the aforementioned indicator? (i.e. don't want to keep pulling up the index)

i assume you want everything, including
all the averages, to be based on price data from the chosen index symbol?

yes, just need to change every occurance of close , to,
= close("SPY");
or something similar...

give me a few minutes....
 
this is great!

@halcyonguy is it possible to be able to choose the index that you want to compare to so that regardless of the equity you may be looking at on your screen, your able to look at the indicator below to get a sense of what the index is doing according to the aforementioned indicator? (i.e. don't want to keep pulling up the index)

i think i forgot about making it a lower chart study.
if that is what you want, add this line

declare lower;

Code:
# index_ma_crossings_01

#https://usethinkscript.com/threads/swing-exposure-indicator-request.12567/#post-107660
# is it possible to be able to choose the index that you want to compare to

input symbol = "-";
# if no symbol is entered, use chart symbol for close price
def sym_cls = if (symbol == "-" or isnan(close(symbol))) then close else close(symbol);

input avg1_type = AverageType.SIMPLE;
#input avg1_price = close;
def avg1_price = sym_cls;
input avg1_len = 5;
def ma1 = MovingAverage(avg1_type, avg1_price, avg1_len);

input avg2_type = AverageType.SIMPLE;
#input avg2_price = close;
def avg2_price = sym_cls;
input avg2_len = 21;
def ma2 = MovingAverage(avg2_type, avg2_price, avg2_len);

input avg3_type = AverageType.SIMPLE;
#input avg3_price = close;
def avg3_price = sym_cls;
input avg3_len = 50;
def ma3 = MovingAverage(avg3_type, avg3_price, avg3_len);


input show_average_lines = no;
plot zma1 = ma1;
zma1.sethiding( !show_average_lines );
zma1.SetDefaultColor(Color.violet);

plot zma2 = ma2;
zma2.sethiding( !show_average_lines );
zma2.SetDefaultColor(Color.violet);
zma2.SetStyle(Curve.MEDIUM_DASH);

plot zma3 = ma3;
zma3.sethiding( !show_average_lines );
zma3.SetDefaultColor(Color.violet);
zma3.SetStyle(Curve.short_DASH);

def cls2 = sym_cls;
def per;
def level;
if cls2 < ma3 and cls2 < ma1 then {
# Price < 50sma & Price < 5sma = 0% exposure max OR Short
# red
  per = 0;
  level = 1;

} else if cls2 < ma3 and cls2 > ma1 then {
# Price < 50sma & Price > 5sma = 20% exposure
# magenta
  per = 20;
  level = 2;

} else if cls2 < ma3 and cls2 > ma2 then {
# Price < 50sma & Price > 21sma = 40% exposure
# orange
  per = 40;
  level = 3;

} else if cls2 > ma3 and cls2 > ma2 and cls2 > ma1 then {
# Price > 50sma & Price > 21sma & Price > 10sma = 100%
# green
  per = 100;
  level = 7;

} else if cls2 > ma3 and cls2 > ma2 then {
# Price > 50sma & Price > 21sma = 80%
# cyan
  per = 80;
  level = 6;

} else if cls2 > ma3 then {
# Price > 50sma = 60% exposure max
# yellow
  per = 60;
  level = 5;

} else {
# gray
  per = 50;
  level = 4;
}

addlabel(1, " ", color.black);

addlabel(1, symbol + " " + (per + "%"),
(if level == 1 then color.red
else if level == 2 then color.magenta
else if level == 3 then color.orange
else if level == 5 then color.yellow
else if level == 6 then color.cyan
else if level == 7 then color.green
else color.gray));
#
 
Last edited:
i think i forgot about making it a lower chart study.
if that is what you want, add this line

declare lower;

Code:
# index_ma_crossings_01

#https://usethinkscript.com/threads/swing-exposure-indicator-request.12567/#post-107660
# is it possible to be able to choose the index that you want to compare to

input symbol = "-";
# if no symbol is entered, use chart symbol for close price
def sym_cls = if (symbol == "-" or isnan(close(symbol))) then close else close(symbol);

input avg1_type = AverageType.SIMPLE;
#input avg1_price = close;
def avg1_price = sym_cls;
input avg1_len = 5;
def ma1 = MovingAverage(avg1_type, avg1_price, avg1_len);

input avg2_type = AverageType.SIMPLE;
#input avg2_price = close;
def avg2_price = sym_cls;
input avg2_len = 21;
def ma2 = MovingAverage(avg2_type, avg2_price, avg2_len);

input avg3_type = AverageType.SIMPLE;
#input avg3_price = close;
def avg3_price = sym_cls;
input avg3_len = 50;
def ma3 = MovingAverage(avg3_type, avg3_price, avg3_len);


input show_average_lines = no;
plot zma1 = ma1;
zma1.sethiding( !show_average_lines );
zma1.SetDefaultColor(Color.violet);

plot zma2 = ma2;
zma2.sethiding( !show_average_lines );
zma2.SetDefaultColor(Color.violet);
zma2.SetStyle(Curve.MEDIUM_DASH);

plot zma3 = ma3;
zma3.sethiding( !show_average_lines );
zma3.SetDefaultColor(Color.violet);
zma3.SetStyle(Curve.short_DASH);

def cls2 = sym_cls;
def per;
def level;
if cls2 < ma3 and cls2 < ma1 then {
# Price < 50sma & Price < 5sma = 0% exposure max OR Short
# red
  per = 0;
  level = 1;

} else if cls2 < ma3 and cls2 > ma1 then {
# Price < 50sma & Price > 5sma = 20% exposure
# magenta
  per = 20;
  level = 2;

} else if cls2 < ma3 and cls2 > ma2 then {
# Price < 50sma & Price > 21sma = 40% exposure
# orange
  per = 40;
  level = 3;

} else if cls2 > ma3 and cls2 > ma2 and cls2 > ma1 then {
# Price > 50sma & Price > 21sma & Price > 10sma = 100%
# green
  per = 100;
  level = 7;

} else if cls2 > ma3 and cls2 > ma2 then {
# Price > 50sma & Price > 21sma = 80%
# cyan
  per = 80;
  level = 6;

} else if cls2 > ma3 then {
# Price > 50sma = 60% exposure max
# yellow
  per = 60;
  level = 5;

} else {
# gray
  per = 50;
  level = 4;
}

addlabel(1, " ", color.black);

addlabel(1, symbol + " " + (per + "%"),
(if level == 1 then color.red
else if level == 2 then color.magenta
else if level == 3 then color.orange
else if level == 5 then color.yellow
else if level == 6 then color.cyan
else if level == 7 then color.green
else color.gray));
#
Dude your awesome thank you for you work!! @halcyonguy
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
451 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