TradingView
therealhaolu
30 กรกฎา 2020 เวลา 19 นาฬิกา 43 นาที

Power X Strategy Back-test 

คำอธิบาย

This script back-test the Power X Strategy developed by Markus Heitkoetter and Rockwell Trading. For more detail about the strategy, please refer to "The PowerX Strategy: How to Trade Stocks and Options in Only 15 Minutes a Day" written by Markus Heitkoetter. Note that this script is not publish, develop or maintain by Rockwell Trading, and may have different results. Rockwell Trading has a powerful software called Power X Optimizer, which scan, back-test and optimize the best stock for the strategy.
The Power X Strategy uses RSI , Slow Stochastic and MACD indicators under the hood. When RSI and slow Stochastic are both greater than 50 and MACD crosses up the signal line, it marks as up-trend. If RSI and slow stochastic are both less than 50 and MACD crosses down the signal line, it marks as down-trend. Other are mark as no trend.
This back-test makes a long entry with an up-trend momentum and short entry with down-trend momentum. Trade is exited when profit target or stop lose is reach. Profit target and stop lose is calculated based on 7 days Average Daily Range (ADR).
If the either of the momentum is lost, trade is exited the next day. It also skips the entire month of March 2020, since the market crash and is not in a normal market condition for the strategy.

เอกสารเผยแพร่

This script back-test the Power X Strategy developed by Markus Heitkoetter and Rockwell Trading. For more detail about the strategy, please refer to "The PowerX Strategy: How to Trade Stocks and Options in Only 15 Minutes a Day" written by Markus Heitkoetter. Note that this script is not publish, develop or maintain by Rockwell Trading, and may have different results. Rockwell Trading has a powerful software called Power X Optimizer, which scan, back-test and optimize the best stock for the strategy.
The Power X Strategy uses RSI , Slow Stochastic and MACD indicators under the hood. When RSI and slow Stochastic are both greater than 50 and MACD crosses up the signal line, it marks as up-trend. If RSI and slow stochastic are both less than 50 and MACD crosses down the signal line, it marks as down-trend. Other are mark as no trend.
This back-test makes a long entry with an up-trend momentum and short entry with down-trend momentum. Trade is exited when profit target or stop lose is reach. Profit target and stop lose is calculated based on 7 days Average Daily Range (ADR).
If the either of the momentum is lost, trade is exited the next day. It also skips the entire month of March 2020, since the market crash and is not in a normal market condition for the strategy.

V2
- Removed the option for only testing long or short. Since it was not working at the first place
- Added an input check box as an option skip the month of March due to the Covid-19 crash. Default is to skip it.
- Added an input option to adjust the amount of the account to risk. The default is 100%.

เอกสารเผยแพร่

- Udpate the covid-19 crash period. Skipping Feb 20 2020 to Mar 26 2020.

เอกสารเผยแพร่

- Add option to not enter a trade if the stock gapped more than certain %. Enable by a checkbox.
- The default of maximum gap is 2%

เอกสารเผยแพร่

- Adjust average daily range to be the average range of past 7 interval period which allows for testing the strategy on different interval.

เอกสารเผยแพร่

- update default start date
ความคิดเห็น
davidmhaylett
Good news folks,
I've no clue about how to code in Pine Script but take a look at line 62 in the code. You will see the following.

qty = round(strategy.initial_capital * risk / 100 / high)

Take a copy of the entire code and put this into your Pine Script editor in Trading view and change the word 'high' to 'adr'. This will then correctly calculate the quantity on each long trade and the correct profit. I don't care about short trades as I don't like shorting stocks. The quantity will then be calculated as my total capital (which I set to £100, the risk on each trade), divided by 1xADR (the stop loss value). Thus the quantity is correctly calculated in accordance with the strategy and the profits are then correct as well.

The net profit in the strategy tester tab summary is then correct for the stock. In other words, all of the profits/losses are summed for all of the trades to give a net figure. Obviously if this is a negative (in red) then you don't want to trade this stock. If it's postive, you just need to take one more step to get the correct ROI. Look lower down in the summary and you will see the total number of trades. Multiply this by the risk you take on each trade. In my case I have set the total capital to £100 and the account risk to 100. This then allocates £100 to each trade (1% of a £10,000 account).
So if you have 14 trades, multiply by £100 and get £1400 being the total risk taken. This is the denominator in your ROI calculation. Lets say the net profit = £875. The ROI would then be (£875/£1400)x100 = 62.5%.
If you are looking for a minimum ROI % of 60% as the Power X Optimizer does, then this would be a good stock to trade.

There are a few other places in the code where the quantity is calculated but these are not causing problems at the moment. I'll take a look at these and see if i can work out what's going on.

Just a final word of warning. Don't rely on the % return shown under the net profit in the summary. This is not correct and is inflated as it uses the total captial as the denominator. So just calculate the correct ROI yourself as above. Only takes a few seconds for one stock.

Hopefully the author will update the code at some point as I lack the skills to make all of the changes needed.
douglayne
Hey, this is a great PowerX Backtester you created. Congratulations! Very nicely done.

One question, Is there any way to remove the short trades and see long trades only? Maybe add a "Long Trades Only" check box.
davidmhaylett
My final post on this folks as I've hit the ceiling with my coding skills. Note the following;

1)I tried to change the quantity calculation for cases where the trade was triggered later than the following day. This did not work correctly so I removed this part of the code entirely (lines 71-97). This is probably a good thing because if there isn't enough price momentum to trigger the trade the next day then i really don't want to wait up to five days for the trade to be triggered. Quite often these are losing trades.

If you do want to wait for these to trigger then I have found that a good way to do this is to follow a bull flag strategy. This means that if you don't get triggered the following day, close your order. Then create a new stop order at the high of the next day's candle (which has a lower high). If this doesn't trigger, cancel the order again and create a new order at the high of the next candle, etc. The advantage of this is that you get into the trade at a lower price, and if it turns out to be a loser, your loss will be reduced.

2)The other change I've made is to delete all of the code related to short trades (as I don't make any). So delete lines 127-190. This tidies up the trade list, removing all of the short trades, so I can focus on the trades I'm interested in.

So that's it folks, the amended code is now very close to what I want. The only thing that's not correct is the % return under the net profit in the summary tab. But I can easily get the correct figure with a calculator as per my previous post.

Many thanks to the author of this code as it helps a lot. If you want to update it and need any non technical assistance let me know and I'd be happy to work with you. But as you've already bought the Optimizer I guess you no longer need the code.

Any comments welcomed from the author or other traders.
davidmhaylett
One more thing on this.
The individual trades calculate the correct profit and profit % based on the shares bought. Going back to trade 17 on ADPT, I changed the starting capital to $200 so that $200 would be allocated to each trade. In this case, dividing by the stock price of 42.76, the program says that 5 shares would be bought. This rounds up by 1 from 4 shares but 5 shares cost $213.8. The profit on the trade is correctly calculated as $40/£213.8 = 18.71%. This is the true ROI that we want showing the return as a proportion of the amount risked.
Of course as noted in my other posts, the quantity calculated is not correct so the profit is significantly understated.
However, there is another problem with the logic. This is that when the total net profit is added up for net long trades, the total profit (stated correctly as $94) is then divided by the total capital ($200 in this case) to come up with a % return of 47%. Of course this isn't correct because this is the ROC, return on total capital. But we don't want this. We want the ROI as specified in the Optimizer which looks for stocks with a minimum ROI of 60% as the default. The real risk here is the number of long trades x the risk per trade = 14 x 200 = 2800. So if the ROI was correctly calculated the % return on this stock on long trades would be $94/$2800 = 3.35%. Of course this is vastly understated because the quantities are not correct in the first place. So this is a case of one error in the logic almost cancelling out another. I hope that the author will have the time to fix the issues as this is potentially a fantastic program and a lot of work has gone into this already.
But for traders looking for a fairly close true ROI figure for a stock i suggest the following;
1)Set the total capital = $200 and the account risk = 100 (the default value).
2)Take the stock price for the stock you are reviewing (latest or median value over the time period you are looking at).
2)Identify the equivalent ADR for this stock and multiply this by 1.5 as your stop value.
3)Divide the Purchase price by the stop value in 2) and this gives you your profit adjustment factor.
4)Multiply the Profit adjustment factor by the total net profit for long trades shown in the strategy tester for the stock concerned.
5)Divide the product of 4 by the total risk on the trades taken (= $200 x number of long trades) and multiply by 100. This gives you the correct ROI % which is the figure you want to determine whether to trade the stock or not.
In the case of ADPT, the profit of $94 gets multiplied by 10.71 to give a profit of $1007. With 14 trades (risk of $2800), the ROI % becomes $1007/$2800 = 35%. If you do the calculation for each individual trade and total them up you get an ROI of 31% so quite close.
BUT to avoid this exercise, I hope the author will be able to update the code, or perhaps another clever person can create another version of it. The tweaks required are fairly minor.
davidmhaylett
Hi,
Sorry here is another post.
I think the first problem I identified with the account risk can be worked around by changing the initial capital. If I change change this to $200 and leave the risk % at 100 this then correctly allocates $200 to each trade. But this doesn't fix the second problem where the amount risked is divided by the share price and not the ADR to calculate the quantity.
Take the example of ADPT again, trade 17. Using the program (where I change the starting Capital to $200 to fix the first problem) the number of shares purchased = 4 (200/42.76). When the profit target is hit at $50.76 the profit is 4 x ($50.76 - $42.76) = $32. As the risk was $200 this is a return of 32/200 = 16%.
Now look at the trade with the correct quantity. We divide $200 by 1.5 x ADR. In this case the ADR = $2.66 so 1.5 x ADR = $3.99. The quantity becomes 200/3.99 = 50. The profit then becomes 50 x 8 (the price move up) = $400. This is a return of 200%. This is the return we should expect on a winning trade as the risk/reward ratio is 1:2 so if we risk $200, we should expect to earn a profit of $400 if we hit the profit target.
So the current program is massively understating the profit in $ and the percentage. The rate of understatement is approximated by the ratio of price/(ADR x 1.5). In this case 42.76/3.99 = 10.71. Therefore the program profit can be multiplied by this ratio to obtain the real profit. So $32 x 10.71 = $342. Its not exact due to rounding but close enough giving traders a way to evaluate the stock in addition to the win/lose ratio.
Of course the increase in quantities also make the losses bigger but overall this estimation should work out. I'm going to check all of the transactions on this stock to check the maths.
However, if the quantity calculation in the program could be updated (to bring it in line with the Power X Strategy) that would be far better than messing around with spreadsheets.
davidmhaylett
Hi,
Just noticed a major difference in the logic between this program and the Power X Strategy. It relates to the quantity of shares purchased on each trade. In this program the quantity purchased is worked out by taking the amount risked (either 100% of the account) or the % in the account risk parameter and dividing this by the entry price of the stock. So for example, take ticker ADPT, trade number 17. This takes the total account size (not realistic, should change the account risk to 1% or 2%) which equals $10,000 and divides by the entry price of $42.76 giving a quantity of 234.
This is NOT correct according to the strategy. Instead, the amount risked should be divided by 1 x ADR (in the book 1.5 x ADR was used but this has been updated). So this would give $10,000 divided by £2.66 (The ADR when purchase was made) = 3759 quantity.
Of course, using the entire account value on each trade is NOT realistic, so if we reduce this to 2% then we risk $200 (on the default account value of $10,000). We then divide this by $2.66 and the actual quantity bought would be 75 of ADPT.
This would then very accurately reflect the strategy. The related issue, in my earlier post, is that there is currently a bug in the account risk parameter with values less than 100 not working properly.
It would be fantastic to get these two issues fixed to assist all traders using this strategy. Comments welcomed.
Thanks.
David H
davidmhaylett
Hi, great script.
There does, however, seem to be a bug related to the 'Account Risk' parameter. By default the setting is 100 (meaning 100% of the account) which means that the entire account value is traded on each trade. Not reality but ok for testing purposes.
But if I change the account risk to 1%, the list of trades is not consistent with regard to the quantity. In some cases the full account value is used (10,000 currency as default) and in other cases 1% is used (100 currency). For example , take stock ticker 'BLMN'. Trade 5 has a quantity = 5 with a price of 19.46 which used up 97.3 of currency (close to 1% of the account). Trade 22 uses a quantity of 420 with a price of 23.78 using 9987.6 of currency (close to 100% of the account). Both occur with the account risk set = 1%. You will find many other examples across numerous stocks.
Would be great if you could update the code. Unfortunately I'm too stupid to do it. I think the existing code can still be used with the Account Risk set= 100 but it would be more realistic to be able to use 1% or 2%, etc as recommended by Markus.
Thanks,
David H
Farmer_George
My experience is also mixed and am refining the approach. A couple of issues with the otherwise excellent program. It tends to buy long on a black candle, which is indicating 'none'. This occurs when the black candle follows a green buy candle and when it has a high greater than the previous green candle's high. Has anyone else observed this? Also, see my previous post on qty.
jbaviator
Just wondering how your trading has been going using this strategy? I've been dabbling with small positions using the screener (haven't bought the software) and have had mixed results. I do like that Markus emphasizes proper risk management in his books / video's and have significantly improved my trading just by managing risk better.
Farmer_George
I've been looking at your excellent PowerX program. I have the following question. Should qty in the following and similar 'crazy if statements' lines:
strategy.entry("Long entry", strategy.long, qty = strategy.initial_capital / high[4], stop = high[4], limit = high[4] * gapPercent)
not be: qty = round(strategy.initial_capital * risk / 100 / high[4])?

Apologies if I misunderstood , but I'm new to Pine. Thanks.
เพิ่มเติม