Mimicking "Power X Strategy" by Markus Heitkoetter

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

@SuryaKranC, could you please explain how to use the volume study you have in your version of the study?

Also, thanks to you, @cos251, @JosephPatrick18, and all other contributors, for bringing this great study to TOS, adapting it for use on TOS, and for continuously updating and improving upon the study!
 
Got it. I'll send you the code to add that finds the beginning in a bit.
Hi Cos,

I believe the op was talking about the DMI code shown below, correct? Could you please send me the code to add that as well? The DMI Oscillator is an indicator I use often, and I think this would work really well with it. Thanks for all your help!
Similar to this?
qwEZFFX.png

DrOVNGE.png

Z4VE4WA.png
 
@CT88 ,

It's a code from right here. (link: https://usethinkscript.com/threads/advanced-volume-indicator-for-thinkorswim.1665/ )
read through the description. I am tweaking this to add few more options like separate pre/post and few enhancements for higher timeframe.

Not completed yet. Will update here, once I am done with it. I do have another volume labels Indicator I worked on. (https://usethinkscript.com/threads/custom-thinkscript-volume-stats-for-thinkorswim.970/post-32359) take a look at that and see if that is a better fit. Details/explanation of the indicator is also available. (https://usethinkscript.com/threads/custom-thinkscript-volume-stats-for-thinkorswim.970/post-31606)

-Surya
 
Hi @trendr - let me see what I can do about fixing that. I've been working on a few other things but want to get back to a couple of outstanding requests on this thread.
 
I have been trying to help with that too, cos251. Progress is slow and I keep hitting dead ends. Been looking at other code on the site and around the web looking for answers. Still trying to get it to plot the starting Profit Target, etc. as a horizontal line throughout the 'UpTrend == 1' signal. It might have something to do with bar numbers and CompoundValue I don't know. I have been able to get it to plot incrementing numbers during the UpTrend signal counting each day and plotting the number on chart. Not my original intention, but it is something more than I could do before, haha. :D

added
Thanks for the kind words, trendr. It is all cos251 hard work that has made this possible.
 
@cos251, is there a consolidated outstanding requests on this? with holidays coming, I can working on this for a bit.

-Surya
Hi SuryaKiranC:

I tried to create a backtest for the POX strategy, when there is a green bar(Indicator paint fill) start the long position and exit at the end of the green bar, same thing on the short side based on red bars.

Used the extract from the scan code

plot UpTrend = if calcRSI >= 50 and calcSlowK >= 50 and calcValue > calcAvg then 1 else 0;
plot DownTrend = if calcRSI < 50 and calcSlowK < 50 and calcValue < calcAvg then 1 else 0;

and leveraged the Uptrend and DownTrend variables to trigger long open, long exit, short open & Short exits in the backtest order.

The order entry and exits plotted are not accurate to match the signals. Not sure why?

The bigger ask: Is it even possible to include and factor in theta decay in backtest strategy orders for option positions?

If we run the strategy on a weekly or daily, with a normal back test, it shows lots of historic gains! but in reality that is not the case when you factor in Theta and sideways movement for swing positions that is a month or 40 days long. The Theta input should be adjustable, so we can try for ATM, ITM & OTM choices. Perhaps we can approximately calculate option price using Delta increments like in real world and calculate backtest report? Experts can weigh in here, Please.

I hope I'm not asking for a replica of Analysis tab/Profitability analysis with Bjerksund-Stensland model 😁

Just thought to ask :) Appreciate all the help you and Cos251 have put in so far.
 
Last edited:
Thought I would contribute around here after a hiatus.
  • Code below adds labels for Stops and Targets as indicated by original strategy.
  • The user can choose to display the labels whether they are going long or short to help reduce some screen clutter
  • Hope it helps
Code:
# Code for Average Range Scan - User selects Percentage of Range covered by changing the ScanRange
# original code provided by autolox
# modified by jox51 to add Power X Strategy Stop and Targets

#Hint: Displays labels for Stops and Targets of the Power X Strategt. AVR is the today's Daily Range Percentage compared with the Average Daily Range

# The number of days you'd like average
input RangePeriod = 7; #hint RangePeriod: Original Power X Strategy uses a period of 7 to compute the daily range. Feel free to change it here as you please.
input ShowLongLabel = yes; #hint ShowLongLabel: Display stops and targets when going long
input ShowShortLabel = yes; #hint ShowShortLabel: Displays stops and targets when going short

# ScanRange = .25 (25%) .50 (50%) .75 (75%) 1 (100%)
#input ScanRange = 1;

def DayRange = high-low;
def AvgRange = average(DayRange,RangePeriod);


# How to address seeing what % of daily range has been achieved
def TodayAgainstAvgRange = (high-low)/AvgRange;
def round_todayrange = roundDown(TodayAgainstAvgRange, 3);

# Power Stops and Targets
def StopOne = AvgRange * 1.5;
def TargetOne = AvgRange * 3;

#PowerX Long StopLoss Exit 1
def PowerEntry = high + 0.01;
def StopPrice = roundDown(PowerEntry-StopOne,2);


#PowerX Long Profit Target
def TargetPrice = roundDown(PowerEntry + TargetOne,2);

#PowerX Short StopLoss
def SellPowerEntry = low - 0.01;
def SellStopPrice = roundDown(SellPowerEntry + StopOne,2);

#Sell Power Short Profit Target
def SellTarget = roundDown(SellPowerEntry - TargetOne,2);



AddLabel(yes,"ADR Percentage: "+round_todayrange*100+"% ",color.yellow);
AddLabel(ShowLongLabel,"Power Stop: "+ StopPrice + " ",color.ORANGE);
AddLabel(ShowLongLabel,"Power Profit Target: "+TargetPrice+" ",color.GREEN);


AddLabel(ShowShortLabel,"Short Stop Loss: "+SellStopPrice+" ",color.RED);
AddLabel(ShowShortLabel,"Short Target: "+SellTarget+" ",color.DaRK_ORANGE);

Short Stop and Target

48cd70b659e342b19beca8d924fe7e66.png


Long Stop and Target

d3eabd327715e9f1b2dae75a90c70022.png
 
Hi SuryaKiranC:

I tried to create a backtest for the POX strategy, when there is a green bar(Indicator paint fill) start the long position and exit at the end of the green bar, same thing on the short side based on red bars.

Used the extract from the scan code

plot UpTrend = if calcRSI >= 50 and calcSlowK >= 50 and calcValue > calcAvg then 1 else 0;
plot DownTrend = if calcRSI < 50 and calcSlowK < 50 and calcValue < calcAvg then 1 else 0;

and leveraged the Uptrend and DownTrend variables to trigger long open, long exit, short open & Short exits in the backtest order.

The order entry and exits plotted are not accurate to match the signals. Not sure why?

The bigger ask: Is it even possible to include and factor in theta decay in backtest strategy orders for option positions?

If we run the strategy on a weekly or daily, with a normal back test, it shows lots of historic gains! but in reality that is not the case when you factor in Theta and sideways movement for swing positions that is a month or 40 days long. The Theta input should be adjustable, so we can try for ATM, ITM & OTM choices. Perhaps we can approximately calculate option price using Delta increments like in real world and calculate backtest report? Experts can weigh in here, Please.

I hope I'm not asking for a replica of Analysis tab/Profitability analysis with Bjerksund-Stensland model 😁

Just thought to ask :) Appreciate all the help you and Cos251 have put in so far.
Use this SCANS version for your back testing. the UpTrendJustStarted & DownTrendJustStarted Variables are set to find the beginning of a trend.

*EDIT - I added the following variables to the SCAN Version
  1. UpTrendJustEnded - can be used in the back testing exit strategy for LONG positions
  2. DownTrendJustEnded - can be used in the back testing exit stratety for SHORT positions

https://usethinkscript.com/threads/mimicking-power-x-strategy-by-markus-heitkoetter.4283/post-43748
 
Last edited:
@cos251, is there a consolidated outstanding requests on this? with holidays coming, I can working on this for a bit.

-Surya
Hi Surya

Thanks so much for inquiring.

A few of the items that were requested are as follows:
  1. Dynamic/Updating ATR Labels for a downtrend or uptrend starts (saw the ones above from @jox51 - I have not reviewed them yet)
  2. Dynamic ATR/ADR plots on chart for a new downtrend or uptrend
  3. Addition of custom moving averages to allow user to select in settings (I have to go back in the thread and find this request but I remember it being out there).

As for Item #2 above - below is a picture of what I have so far. I was able to figure out how to shade only for the current day and to get the lines for the dynamic ATR/ADR to plot straight. I also envision having a standard version of this that plots ATR lines for the DAILY time frame only that are more static (this option is easier - at least for me).

I had to spend a bit of time to figure out how to get these lines to plot correctly but I think I have it figured out. I need to keep tweaking/cleaning up the code in order to put this out for use though, but see below for an illustration.

Lastly - if it matters to the users I need to figure out how to shade only the current trend (if anyone knows how to do this fast and easy please let me know) :)

*EDIT - the ATR Lines plotted are dynamic and calculated on a new uptrend or downtrend. They seem to make good profit targets. @RickAns - was this what you were ultimately after?
*EDIT2 - currently only plotting 3 ATR from trend start - I will add an option for 4,5 and 6 ATR's in the settings.

LoqjSkr.png
 
Use this SCANS version for your back testing. the UpTrendJustStarted & DownTrendJustStarted Variables
Just tried, its not working. Should I put it as a lower study? it didn't make sense to be a lower study, but please let me know
 
Last edited:
Things are looking great, @cos251 ! In regards of item #2 in your post above. Really liking the extra ATR lines. If what you have done there can also be applied to the daily charts it would be perfect for me. I am trying to help out with coding that bit if I can. Yet it is still beyond what I am able to code currently.

added
The timing of the ATR/ADR clouds per uptrend / downtrend signal are on point as well.
Also really appreciate all the effort you are putting into this project. :)
 
I have done it @cos251 ! Finally figured out how to plot the horizontal lines and clouds on a daily chart throughout the duration of the UpTrend signal. Works as well on intraday too as far as I can tell. Tweaked some code from Welkin (horizontal lines / clouds) and Dublin_Capital (number counting). Might not be the prettiest way to code this but maybe you can help polish it up if you like.

-Added an extra ATR line as a test.
-Added bar number counting as a test. More playing about really.
-This is Long Side only so far, more a working proof of concept. Will work on Short selling side next.
-The horizontal lines marking the edges of the clouds are currently hidden but can be shown if wanted.
-Green cloud measures up to Profit Target from close, Red cloud down to Stop Loss, with the close being the middle point. Since we are supposed to buy .01 cent above previous days close per Markus.

Here goes, let me know what you think. I am pleased to be helping out with this project. Hope you don't mind on that. :)

For those wanting to try this paste it on the end of what Cos has done. It still needs his code.

Code:
########### 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;

#-- end code



Added:
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.

What I had been coding this on was "2020.10.27 V1.0".


Added: 12/23/2020 There is a more up to date version of this see post # 235.
 
Last edited by a moderator:
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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