Mimicking "Power X Strategy" by Markus Heitkoetter

Status
Not open for further replies.
A screen shot for the above code.

The AddLabels can be commented out since jox51 posted a nicer version of them.

2020-12-20-17-56.png
 
Last edited by a moderator:
Guess I should have said. I had been messing about with his "2020.10.27 V1.0". Probably should have tested this on his latest to see if any conflicts from his recent changes. Was excited I got my project working. :) I will try this on his latest in a bit. Time to eat and I am hungry.
 
Here is what I have of my working version (cos251 "2020.10.27 V1.0" ). Will test on his latest version later this evening. Maybe delete my above posts to clean things up.

Code:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
#
#CHANGELOG
# 2020.10.27 V1.0 @cos251 - Added RSI, StochasticSlow and MACD to same indicator
#             - also calculates MACD;
#               Will shade the lower plot area if the following conditions are met
#                    Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg
#                    Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg
#                  
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 5(not14) and 3 WILDERS
#               MACD 12,26,9 WEIGHTED

declare upper;

################################################################
##########                 RSI                         #########
################################################################
input paintBars = yes;
input showShade = no;
input tradetype = { default "long", "short", "both" };
input lengthRSI = 7;
input price = close;
input averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);


################################################################
##########                 Stochastic Slow             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14; #Originally 14 but changed to 5 by coder
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;



#################################################################
#MACD Calculation
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;


#######  AssignPriceColor  - paint candles / bars  #######
AssignPriceColor(if paintBars and RSI >= 50 and SlowK >= 50 and Value > Avg then Color.GREEN else if paintBars and RSI < 50 and SlowK < 50 and Value < Avg then Color.RED else if paintBars then Color.pink else Color.CURRENT);

#################################################################
############  Shade areas based on criteria; adjust as needed  ##
#################################################################
AddCloud(if showShade and RSI >= 50 and SlowK >= 50 and Value > Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI >= 50 and SlowK >= 50 and Value > Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_Green);
AddCloud(if showShade and RSI < 50 and SlowK < 50 and Value < Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI < 50 and SlowK < 50 and Value < Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);



#################################################################
############          SCAN Variables                    #########
#################################################################
plot UpTrend = if RSI >= 50 and SlowK >= 50 and Value > Avg then 1 else 0;
plot DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if UpTrend[1] == 1 and UpTrend == 0 then 1 else 0;
def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if DownTrend == 0 and DownTrend[1] == 1 then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
AddLabel(yes, if UpTrend == 1 then "::RSM-Signal:LONG" else if DownTrend == 1 then "::RSM-Signal:SHORT" else "::RSM-Signal:IDLE", if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.RED else Color.yellow);





########### my additions to PowerX #########
# Big Kudos to Cos251 for the main code without which this would not be possible. To Welkin for the Horizontal Line and Cloud code. To Dublin_Capital for the number counting.

def ADR = Average(High(period = AggregationPeriod.DAY) - Low(period = AggregationPeriod.DAY), 7);
def Target = close(period = AggregationPeriod.DAY) + (ADR * 3);
def StopLoss = close(period = AggregationPeriod.DAY) - (ADR * 1.5);
def EntryPoint = close(period = AggregationPeriod.DAY);




AddLabel(yes, "Profit_X Target = +" +ADR * 3+ "", color.cyan);
AddLabel(yes, "(" +(close(period = AggregationPeriod.DAY) + (ADR * 3))+ ")", color.cyan);
AddLabel(yes, " : Stop_X Loss =  -" +ADR * 1.5+ "", color.Pink);
AddLabel(yes, "(" +(close(period = AggregationPeriod.DAY) - (ADR * 1.5))+ ")", color.Pink);





#number counting during UpTrend
def longSignal = UpTrend == 1;
def barNumberLong = CompoundValue(1, if LongSignal == 1 then barNumberLong[1] + 1 else 0, 0);
plot barsUp = if barNumberLong > 0 then barNumberLong else Double.NaN;
barsUp.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
barsUp.SetDefaultColor(Color.GREEN);


# Long Mode only so far
input crossingType = {default above, below}; # for Long / Short
plot UT = UpTrend;
UT.Hide();
plot DT = DownTrend;
DT.Hide();


def TrendTest;
switch(crossingType) {
case above:
TrendTest = UT crosses above DT;
case below:
TrendTest = DT crosses above UT;
}

#--Entry, actually Daily Close
def Entryline = if TrendTest  then EntryPoint else if TrendTest[1] and !TrendTest then EntryPoint[1] else Entryline[1];
plot EntrySig = if UpTrend == 1 then Entryline else Double.NaN;
EntrySig.DefineColor("Above", GetColor(7));
EntrySig.DefineColor("Below", GetColor(7));
EntrySig.AssignValueColor(if crossingType == crossingType.above then EntrySig.Color("Above") else EntrySig.Color("Below"));
EntrySig.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
EntrySig.Hide(); # Add a # in front if you want a solid line displayed

#--Profit Target point
def TargetLine = if TrendTest  then Target else if TrendTest[1] and !TrendTest then Target[1] else TargetLine[1];
plot TargetSig = if UpTrend == 1 then TargetLine else Double.NaN;
TargetSig.DefineColor("Above", GetColor(6));
TargetSig.DefineColor("Below", GetColor(7));
TargetSig.AssignValueColor(if crossingType == crossingType.above then TargetSig.Color("Above") else TargetSig.Color("Below"));
TargetSig.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TargetSig.Hide(); # Add a # in front if you want a solid line displayed

#--Stop Loss point
def StopLine =  if TrendTest  then StopLoss else if TrendTest[1] and !TrendTest then StopLoss[1] else StopLine[1];
plot StopSig = if UpTrend == 1 then StopLine else Double.NaN;
StopSig.DefineColor("Above", GetColor(2));
StopSig.DefineColor("Below", GetColor(5));
StopSig.AssignValueColor(if crossingType == crossingType.above then StopSig.Color("Above") else StopSig.Color("Below"));
StopSig.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
StopSig.Hide(); # Add a # in front if you want a solid line displayed

#--Clouds
AddCloud( if UpTrend == 1 then TargetSig else Double.NaN, EntrySig, Color.Light_Green, Color.Light_Green);
AddCloud(if UpTrend == 1 then EntrySig else Double.NaN, StopSig, Color.Pink, Color.Pink);


#--  extra ADR  test
plot Targ2 = if UpTrend == 1 then TargetLine*1.25 else Double.NAN;
 
Last edited by a moderator:
I've tested my code with cos251's "2020.12.01 V1.3". It does work but there are a couple small conflicts that I noticed.

-My "def = ADR ...." is a duplicate with his and should to be commented out with a # in front of the line.

-Also cos251's use of input able Aggregation period in the settings conflicts with what I coded when going to a daily chart (if you have your AggPeriod set to minutes) . It would need to be set to DAY in order to see my targets and clouds since what I did is intended to be used on a daily chart. Those are the only contradictions that have jumped out at me so far.

Will add this to my earlier code post to avoid confusion.
 
Last edited by a moderator:
Hi @cos251 thanks for the kind words, glad you like that bit of code. If your next version is ready to roll out now that is fine, might as well not keep others waiting. No sense postponing things for what I did. Please do not think I am forcing my code on you if you do not want it in your project. I'm new to all this and trying to be helpful and learn in the process.

My code may still need some polish since the Short side is not ready yet. Should not be too much trouble to do. Plus, I am not sure how to get it to play nice with your adjustable AggPeriod when someone switches between intraday and daily charts. I'm sure there is a way to force DAY on a daily and MINUTE on a minute chart. I also wonder if a different ATR formula might benefit the intraday traders more. Something more geared to the range of that day in particular. Since my ATR uses values at the start of the trend for a daily purpose. The coding for the lines and clouds could still be useful in both situations.

What are your thoughts, is there a different direction you would like to go with this?


Added
Removing my AGG=Day statements lets it play much nicer in the Minute intraday timeframe. Still needs some tweaks.
 
Last edited by a moderator:
Thanks @andre.muhammad , appreciate it. I will post it up like I did with post # 227 as a complete code unit when it is ready. Will '@ tag' you when I do so you get notified. (y)
 
New code for the ADR Clouds. This have both the Long and Short side with matching Target / Stop labels. Give it a whirl @andre.muhammad and let me know what you think. @cos251 is this something you can work with?

Code:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
#
#CHANGELOG
# 2020.10.27 V1.0 @cos251 - Added RSI, StochasticSlow and MACD to same indicator
#             - also calculates MACD;
#               Will shade the lower plot area if the following conditions are met
#                    Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg
#                    Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg
#                   
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 5(not14) and 3 WILDERS
#               MACD 12,26,9 WEIGHTED

declare upper;

################################################################
##########                 RSI                         #########
################################################################
input paintBars = yes;
input showShade = no;
input tradetype = { default "long", "short", "both" };
input lengthRSI = 7;
input price = close;
input averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);


################################################################
##########                 Stochastic Slow             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14; #Originally 14 but changed to 5 by coder
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;



#################################################################
#MACD Calculation
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;


#######  AssignPriceColor  - paint candles / bars  #######
AssignPriceColor(if paintBars and RSI >= 50 and SlowK >= 50 and Value > Avg then Color.GREEN else if paintBars and RSI < 50 and SlowK < 50 and Value < Avg then Color.RED else if paintBars then Color.pink else Color.CURRENT);

#################################################################
############  Shade areas based on criteria; adjust as needed  ##
#################################################################
AddCloud(if showShade and RSI >= 50 and SlowK >= 50 and Value > Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI >= 50 and SlowK >= 50 and Value > Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_Green);
AddCloud(if showShade and RSI < 50 and SlowK < 50 and Value < Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI < 50 and SlowK < 50 and Value < Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);



#################################################################
############          SCAN Variables                    #########
#################################################################
plot UpTrend = if RSI >= 50 and SlowK >= 50 and Value > Avg then 1 else 0;
plot DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if UpTrend[1] == 1 and UpTrend == 0 then 1 else 0;
def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if DownTrend == 0 and DownTrend[1] == 1 then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
AddLabel(yes, if UpTrend == 1 then "::RSM-Signal:LONG" else if DownTrend == 1 then "::RSM-Signal:SHORT" else "::RSM-Signal:IDLE", if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.RED else Color.yellow);





########### my additions to PowerX #########
# Big Kudos to Cos251 for the main code without which this would not be possible. To Welkin for the Horizontal Line and Cloud code. To Dublin_Capital for the number counting.
#I guess this could be considered ver 2 ?

AddLabel(yes, "Daily ver. " , color.cyan);


def ADR = Average(High(period = AggregationPeriod.DAY) - Low(period = AggregationPeriod.DAY), 7);
def EntryPoint = close(period = AggregationPeriod.DAY);
def TargetUp = close(period = AggregationPeriod.DAY) + (ADR * 3);
def TargetDn = close(period = AggregationPeriod.DAY) - (ADR * 3);
def StopLossUp = close(period = AggregationPeriod.DAY) - (ADR * 1.5);
def StopLossDn = close(period = AggregationPeriod.DAY) + (ADR * 1.5);


#number counting during Trend
# Up
def longSignal = UpTrend == 1;
def barNumberLong = CompoundValue(1, if LongSignal == 1 then barNumberLong[1] + 1 else 0, 0);
plot barsUp = if barNumberLong > 0 then barNumberLong else Double.NaN;
barsUp.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
barsUp.SetDefaultColor(Color.GREEN);
# Dn
def shortSignal = DownTrend == 1;
def barNumberShort = CompoundValue(1, if shortSignal == 1 then barNumberShort[1] + 1 else 0, 0);
plot barsDn = if barNumberShort > 0 then barNumberShort else Double.NaN;
barsDn.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barsDn.SetDefaultColor(Color.RED);



#- Use instead of crossingType / switch ?
def TrendUp = UpTrend crosses above DownTrend;
def TrendDn = DownTrend crosses above UpTrend;



#--Entry, actually Daily Close
#up
def EntrylineUp = if TrendUp  then EntryPoint else if TrendUp[1] and !TrendUp then EntryPoint[1] else EntrylineUp[1];
plot EntrySigUp = if UpTrend == 1 then EntrylineUp else Double.NaN;
EntrySigUp.SetDefaultColor(Color.GREEN);
EntrySigUp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
EntrySigUp.Hide(); # Add a # in front if you want a solid line displayed
#dn
def EntrylineDn = if TrendDn  then EntryPoint else if TrendDn[1] and !TrendDn then EntryPoint[1] else EntrylineDn[1];
plot EntrySigDn = if DownTrend == 1 then EntrylineDn else Double.NaN;
EntrySigDn.SetDefaultColor(Color.GREEN);
EntrySigDn.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
EntrySigDn.Hide(); # Add a # in front if you want a solid line displayed


#--Profit Target points
#up
def TargetLineUp = if TrendUp  then TargetUp else if TrendUp[1] and !TrendUp then TargetUp[1] else TargetLineUp[1];
plot TargetSigUp = if UpTrend == 1 then TargetLineUp else Double.NaN;
TargetSigUp.SetDefaultColor(Color.GREEN);
TargetSigUp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TargetSigUp.Hide(); # Add a # in front if you want a solid line displayed
#dn
def TargetLineDn = if TrendDn  then TargetDn else if TrendDn[1] and !TrendDn then TargetDn[1] else TargetLineDn[1];
plot TargetSigDn = if DownTrend == 1 then TargetLineDn else Double.NaN;
TargetSigDn.SetDefaultColor(Color.GREEN);
TargetSigDn.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TargetSigDn.Hide(); # Add a # in front if you want a solid line displayed



#--Stop Loss points
#up
def StopLineUp =  if TrendUp  then StopLossUp else if TrendUp[1] and !TrendUp then StopLossUp[1] else StopLineUp[1];
plot StopSigUp = if UpTrend == 1 then StopLineUp else Double.NaN;
StopSigUp.SetDefaultColor(Color.PINK);
StopSigUp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
StopSigUp.Hide(); # Add a # in front if you want a solid line displayed
#dn
def StopLineDn =  if TrendDn  then StopLossDn else if TrendDn[1] and !TrendDn then StopLossDn[1] else StopLineDn[1];
plot StopSigDn = if DownTrend == 1 then StopLineDn else Double.NaN;
StopSigDn.SetDefaultColor(Color.PINK);
StopSigDn.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
StopSigDn.Hide(); # Add a # in front if you want a solid line displayed


#--Clouds
#up
AddCloud( if UpTrend == 1 then TargetSigUp else Double.NaN, EntrySigUp, Color.Light_Green, Color.Light_Green);
AddCloud(if UpTrend == 1 then EntrySigUp else Double.NaN, StopSigUp, Color.Pink, Color.Pink);
#dn
AddCloud( if DownTrend == 1 then TargetSigDn else Double.NaN, EntrySigDn, Color.Light_Green, Color.Light_Green);
AddCloud(if DownTrend == 1 then EntrySigDn else Double.NaN, StopSigDn, Color.Pink, Color.Pink);

#---Labels
#up
AddLabel(yes and UpTrend, "TargetUp = " +TargetSigUp+ "", color.cyan);
AddLabel(yes and UpTrend, " : StopUp =  " +StopSigUp+ "", color.Pink);
#dn
AddLabel(yes and DownTrend, "TargetDn = " +TargetSigDn+ "", color.cyan);
AddLabel(yes and DownTrend, " : StopDn =  " +StopSigDn+ "", color.Pink);


#--  extra ADR  test - (the .1 is a made up test value)
plot Targ2Up = if UpTrend == 1 then TargetLineUp + (TargetLineUp * .1) else Double.NAN;
plot Targ2Dn = if DownTrend == 1 then TargetLineDn - (TargetLineDn * .1) else Double.NAN;


# end code
 
New code for the ADR Clouds. This have both the Long and Short side with matching Target / Stop labels. Give it a whirl @andre.muhammad and let me know what you think. @cos251 is this something you can work with?

Code:
#START OF RSI/Stochastic/MACD Confluence Strategy for ThinkOrSwim
#
#CHANGELOG
# 2020.10.27 V1.0 @cos251 - Added RSI, StochasticSlow and MACD to same indicator
#             - also calculates MACD;
#               Will shade the lower plot area if the following conditions are met
#                    Shade GREEN = RSI > 50 and SlowK > 50 and (macd)Value > (macd)Avg
#                    Shade RED = RSI < 50 and SlowK < 50 and (macd)Value < (macd)Avg
#                  
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
#               Stoch Slow 5(not14) and 3 WILDERS
#               MACD 12,26,9 WEIGHTED

declare upper;

################################################################
##########                 RSI                         #########
################################################################
input paintBars = yes;
input showShade = no;
input tradetype = { default "long", "short", "both" };
input lengthRSI = 7;
input price = close;
input averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);


################################################################
##########                 Stochastic Slow             #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14; #Originally 14 but changed to 5 by coder
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, priceH, priceL, priceC, 3, averageTypeStoch).FullD;



#################################################################
#MACD Calculation
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;


#######  AssignPriceColor  - paint candles / bars  #######
AssignPriceColor(if paintBars and RSI >= 50 and SlowK >= 50 and Value > Avg then Color.GREEN else if paintBars and RSI < 50 and SlowK < 50 and Value < Avg then Color.RED else if paintBars then Color.pink else Color.CURRENT);

#################################################################
############  Shade areas based on criteria; adjust as needed  ##
#################################################################
AddCloud(if showShade and RSI >= 50 and SlowK >= 50 and Value > Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI >= 50 and SlowK >= 50 and Value > Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_Green);
AddCloud(if showShade and RSI < 50 and SlowK < 50 and Value < Avg then Double.POSITIVE_INFINITY else Double.NaN, if RSI < 50 and SlowK < 50 and Value < Avg then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_RED);



#################################################################
############          SCAN Variables                    #########
#################################################################
plot UpTrend = if RSI >= 50 and SlowK >= 50 and Value > Avg then 1 else 0;
plot DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 then 1 else 0;
def LongExit = if UpTrend[1] == 1 and UpTrend == 0 then 1 else 0;
def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if DownTrend == 0 and DownTrend[1] == 1 then 1 else 0;
UpTrend.Hide();
DownTrend.Hide();
AddLabel(yes, if UpTrend == 1 then "::RSM-Signal:LONG" else if DownTrend == 1 then "::RSM-Signal:SHORT" else "::RSM-Signal:IDLE", if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.RED else Color.yellow);





########### my additions to PowerX #########
# Big Kudos to Cos251 for the main code without which this would not be possible. To Welkin for the Horizontal Line and Cloud code. To Dublin_Capital for the number counting.
#I guess this could be considered ver 2 ?

AddLabel(yes, "Daily ver. " , color.cyan);


def ADR = Average(High(period = AggregationPeriod.DAY) - Low(period = AggregationPeriod.DAY), 7);
def EntryPoint = close(period = AggregationPeriod.DAY);
def TargetUp = close(period = AggregationPeriod.DAY) + (ADR * 3);
def TargetDn = close(period = AggregationPeriod.DAY) - (ADR * 3);
def StopLossUp = close(period = AggregationPeriod.DAY) - (ADR * 1.5);
def StopLossDn = close(period = AggregationPeriod.DAY) + (ADR * 1.5);


#number counting during Trend
# Up
def longSignal = UpTrend == 1;
def barNumberLong = CompoundValue(1, if LongSignal == 1 then barNumberLong[1] + 1 else 0, 0);
plot barsUp = if barNumberLong > 0 then barNumberLong else Double.NaN;
barsUp.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
barsUp.SetDefaultColor(Color.GREEN);
# Dn
def shortSignal = DownTrend == 1;
def barNumberShort = CompoundValue(1, if shortSignal == 1 then barNumberShort[1] + 1 else 0, 0);
plot barsDn = if barNumberShort > 0 then barNumberShort else Double.NaN;
barsDn.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barsDn.SetDefaultColor(Color.RED);



#- Use instead of crossingType / switch ?
def TrendUp = UpTrend crosses above DownTrend;
def TrendDn = DownTrend crosses above UpTrend;



#--Entry, actually Daily Close
#up
def EntrylineUp = if TrendUp  then EntryPoint else if TrendUp[1] and !TrendUp then EntryPoint[1] else EntrylineUp[1];
plot EntrySigUp = if UpTrend == 1 then EntrylineUp else Double.NaN;
EntrySigUp.SetDefaultColor(Color.GREEN);
EntrySigUp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
EntrySigUp.Hide(); # Add a # in front if you want a solid line displayed
#dn
def EntrylineDn = if TrendDn  then EntryPoint else if TrendDn[1] and !TrendDn then EntryPoint[1] else EntrylineDn[1];
plot EntrySigDn = if DownTrend == 1 then EntrylineDn else Double.NaN;
EntrySigDn.SetDefaultColor(Color.GREEN);
EntrySigDn.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
EntrySigDn.Hide(); # Add a # in front if you want a solid line displayed


#--Profit Target points
#up
def TargetLineUp = if TrendUp  then TargetUp else if TrendUp[1] and !TrendUp then TargetUp[1] else TargetLineUp[1];
plot TargetSigUp = if UpTrend == 1 then TargetLineUp else Double.NaN;
TargetSigUp.SetDefaultColor(Color.GREEN);
TargetSigUp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TargetSigUp.Hide(); # Add a # in front if you want a solid line displayed
#dn
def TargetLineDn = if TrendDn  then TargetDn else if TrendDn[1] and !TrendDn then TargetDn[1] else TargetLineDn[1];
plot TargetSigDn = if DownTrend == 1 then TargetLineDn else Double.NaN;
TargetSigDn.SetDefaultColor(Color.GREEN);
TargetSigDn.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TargetSigDn.Hide(); # Add a # in front if you want a solid line displayed



#--Stop Loss points
#up
def StopLineUp =  if TrendUp  then StopLossUp else if TrendUp[1] and !TrendUp then StopLossUp[1] else StopLineUp[1];
plot StopSigUp = if UpTrend == 1 then StopLineUp else Double.NaN;
StopSigUp.SetDefaultColor(Color.PINK);
StopSigUp.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
StopSigUp.Hide(); # Add a # in front if you want a solid line displayed
#dn
def StopLineDn =  if TrendDn  then StopLossDn else if TrendDn[1] and !TrendDn then StopLossDn[1] else StopLineDn[1];
plot StopSigDn = if DownTrend == 1 then StopLineDn else Double.NaN;
StopSigDn.SetDefaultColor(Color.PINK);
StopSigDn.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
StopSigDn.Hide(); # Add a # in front if you want a solid line displayed


#--Clouds
#up
AddCloud( if UpTrend == 1 then TargetSigUp else Double.NaN, EntrySigUp, Color.Light_Green, Color.Light_Green);
AddCloud(if UpTrend == 1 then EntrySigUp else Double.NaN, StopSigUp, Color.Pink, Color.Pink);
#dn
AddCloud( if DownTrend == 1 then TargetSigDn else Double.NaN, EntrySigDn, Color.Light_Green, Color.Light_Green);
AddCloud(if DownTrend == 1 then EntrySigDn else Double.NaN, StopSigDn, Color.Pink, Color.Pink);

#---Labels
#up
AddLabel(yes and UpTrend, "TargetUp = " +TargetSigUp+ "", color.cyan);
AddLabel(yes and UpTrend, " : StopUp =  " +StopSigUp+ "", color.Pink);
#dn
AddLabel(yes and DownTrend, "TargetDn = " +TargetSigDn+ "", color.cyan);
AddLabel(yes and DownTrend, " : StopDn =  " +StopSigDn+ "", color.Pink);


#--  extra ADR  test - (the .1 is a made up test value)
plot Targ2Up = if UpTrend == 1 then TargetLineUp + (TargetLineUp * .1) else Double.NAN;
plot Targ2Dn = if DownTrend == 1 then TargetLineDn - (TargetLineDn * .1) else Double.NAN;


# end code
 
Hi @trendr it is up, post # 235. It is on version 1 of cos's code. Wanted to get it up and running correctly before trying it on his later, more complex versions. :)

Added, let me know what you think or if there are any problems.
 
Hi @trendr it is up, post # 235. It is on version 1 of cos's code. Wanted to get it up and running correctly before trying it on his later, more complex versions. :)

Added, let me know what you think or if there are any problems.
Looks great, Thanks!! You guys are awesome, Thank yall for all the hard work!
 
Hi All.... - so sorry for the delay. I've had a rough go of trying to figure out a few updates for the latest version of the code but I think I have at least a decent working version. There are many additions in this code now and it is getting a little heavy. I apologize if this particular version does not have what you are looking for. I am happy to continue plugging away at further enhancements.

For now here are the updates available in Version 1.4 of the Standard Code (single TF/Tick version) Added the updates to this version as it is the most reliable at this time for quick and easy use.

Link to updated code - https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/post-42978
Again Version 1.4

Updates are as follows
  1. Dynamic ATR/ADR Targets/Plots on the start of an UpTrend or DownTrend
  2. Dynamic Stop Loss at 1x the ATR/ADR
  3. Dynamic Stop Loss adjustment in settings; currently set to 1.0
  4. Shading for ATR/ADR Targets/Plots - can be turned on or off
  5. Extra Targets (4-6) - can be enabled in settings
  6. Option to only show Dynamic Targets for TodayOnly
  7. Ability to plot ATR/ADR and all settings described above for Daily Chart - BUT MUST TURN OFF "showTodayOnly"
  8. Dynamic ATR/ADR Target Labels at top of chart for current trend
  9. Dynamic Trend Labels will display when trend started, at what price and how many bars are in current trend
  10. Debug function - miscellaneous labels that can be used for debug purposes - remove if you like
It has taken me a good while to get all these plots down correctly but I think this is a good point

Now I will say this can makes the chart look a little messy depending on your taste. I'll let you guys be the judge. I also have the same copy in MTF version but there is an issue with the Target Plots once the trend starts. It does not plot correctly but eventually straightens out. I'll see if I can figure out how to adjust it.

The ATR/ADR calculations are also pretty standard, if you see issues with them please let me know so I can adjust the script and ensure accurate calculation for all.
I'll add edits below as I think of them. For now see fresh version of code with link above and screenshots for reference below.
Thanks so much for your patience.

MSFT Today on 5m TF with "showTodayOnly" set to "yes"
FjbmNJJ.png


MSFT on Daily Chart with "showTodayOnly" set to "no" (Must be set to "no" so plots will work on daily)
Trend Labels set to "yes" for example purposes
0WEc2RO.png
 
Last edited:
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
371 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