Power Trading (based on Standard Deviation)
Forums › ProRealTime English forum › ProOrder support › Power Trading (based on Standard Deviation)
- This topic has 16 replies, 4 voices, and was last updated 2 years ago by Khaled.
-
-
09/17/2022 at 12:27 PM #200932
Power Trading (a trading system based on the standard deviation)
I want to share with you a trading system that is based on a difference equation.
In this case, the difference equation describes the difference between two prices.
The basic question was: how can I describe the difference between two prices or in formula form:
Close = Close[n] + ???
What is it that causes the current rate to differ from the previous rate, what causes the price change?
There are many different opinions about this, for example:
1: It is a deterministic process (it is already fixed)
2: It is the psychology of the investor
3: It is purely economical
4: It is a random, unpredictable stochastic process
5: etc.
The change of course is probably the result of a mix of the above views… 🙂
Because you can’t figure this out, the next question is: how can I describe this change of course, in formula form, in the best possible way?
To make a very long story short, it turned out that the standard deviation is the best (?) way to describe the price change.
The difference equation then looks like this:
Close = Close[n] + Std[n](Close[n])
Or for falling prices:
Close = Close[n] – Std[n](Close[n])
Example:
Suppose you want to build a LONG system for the Nasdaq, then your code, in its simplest form, can look like this:
DefParam CumulateOrders = False
If Close > Close[n] + Std[n](Close[n]) then
Buy 1 contract at Market
EndIf
If Close < Close[n] – Std[n](Close[n]) then
Sell at Market
EndIf
The only variable in this system is the period [n] and you can of course optimize this for the different markets. It turns out to be a robust system.
It would be nice if we could use all the knowledge from the forum regarding optimization of the system (TF, Money Management, Stops, MTF, etc.) so that we can all benefit from it.
Power Trading123456789DefParam CumulateOrders = FalseIf Close > Close[n] + Std[n](Close[n]) thenBuy 1 contract at MarketEndIfIf Close < Close[n] - Std[n](Close[n]) thenSell at MarketEndIf1 user thanked author for this post.
09/17/2022 at 3:56 PM #20094209/17/2022 at 4:48 PM #200943Hi @phoentz
No, not only LONG, you can also use these equations to make a SHORT system or a combined LONG / SHORT.
Example SHORT:
If Close < Close[n] – Std[n](Close[n]) then
SellShort x contracts at Market
EndIf
The “DrawDown” and the time in the market depends on which time frame you use the system in… time frame can vary from 10 seconds to an hour?
09/17/2022 at 5:31 PM #200944Would this be the setup for long and short?
1234567891011121314151617DefParam CumulateOrders = Falsesl=1If Close > Close[n] + Std[n](Close[n]) thenBuy 1 contract at MarketEndIfIf longonmarket and Close < Close[n] - Std[n](Close[n]) thenSell at MarketEndIfIf Close < Close[n2] - Std[n2](Close[n2]) thensellshort 1 contract AT MARKETEndIfIf shortonmarket and Close > Close[n2] + Std[n2](Close[n2]) thenexitshort at MarketEndIf09/17/2022 at 5:39 PM #20094509/17/2022 at 6:26 PM #200946In addition to the theory:
Difference equations can also use coefficients, for example, the difference equation can looks like this:
Close = a * Close[n] + b * Std[n](Close[n])
The coefficients used here are therefore a and b.
How could you use these coefficients?
Suppose you use the LONG system again and when you, for example, let the coefficient b vary when closing the LONG position, you give more “space” to the price in practice to be able to move before the position is closed.
DefParam CumulateOrders = False
If Close > Close[n] + Std[n](Close[n]) then
Buy 1 contract at Market
EndIf
If Close < Close[n] – 2 * Std[n](Close[n]) then
Sell at Market
EndIf
1 user thanked author for this post.
09/19/2022 at 10:46 PM #201062Hi JS, I think we have discussed this STD topic before. The difficulty is to adapt the lookback (n1, n2) and the factors (a1, a2, b1, b2, etc.) over time as these factors need to be reassessed whether the market is bull or bear. You need a polynomial equation may be using Phyton. In reality, there is an infinite number of combinations of these factors.
Do you use Phyton to optimize your equations?
09/20/2022 at 6:55 AM #201064Hi @Khaled
We may have talked about the standard deviation before, but this difference equation is “new”…
My basic setup for any market is as follows:
Long system (Bull market) + Short system (Bear market)
Optimizing the period for the Long [n1] and Short [n2] sides.
In my optimizations, [n] is robust and fairly constant for the different markets.
The only coefficient I then use in practice is (b), to adjust the standard deviation to the volatility of the different markets. In a Long/Short system, I use the coefficient (b) only to close the position. You can (b) vary between 1 and 5, where it usually comes to 1, 2 or 3.
When optimizing the coefficient (b) I use steps of 1 to keep the whole thing robust.
I have mentioned all coefficients as a supplement to the theory of a difference equation, but I only use (b).
Of course, the story is not finished yet, because the other parts of the system (MM, TF, etc.) are just as important…
09/20/2022 at 10:07 AM #201076JS, your idea is brilliant. It is actually close to Bollinger Bands concept. I think we can trade it:
- Mean Reversion where for Long: close crosses over close[n1] – (minus) a1 * STD[n2]. (Note: n1 and n2 can be equal). Opposite for Shorts.
- Breakout where you have a tight a1, a2 and for Long : close crosses over close[n1] + (plus) a1 * STD[n2]
We can also use STE instead of STD.
I wonder if using a programme like Phyton we can find the best equation which can be a Polynomial. It’s a pity that we still cannot programme functions on PRT. (https://www.prorealcode.com/topic/polynomial-regression-indicator/page/2/#post-200827)
Any other idea how we can trade it?
Any idea how we can get Z = aX^n1 + bX^n2 + c (or another degree) equation ? I saw some suggestions using Phyton, but it’s not handy.
I tried to create a Polynomial based on the close of the last 30 days of ES, but the only variable which provided reasonnable R^2 was the Barinex. I tried RSI, Will R%, Momentum, ROC, but R^2 was low compared to Barindex. For me, it doesn’t make sense to have the price of an asset as a function of the number of bars 🙂
I’m really very interesed in this area of predictive functions, but I have a full time job and don’t have enough time to explore all options available on internet.
The dream is to have the n, a, b c, etc. variables optimized live by PRT using the module of backtesting in an Indicator or a System running live. Not sure if the idea is clear enough, but if PRT can do backtesting in ProOrder, this very same module should be made availble to have LIVE optimization of parameters of an indicator or a system which is running live)
Please if you have any thoughts on all the above, it would be much appreciated.
09/20/2022 at 4:28 PM #201096Hi @Khaled
Nice that you think it’s a good idea.
You can also visualize the equation in this way: you compare the price with a shift of itself (Close = Close[n]) and on this you project the volatility (Close[n] + Std[n](Close[n]).
It is a “break-out” system (Close > …)
First there was the idea and that turned out to fall into the category of “difference equations”. The system itself falls under the category of LTD systems.
LTD = Linear Time Invariant Discreet (you just must look it up on the internet, is super interesting).
I have never used STE myself, but I will definitely try it.
To solve a “complete” difference equation, including the coefficients, is (still) a step too far for me, I also only know the code of PRT (and BASIC) but no other programming language.
It would of course be super interesting if you / someone could do this.
I also have a full-time job and two children 😉 so my time is also limited to learn a whole new programming language.
I also think it is not necessary at all, there are already enough possibilities available to make something beautiful out of it …
I am working on a filter based on the STD and with MM connected to the system.
09/20/2022 at 8:20 PM #201105I think the problem with the (n1, n2) and (a, b, c) is that you need to run an optimization, thus somehow curve fitting, and therefore requires updates to find the optimal parameters. When you at Indices, it’s clear the markets in 2022 are very different from 2021. There is no size fits all, like in any Algos. With that said, I tried your idea with only 4 parameters (n1, a1 and n2,b) and found an incredibly high win rate without adding sophisticated trailing stop or MM. So, it’s promising for sure. Need to find time to explore the subject.
09/20/2022 at 9:02 PM #201107That’s right, the Profit/Loss ratio is very good with this system and the Risk/Reward ratio.
To make the system even better, it must be totally consistent.
The most important factor in the system is the standard deviation and this important factor should also play a role in buying and selling the contracts.
Now it simply says: “Buy 1 contract at Market” and the most important factor does not appear here. The system and the MM are not consistent with each other, it is not one whole.
What I am showing now is not for practice but to show that when a system is consistent it performs much better overall.
When you change the code from:
“Buy 1 contract at Market” in “Buy Std[n](Close[n]) at Market”
Now you made the system consistent by using both the standard deviation in the condition and in the Money Management.
This makes all the ratios better and the best thing is, which is incredible, that the period [n] for a lot of markets comes out at about the same values.
If Close > Close[n] + Std[n](Close[n]) then
Buy Std[n](Close[n]) at Market
EndIf
Again, this is not for trading in practice (or you have to have very deep pockets) but as an example of how to make a system consistent.
1 user thanked author for this post.
09/20/2022 at 9:23 PM #201108For the sake of completeness, I then use this system:
DefParam CumulateOrders = False
If Close > Close[n] + Std[n](Close[n] then
Buy Std[n](Close[n]) at Market
EndIf
If Close < Close[n] – 2 * Std[n](Close[n] then
Sell at Market
EndIf
Nasdaq, TF 10 min, Spread 2, 200k Units
09/20/2022 at 10:49 PM #201113Interesting. Thanks!
On another topic. I see you’re using a Mac. Do you have any speed/slow issues with PRT? I’m running PRT on MacBookAir 2021 RMA 16Gb, Monterey 12.6, Broker IB, and after 1 or 2 hours using PRT, it get very slow.
09/21/2022 at 6:02 AM #201117 -
AuthorPosts
Find exclusive trading pro-tools on