Mimicking "Power X Strategy" by Markus Heitkoetter

Status
Not open for further replies.
@Sree - I added the ATR calculation as part of the additional updates from the previous screenshots I posted. I'll see if I can update the code for the labels so that updates as well based on the new trend. I'll get a fresh version of the code up today most likely. Thanks again for all the feedback, I'm happy to work on this as it is very conducive to my learning and trading. Thanks for the opportunity.
@cos251 Sorry to hijack this thread but I did not know how else to contact you. Amazing work on the RAF indicator. I had been using a previous TOS import link. Could you please kindly share you latest TOS link with the final versions of all RAF studies please? [https://usethinkscript.com/threads/...e-overbought-oversold.2592/page-11#post-43040]. Best Regards. And really thanks a lot in advance.
 

BenTen's Watchlist + Setup + Trade Recaps

Get access to Ben's watchlist, swing trading strategy, ThinkorSwim setup, and trade examples.

Learn more

@cos251 Sorry to hijack this thread but I did not know how else to contact you. Amazing work on the RAF indicator. I had been using a previous TOS import link. Could you please kindly share you latest TOS link with the final versions of all RAF studies please? [https://usethinkscript.com/threads/...e-overbought-oversold.2592/page-11#post-43040]. Best Regards. And really thanks a lot in advance.
Hi @newbie19760123 - sure thing. Just to make sure you are referring to the Ready Aim Fire replica we have going in thread you linked to correct?
 
Last edited:
Alphabet was priming well for a long this morning and I was ready to pull the trigger on an Options Swing trade, but then the market decided to grind sideways...so, waiting for proper signals. According to my fib retracement analysis, if the market decides to go up, profit target is $1874. Good support at this point seems to be between 1817 and 1809. May be an entry order at 1809? perhaps at 1791 if 1809 support fails? What do you all think?
 
Last edited:
I added the ATR calculation as part of the additional updates from the previous screenshots I posted. I'll see if I can update the code for the labels so that updates as well based on the new trend. I'll get a fresh version of the code up today most likely.
Hi Cos251, any updates on release of the next updated version?
 
Yes @cos251 that is exactly what I am thinking of. If it can also be done on a daily chart- example 6 mo / 1 day it would be awesome sauce! I am gladly willing to send you some beer money via paypal to your email if you like as a means of Thanks :D. Not sure if there is an option to private message you to keep emails off the public forums
I will be willing to match that beer money also! Just let me know how much!!
 
Hi Cos251, any updates on release of the next updated version?
Hi guys. Sorry got side tracked last night and today. I did not get a chance to fix the profit target labels with the ATR adjustments as requested yet. I will do my best to update that section. But for now let me post the two updates I do have.
Updates are as follows
1. Added ATR calculation so it can be used instead of ADR - this option can be selected in settings
2. Added additional profit target plots - +/- 1,2,3 targets.
3. Added the shading to the profit targets - the catch here is that the shading will only be for the trend above or below daily open. So if the price is above daily open and the underlying goes into a downtrend it will not provide new profit targets or plots in that direction - at least not yet.

This is where we are at. I know we have a couple of outstanding updates still pending. The backtesting strategy with all 3 indicators at the bottom and the adjustments to the profit target labels. I also think there was another request to add a couple of other moving average calculations that could be selected in addition to the defaults available.

@Sree - please let me know if the ATR calculation I added is what you were intending - want to make sure we get your updates in as requested.

Lastly - I know there are now several iterations of this study and strategy - please feel free to modify, adjust and change any of the provided samples to suit your needs as you see fit.

Current code below:

EDIT
See below for link to latest code
https://usethinkscript.com/threads/rsm-indicator-for-thinkorswim.5407/
 
Last edited:
I have also been using this script on my 1m or 2m chart for the last couple of weeks. I finally got around to updating it so the labels are added dynamically based on your current charts timeframe. This is an MTF Labels version of the UpTrend or DownTrend for the following timeframes:
- 1m, 2m, 5m, 15m, 30m, 1h, 2h, 4h, D
Time frames will show up for the current chart TF and above up to the Daily. If you want I can add more, I figured up to the Daily was sufficient for now.

TronKVE.png


EDIT
See below for link to latest code
https://usethinkscript.com/threads/rsm-indicator-for-thinkorswim.5407/
 
Last edited:
Thanks Cos! I copy pasted the code, but not seeing anything. not sure what I missed. Could you please post screenshot from your side to show how it appears?
 
Thanks Cos! I copy pasted the code, but not seeing anything. not sure what I missed. Could you please post screenshot from your side to show how it appears?
I did a quick copy paste from the code in post 150 and it worked for me. Let me know if it is bad and I can post a shared link to the study instead.

The ADR/ATR calculations are based on the DAY TF. I can add an option to change the aggregation period for the calculation of both and see how that comes out.

This is what the options should look like. The difference in price targets are reflected below
ATR Options
BrA9oLu.png

Example of BA ADR today
HcqHzql.png


ATR Option
RsGgprD.png

Example of BA ATR today
zvVQYw8.png
 
I did a quick copy paste from the code in post 150 and it worked for me. Let me know if it is bad and I can post a shared link to the study instead.

The ADR/ATR calculations are based on the DAY TF. I can add an option to change the aggregation period for the calculation of both and see how that comes out.

This is what the options should look like. The difference in price targets are reflected below
ATR Options
BrA9oLu.png

Example of BA ADR today
HcqHzql.png


ATR Option
RsGgprD.png

Example of BA ATR today
zvVQYw8.png
I'm not able to see your screen shots, but never mind, the indicator appeared on my screen now. I do see a 1 candle discrepancy between prior version and this version...I have tried switching between ATR and ADR, it still is there...The lower study is older version, the upper is V1.3

discrepancy.jpg
 
Comparing the plot against the individual studies on the lower, V1.3 is more accurate though...so, its good so far. I will observe more on tomorrow's market and will keep you posted.
 
Comparing the plot against the individual studies on the lower, V1.3 is more accurate though...so, its good so far. I will observe more on tomorrow's market and will keep you posted.
Hi Sree,

You have got much better visual setup.. Can you share the studies you used or share chart button? Thanks!
 
@cos251:

I tried to create a scan with the study code of post #151. But, I am getting an error message.
"Script.Runtime. ToolComplexException. The complexity of the expression that it may not be reliable with real-time data. "

How can I generate a scan from your latest script providing me the stocks with a Long Signal (changing from downtrend to uptrend)?
 
I have also been using this script on my 1m or 2m chart for the last couple of weeks. I finally got around to updating it so the labels are added dynamically based on your current charts timeframe. This is an MTF Labels version of the UpTrend or DownTrend for the following timeframes:
- 1m, 2m, 5m, 15m, 30m, 1h, 2h, 4h, D
Time frames will show up for the current chart TF and above up to the Daily. If you want I can add more, I figured up to the Daily was sufficient for now.

TronKVE.png


Code:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
#FVO_RSM_MTF_SIGNALS_V2
#
#CHANGELOG
#
# 2020.12.02 V1.0 @cos251 - Added RSM signal calculation for following timeframes:
#                         - 1m, 2m, 5m, 15m, 30m, 1h, 2h, 4h, D
#                         - Label will be added to top of chart for every allowed TF
#                         - Label will read "TF:L(Long):S(Short):I(Idle)"
#                         - Label Color will be green, red or gray accordingly
#
#                  
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 5(not14) and 3 WILDERS
#               MACD 12,26,9 WEIGHTED
#
#ORIGINAL REQUEST - @Joseph Patrick 18
#                 - Link: https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/
#
#


AddLabel(yes, "::RSM-Signal::", Color.ORANGE);

# Timeframe boolean variables
def one_min_bool;
def two_min_bool;
def five_min_bool;
def fifteen_min_bool;
def thirty_min_bool;
def one_hour_bool;
def two_hour_bool;
def four_hour_bool;
def one_day_bool;

# Check if current chart is less that Day Aggregation Period
def ltDay = if GetAggregationPeriod() < AggregationPeriod.DAY then 1 else Double.NaN;
# Set Chart for 1m
if GetAggregationPeriod() == AggregationPeriod.MIN {
    one_min_bool = 1;
} else {
    one_min_bool = 0;
}
# Set Chart for 2m
if GetAggregationPeriod() == AggregationPeriod.TWO_MIN {
    two_min_bool = 1;
} else {
    two_min_bool = 0;
}
# Set Chart for 5m
if GetAggregationPeriod() == AggregationPeriod.FIVE_MIN {
    five_min_bool = 1;
} else {
    five_min_bool = 0;
}
# Set Chart for 15mm
if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN {
    fifteen_min_bool = 1;
} else {
    fifteen_min_bool = 0;
}
# Set Chart for 30m
if GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN {
    thirty_min_bool = 1;
} else {
    thirty_min_bool = 0;
}
# Set Chart for 1 HOUR
if GetAggregationPeriod() == AggregationPeriod.HOUR {
    one_hour_bool = 1;
} else {
    one_hour_bool = 0;
}
# Set Chart for 2 HOURS
if GetAggregationPeriod() == AggregationPeriod.TWO_HOURS {
    two_hour_bool = 1;
} else {
    two_hour_bool = 0;
}
# Set Chart for 4 HOUR
if GetAggregationPeriod() == AggregationPeriod.FOUR_HOURS {
    four_hour_bool = 1;
} else {
    four_hour_bool = 0;
}
# Set Chart for 1 DAY
if GetAggregationPeriod() == AggregationPeriod.DAY {
    one_day_bool = 1;
} else {
    one_day_bool = 0;
}


################################################################
##########            Global Variables                 #########
################################################################
# inputs are set per the Power-X Strategy
# Link: https://rockwell-files.s3.amazonaws.com/PXCompanionGuide2ndEd_cover.pdf
# RSI
input lengthRSI = 7;
input averageTypeRSI = AverageType.EXPONENTIAL;
# Stochastic
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 5;
input DPeriod = 3;
input averageTypeStoch = AverageType.WILDERS;
# MACD
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;








################################################################
##########                 RSI                         #########
################################################################
# 1 Minute
def NetChgAvg1m;
def TotChgAvg1m;
def ChgRatio1m;
def RSI_1m;
if GetAggregationPeriod() <= AggregationPeriod.MIN {

    NetChgAvg1m = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.MIN) - close(period = AggregationPeriod.MIN)[1], lengthRSI);
    TotChgAvg1m = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.MIN) - close(period = AggregationPeriod.MIN)[1]), lengthRSI);
    ChgRatio1m = if TotChgAvg1m != 0 then NetChgAvg1m / TotChgAvg1m else 0;
    RSI_1m = 50 * (ChgRatio1m + 1);
} else {
    NetChgAvg1m = 0;
    TotChgAvg1m = 0;
    ChgRatio1m = 0;
    RSI_1m = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 1 Minute
def SlowK_1m;
def SlowD_1m;
if GetAggregationPeriod() <= AggregationPeriod.MIN {
    SlowK_1m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.MIN), low(period =
        AggregationPeriod.MIN), close(period = AggregationPeriod.MIN), 3, averageTypeStoch).FullK;
    SlowD_1m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.MIN), low(period =
        AggregationPeriod.MIN), close(period = AggregationPeriod.MIN), 3, averageTypeStoch).FullD;
} else {
    SlowK_1m = 0;
    SlowD_1m = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 1 Minute
def Value_1m;
def Avg_1m;
def Diff_1m;
if GetAggregationPeriod() <= AggregationPeriod.MIN {
    Value_1m = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.MIN), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.MIN), slowLength);
    Avg_1m = MovingAverage(averageTypeMACD, Value_1m, MACDLength);
    Diff_1m = Value_1m - Avg_1m;
} else {
    Value_1m = 0;
    Avg_1m = 0;
    Diff_1m = 0;
}
#################################################################
##########        1m  Trend  & Labels                   #########
#################################################################
plot UpTrend_1m = if RSI_1m >= 50 and SlowK_1m >= 50 and Value_1m > Avg_1m then 1 else 0;
plot DownTrend_1m = if RSI_1m < 50 and SlowK_1m < 50 and Value_1m < Avg_1m then 1 else 0;
UpTrend_1m.Hide();
DownTrend_1m.Hide();
AddLabel(if (one_min_bool == 1) then yes else no, if UpTrend_1m == 1 then "1m:L" else if DownTrend_1m == 1 then "1m:S" else "1m:I", if UpTrend_1m == 1 then Color.GREEN else if DownTrend_1m == 1 then Color.RED else Color.GRAY);








################################################################
##########                 RSI                         #########
################################################################
# 2 Minute
def NetChgAvg2m;
def TotChgAvg2m;
def ChgRatio2m;
def RSI_2m;
if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN {

    NetChgAvg2m = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.TWO_MIN) - close(period = AggregationPeriod.TWO_MIN)[1], lengthRSI);
    TotChgAvg2m = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.TWO_MIN) - close(period = AggregationPeriod.TWO_MIN)[1]), lengthRSI);
    ChgRatio2m = if TotChgAvg2m != 0 then NetChgAvg2m / TotChgAvg2m else 0;
    RSI_2m = 50 * (ChgRatio2m + 1);
} else {
    NetChgAvg2m = 0;
    TotChgAvg2m = 0;
    ChgRatio2m = 0;
    RSI_2m = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 2 Minute
def SlowK_2m;
def SlowD_2m;
if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN {
    SlowK_2m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.TWO_MIN), low(period =
        AggregationPeriod.TWO_MIN), close(period = AggregationPeriod.TWO_MIN), 3, averageTypeStoch).FullK;
    SlowD_2m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.TWO_MIN), low(period =
        AggregationPeriod.TWO_MIN), close(period = AggregationPeriod.TWO_MIN), 3, averageTypeStoch).FullD;
} else {
    SlowK_2m = 0;
    SlowD_2m = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 2 Minute
def Value_2m;
def Avg_2m;
def Diff_2m;
if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN {
    Value_2m = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.TWO_MIN), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.TWO_MIN), slowLength);
    Avg_2m = MovingAverage(averageTypeMACD, Value_2m, MACDLength);
    Diff_2m = Value_2m - Avg_2m;
} else {
    Value_2m = 0;
    Avg_2m = 0;
    Diff_2m = 0;
}
#################################################################
##########        2m  Trend  & Labels                   #########
#################################################################
plot UpTrend_2m = if RSI_2m >= 50 and SlowK_2m >= 50 and Value_2m > Avg_2m then 1 else 0;
plot DownTrend_2m = if RSI_2m < 50 and SlowK_2m < 50 and Value_2m < Avg_2m then 1 else 0;
UpTrend_2m.Hide();
DownTrend_2m.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or ltDay) then yes else no, if UpTrend_2m == 1 then "2m:L" else if DownTrend_2m == 1 then "2m:S" else "2m:I", if UpTrend_2m == 1 then Color.GREEN else if DownTrend_2m == 1 then Color.RED else Color.GRAY);




################################################################
##########                 RSI                         #########
################################################################
# 5 Minute
def NetChgAvg5m;
def TotChgAvg5m;
def ChgRatio5m;
def RSI_5m;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {

    NetChgAvg5m = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.FIVE_MIN) - close(period = AggregationPeriod.FIVE_MIN)[1], lengthRSI);
    TotChgAvg5m = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.FIVE_MIN) - close(period = AggregationPeriod.FIVE_MIN)[1]), lengthRSI);
    ChgRatio5m = if TotChgAvg5m != 0 then NetChgAvg5m / TotChgAvg5m else 0;
    RSI_5m = 50 * (ChgRatio5m + 1);
} else {
    NetChgAvg5m = 0;
    TotChgAvg5m = 0;
    ChgRatio5m = 0;
    RSI_5m = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 5 Minute
def SlowK_5m;
def SlowD_5m;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
    SlowK_5m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.FIVE_MIN), low(period =
        AggregationPeriod.FIVE_MIN), close(period = AggregationPeriod.FIVE_MIN), 3, averageTypeStoch).FullK;
    SlowD_5m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.FIVE_MIN), low(period =
        AggregationPeriod.FIVE_MIN), close(period = AggregationPeriod.FIVE_MIN), 3, averageTypeStoch).FullD;
} else {
    SlowK_5m = 0;
    SlowD_5m = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 5 Minute
def Value_5m;
def Avg_5m;
def Diff_5m;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
    Value_5m = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.FIVE_MIN), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.FIVE_MIN), slowLength);
    Avg_5m = MovingAverage(averageTypeMACD, Value_5m, MACDLength);
    Diff_5m = Value_5m - Avg_5m;
} else {
    Value_5m = 0;
    Avg_5m = 0;
    Diff_5m = 0;
}
#################################################################
##########        5m  Trend  & Labels                   #########
#################################################################
plot UpTrend_5m = if RSI_5m >= 50 and SlowK_5m >= 50 and Value_5m > Avg_5m then 1 else 0;
plot DownTrend_5m = if RSI_5m < 50 and SlowK_5m < 50 and Value_5m < Avg_5m then 1 else 0;
UpTrend_5m.Hide();
DownTrend_5m.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or five_min_bool == 1 or ltDay) then yes else no, if UpTrend_5m == 1 then "5m:L" else if DownTrend_5m == 1 then "5m:S" else "5m:I", if UpTrend_5m == 1 then Color.GREEN else if DownTrend_5m == 1 then Color.RED else Color.GRAY);








################################################################
##########                 RSI                         #########
################################################################
# 15 Minute
def NetChgAvg15m;
def TotChgAvg15m;
def ChgRatio15m;
def RSI_15m;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {

    NetChgAvg15m = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.FIFTEEN_MIN) - close(period = AggregationPeriod.FIFTEEN_MIN)[1], lengthRSI);
    TotChgAvg15m = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.FIFTEEN_MIN) - close(period = AggregationPeriod.FIFTEEN_MIN)[1]), lengthRSI);
    ChgRatio15m = if TotChgAvg15m != 0 then NetChgAvg15m / TotChgAvg15m else 0;
    RSI_15m = 50 * (ChgRatio15m + 1);
} else {
    NetChgAvg15m = 0;
    TotChgAvg15m = 0;
    ChgRatio15m = 0;
    RSI_15m = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 15 Minute
def SlowK_15m;
def SlowD_15m;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    SlowK_15m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.FIFTEEN_MIN), low(period =
        AggregationPeriod.FIFTEEN_MIN), close(period = AggregationPeriod.FIFTEEN_MIN), 3, averageTypeStoch).FullK;
    SlowD_15m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.FIFTEEN_MIN), low(period =
        AggregationPeriod.FIFTEEN_MIN), close(period = AggregationPeriod.FIFTEEN_MIN), 3, averageTypeStoch).FullD;
} else {
    SlowK_15m = 0;
    SlowD_15m = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 15 Minute
def Value_15m;
def Avg_15m;
def Diff_15m;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    Value_15m = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.FIFTEEN_MIN), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.FIFTEEN_MIN), slowLength);
    Avg_15m = MovingAverage(averageTypeMACD, Value_15m, MACDLength);
    Diff_15m = Value_15m - Avg_15m;
} else {
    Value_15m = 0;
    Avg_15m = 0;
    Diff_15m = 0;
}
#################################################################
##########        15m  Trend  & Labels                   #########
#################################################################
plot UpTrend_15m = if RSI_15m >= 50 and SlowK_15m >= 50 and Value_15m > Avg_15m then 1 else 0;
plot DownTrend_15m = if RSI_15m < 50 and SlowK_15m < 50 and Value_15m < Avg_15m then 1 else 0;
UpTrend_15m.Hide();
DownTrend_15m.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or five_min_bool == 1 or fifteen_min_bool == 1 or ltDay) then yes else no, if UpTrend_15m == 1 then "15m:L" else if DownTrend_15m == 1 then "15m:S" else "15m:I", if UpTrend_15m == 1 then Color.GREEN else if DownTrend_15m == 1 then Color.RED else Color.GRAY);






################################################################
##########                 RSI                         #########
################################################################
# 30 Minute
def NetChgAvg30m;
def TotChgAvg30m;
def ChgRatio30m;
def RSI_30m;
if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {

    NetChgAvg30m = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.THIRTY_MIN) - close(period = AggregationPeriod.THIRTY_MIN)[1], lengthRSI);
    TotChgAvg30m = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.THIRTY_MIN) - close(period = AggregationPeriod.THIRTY_MIN)[1]), lengthRSI);
    ChgRatio30m = if TotChgAvg30m != 0 then NetChgAvg30m / TotChgAvg30m else 0;
    RSI_30m = 50 * (ChgRatio30m + 1);
} else {
    NetChgAvg30m = 0;
    TotChgAvg30m = 0;
    ChgRatio30m = 0;
    RSI_30m = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 30 Minute
def SlowK_30m;
def SlowD_30m;
if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
    SlowK_30m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.THIRTY_MIN), low(period =
        AggregationPeriod.THIRTY_MIN), close(period = AggregationPeriod.THIRTY_MIN), 3, averageTypeStoch).FullK;
    SlowD_30m = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.THIRTY_MIN), low(period =
        AggregationPeriod.THIRTY_MIN), close(period = AggregationPeriod.THIRTY_MIN), 3, averageTypeStoch).FullD;
} else {
    SlowK_30m = 0;
    SlowD_30m = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 30 Minute
def Value_30m;
def Avg_30m;
def Diff_30m;
if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
    Value_30m = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.THIRTY_MIN), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.THIRTY_MIN), slowLength);
    Avg_30m = MovingAverage(averageTypeMACD, Value_30m, MACDLength);
    Diff_30m = Value_30m - Avg_30m;
} else {
    Value_30m = 0;
    Avg_30m = 0;
    Diff_30m = 0;
}
#################################################################
##########        30m  Trend  & Labels                   #########
#################################################################
plot UpTrend_30m = if RSI_30m >= 50 and SlowK_30m >= 50 and Value_30m > Avg_30m then 1 else 0;
plot DownTrend_30m = if RSI_30m < 50 and SlowK_30m < 50 and Value_30m < Avg_30m then 1 else 0;
UpTrend_30m.Hide();
DownTrend_30m.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or five_min_bool == 1 or fifteen_min_bool == 1 or thirty_min_bool == 1 or ltDay) then yes else no, if UpTrend_30m == 1 then "30m:L" else if DownTrend_30m == 1 then "30m:S" else "30m:I", if UpTrend_30m == 1 then Color.GREEN else if DownTrend_30m == 1 then Color.RED else Color.GRAY);








################################################################
##########                 RSI                         #########
################################################################
# 1 HOUR
def NetChgAvg1h;
def TotChgAvg1h;
def ChgRatio1h;
def RSI_1h;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {

    NetChgAvg1h = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.HOUR) - close(period = AggregationPeriod.HOUR)[1], lengthRSI);
    TotChgAvg1h = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.HOUR) - close(period = AggregationPeriod.HOUR)[1]), lengthRSI);
    ChgRatio1h = if TotChgAvg1h != 0 then NetChgAvg1h / TotChgAvg1h else 0;
    RSI_1h = 50 * (ChgRatio1h + 1);
} else {
    NetChgAvg1h = 0;
    TotChgAvg1h = 0;
    ChgRatio1h = 0;
    RSI_1h = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 1 HOUR
def SlowK_1h;
def SlowD_1h;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    SlowK_1h = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.HOUR), low(period =
        AggregationPeriod.HOUR), close(period = AggregationPeriod.HOUR), 3, averageTypeStoch).FullK;
    SlowD_1h = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.HOUR), low(period =
        AggregationPeriod.HOUR), close(period = AggregationPeriod.HOUR), 3, averageTypeStoch).FullD;
} else {
    SlowK_1h = 0;
    SlowD_1h = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 1 HOUR
def Value_1h;
def Avg_1h;
def Diff_1h;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    Value_1h = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.HOUR), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.HOUR), slowLength);
    Avg_1h = MovingAverage(averageTypeMACD, Value_1h, MACDLength);
    Diff_1h = Value_1h - Avg_1h;
} else {
    Value_1h = 0;
    Avg_1h = 0;
    Diff_1h = 0;
}
#################################################################
##########        1h  Trend  & Labels                   #########
#################################################################
plot UpTrend_1h = if RSI_1h >= 50 and SlowK_1h >= 50 and Value_1h > Avg_1h then 1 else 0;
plot DownTrend_1h = if RSI_1h < 50 and SlowK_1h < 50 and Value_1h < Avg_1h then 1 else 0;
UpTrend_1h.Hide();
DownTrend_1h.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or five_min_bool == 1 or fifteen_min_bool == 1 or thirty_min_bool == 1 or one_hour_bool == 1 or ltDay) then yes else no, if UpTrend_1h == 1 then "1h:L" else if DownTrend_1h == 1 then "1h:S" else "1h:I", if UpTrend_1h == 1 then Color.GREEN else if DownTrend_1h == 1 then Color.RED else Color.GRAY);








################################################################
##########                 RSI                         #########
################################################################
# 2 HOUR
def NetChgAvg2h;
def TotChgAvg2h;
def ChgRatio2h;
def RSI_2h;
if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {

    NetChgAvg2h = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.TWO_HOURS) - close(period = AggregationPeriod.TWO_HOURS)[1], lengthRSI);
    TotChgAvg2h = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.TWO_HOURS) - close(period = AggregationPeriod.TWO_HOURS)[1]), lengthRSI);
    ChgRatio2h = if TotChgAvg2h != 0 then NetChgAvg2h / TotChgAvg2h else 0;
    RSI_2h = 50 * (ChgRatio2h + 1);
} else {
    NetChgAvg2h = 0;
    TotChgAvg2h = 0;
    ChgRatio2h = 0;
    RSI_2h = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 2 HOUR
def SlowK_2h;
def SlowD_2h;
if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
    SlowK_2h = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.TWO_HOURS), low(period =
        AggregationPeriod.TWO_HOURS), close(period = AggregationPeriod.TWO_HOURS), 3, averageTypeStoch).FullK;
    SlowD_2h = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.TWO_HOURS), low(period =
        AggregationPeriod.TWO_HOURS), close(period = AggregationPeriod.TWO_HOURS), 3, averageTypeStoch).FullD;
} else {
    SlowK_2h = 0;
    SlowD_2h = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 2 HOUR
def Value_2h;
def Avg_2h;
def Diff_2h;
if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
    Value_2h = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.TWO_HOURS), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.TWO_HOURS), slowLength);
    Avg_2h = MovingAverage(averageTypeMACD, Value_2h, MACDLength);
    Diff_2h = Value_2h - Avg_2h;
} else {
    Value_2h = 0;
    Avg_2h = 0;
    Diff_2h = 0;
}
#################################################################
##########        2h  Trend  & Labels                   #########
#################################################################
plot UpTrend_2h = if RSI_2h >= 50 and SlowK_2h >= 50 and Value_2h > Avg_2h then 1 else 0;
plot DownTrend_2h = if RSI_2h < 50 and SlowK_2h < 50 and Value_2h < Avg_2h then 1 else 0;
UpTrend_2h.Hide();
DownTrend_2h.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or five_min_bool == 1 or fifteen_min_bool == 1 or thirty_min_bool == 1 or one_hour_bool == 1 or two_hour_bool == 1 or ltDay) then yes else no, if UpTrend_2h == 1 then "2h:L" else if DownTrend_2h == 1 then "2h:S" else "2h:I", if UpTrend_2h == 1 then Color.GREEN else if DownTrend_2h == 1 then Color.RED else Color.GRAY);








################################################################
##########                 RSI                         #########
################################################################
# 4 HOUR
def NetChgAvg4h;
def TotChgAvg4h;
def ChgRatio4h;
def RSI_4h;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {

    NetChgAvg4h = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.FOUR_HOURS) - close(period = AggregationPeriod.FOUR_HOURS)[1], lengthRSI);
    TotChgAvg4h = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.FOUR_HOURS) - close(period = AggregationPeriod.FOUR_HOURS)[1]), lengthRSI);
    ChgRatio4h = if TotChgAvg4h != 0 then NetChgAvg4h / TotChgAvg4h else 0;
    RSI_4h = 50 * (ChgRatio4h + 1);
} else {
    NetChgAvg4h = 0;
    TotChgAvg4h = 0;
    ChgRatio4h = 0;
    RSI_4h = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 4 HOUR
def SlowK_4h;
def SlowD_4h;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    SlowK_4h = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.FOUR_HOURS), low(period =
        AggregationPeriod.FOUR_HOURS), close(period = AggregationPeriod.FOUR_HOURS), 3, averageTypeStoch).FullK;
    SlowD_4h = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.FOUR_HOURS), low(period =
        AggregationPeriod.FOUR_HOURS), close(period = AggregationPeriod.FOUR_HOURS), 3, averageTypeStoch).FullD;
} else {
    SlowK_4h = 0;
    SlowD_4h = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 4 HOUR
def Value_4h;
def Avg_4h;
def Diff_4h;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    Value_4h = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.FOUR_HOURS), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.FOUR_HOURS), slowLength);
    Avg_4h = MovingAverage(averageTypeMACD, Value_4h, MACDLength);
    Diff_4h = Value_4h - Avg_4h;
} else {
    Value_4h = 0;
    Avg_4h = 0;
    Diff_4h = 0;
}
#################################################################
##########        4h  Trend  & Labels                   #########
#################################################################
plot UpTrend_4h = if RSI_4h >= 50 and SlowK_4h >= 50 and Value_4h > Avg_4h then 1 else 0;
plot DownTrend_4h = if RSI_4h < 50 and SlowK_4h < 50 and Value_4h < Avg_4h then 1 else 0;
UpTrend_4h.Hide();
DownTrend_4h.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or five_min_bool == 1 or fifteen_min_bool == 1 or thirty_min_bool == 1 or one_hour_bool == 1 or two_hour_bool == 1 or four_hour_bool == 1 or ltDay) then yes else no, if UpTrend_4h == 1 then "4h:L" else if DownTrend_4h == 1 then "4h:S" else "4h:I", if UpTrend_4h == 1 then Color.GREEN else if DownTrend_4h == 1 then Color.RED else Color.GRAY);










################################################################
##########                 RSI                         #########
################################################################
# 1 DAY
def NetChgAvg1d;
def TotChgAvg1d;
def ChgRatio1d;
def RSI_1d;
if GetAggregationPeriod() <= AggregationPeriod.DAY {

    NetChgAvg1d = MovingAverage(averageTypeRSI, close(period = AggregationPeriod.DAY) - close(period = AggregationPeriod.DAY)[1], lengthRSI);
    TotChgAvg1d = MovingAverage(averageTypeRSI, AbsValue(close(period = AggregationPeriod.DAY) - close(period = AggregationPeriod.DAY)[1]), lengthRSI);
    ChgRatio1d = if TotChgAvg1d != 0 then NetChgAvg1d / TotChgAvg1d else 0;
    RSI_1d = 50 * (ChgRatio1d + 1);
} else {
    NetChgAvg1d = 0;
    TotChgAvg1d = 0;
    ChgRatio1d = 0;
    RSI_1d = 0;
}
################################################################
##########                 Stochastic Slow             #########
################################################################
# Stochastic 1 DAY
def SlowK_1d;
def SlowD_1d;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
    SlowK_1d = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.DAY), low(period =
        AggregationPeriod.DAY), close(period = AggregationPeriod.DAY), 3, averageTypeStoch).FullK;
    SlowD_1d = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high(period = AggregationPeriod.DAY), low(period =
        AggregationPeriod.DAY), close(period = AggregationPeriod.DAY), 3, averageTypeStoch).FullD;
} else {
    SlowK_1d = 0;
    SlowD_1d = 0;
}
################################################################
##########                 MACD                      ###########
################################################################
#MACD Calculation
# 1 DAY
def Value_1d;
def Avg_1d;
def Diff_1d;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
    Value_1d = MovingAverage(averageTypeMACD, close(period = AggregationPeriod.DAY), fastLength) - MovingAverage(averageTypeMACD, close(period =
        AggregationPeriod.DAY), slowLength);
    Avg_1d = MovingAverage(averageTypeMACD, Value_1d, MACDLength);
    Diff_1d = Value_1d - Avg_1d;
} else {
    Value_1d = 0;
    Avg_1d = 0;
    Diff_1d = 0;
}
#################################################################
##########        1d  Trend  & Labels                   #########
#################################################################
plot UpTrend_1d = if RSI_1d >= 50 and SlowK_1d >= 50 and Value_1d > Avg_1d then 1 else 0;
plot DownTrend_1d = if RSI_1d < 50 and SlowK_1d < 50 and Value_1d < Avg_1d then 1 else 0;
UpTrend_1d.Hide();
DownTrend_1d.Hide();
AddLabel(if (one_min_bool == 1 or two_min_bool == 1 or five_min_bool == 1 or fifteen_min_bool == 1 or thirty_min_bool == 1 or one_hour_bool == 1 or two_hour_bool == 1 or four_hour_bool == 1 or one_day_bool == 1 or ltDay) then yes else no, if UpTrend_1d == 1 then "1d:L" else if DownTrend_1d == 1 then "1d:S" else "1d:I", if UpTrend_1d == 1 then Color.GREEN else if DownTrend_1d == 1 then Color.RED else Color.GRAY);


First off Amazing work @cos251 and thank you for putting in the work! I do have a quick question, how can I add an arrow to indicate when the bars are gray? For me keeping the bars clean helps me with my strategy so I have Red and Green arrows turned on for your script so I know when the market is in up trend or down but since I don't have color to my bars it would help me to see when the market is turning "choppy" or sideways.

Thank you so much once again
 
Status
Not open for further replies.

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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