There are a billions ways to adapt your risk exposure while trading. Another approach is to base our trades triggers on recent performance of the strategy by using the strategy profit curve like any other technical indicator. ProBuilder language offers this possibility.
What is the strategy profit curve ?
The instruction ‘strategyprofit’ is present in the ProBuilder language. It returns the profit of the automated trading strategy you actually trade. Like any other variable it can be use to manage trading triggers with specific conditions based on it.
A perfect trading strategy would return a perfect profit curve, like this one :
Of course, it is irrelevant as it would reflect a strategy that always win or never cut a loss.
Using the strategy profit curve, built in ProRealTime, can almost achieve this possibility, not to make a strategy perfect, but the capability to make your profit curve look more straight than it could be without using this trick.
Let have a look of what is the strategy profit look like in ProBacktest, using the GRAPH instruction i introduced in a recent other blog article.
I’m using a simple golden cross long only strategy on S&P500 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
i1 = exponentialaverage[15](close) i2 = exponentialaverage[50](close) long = i1 crosses over i2 short = i1 crosses under i2 IF NOT LongOnMarket AND long THEN BUY 1 CONTRACTS AT MARKET ENDIF IF short THEN SELL AT MARKET ENDIF |
Adding the GRAPH instruction at the end of the code, to reflect the profit as a variable :
1 |
GRAPH strategyprofit as "strategy profit" |
Return the stair steps of our profit over time :
Use strategyprofit variable as a trigger
While our strategy may have a nice decent profit, its curve is not so straight and may create doubt in its reliability over time. We know that the strategy is profitable on long term, because we also have a clear view of the past by now, but we also know by now that market conditions may minimize its profitability sometimes.
Sometimes, our strategy profit is declining, we can avoid long runs of profit disappearance by triggering our entries with the strategyprofit curve.
This curve can act as any other technical indicators to make market entries decisions. A simple way to open trades or not is to add a classical moving average to the curve and using it as a trigger.
Passing strategyprofit values into a simple moving average :
1 2 3 4 5 |
curveperiod = 500 equitycurve = average[curveperiod](strategyprofit) GRAPH equitycurve coloured(255,0,0) as "profit curve" |
give us a more clear view of the profit over time :
We can see here that a crossover of the profit of the strategy crossing its average may be a good trigger to :
- stop using the strategy while the profit is under the average
- trading the strategy while the profit is still over the average profit over time
Equity curve trading
Here is the entire code of the strategy within the triggers :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
//variables equitycurve = undefined curveperiod = 500 once mydays = 1 once olddate = 0 //indicators i1 = exponentialaverage[15](close) i2 = exponentialaverage[50](close) equitycurve = average[curveperiod](strategyprofit) //trades conditions long = i1 crosses over i2 short = i1 crosses under i2 //mydays variable incrementing to let the average curve build over time if date > olddate then mydays=mydays+1 olddate = date endif //first trades while the average profit curve is building IF NOT LongOnMarket AND long AND mydays<curveperiod THEN BUY 1 CONTRACTS AT MARKET ENDIF //trades when the curve has built IF NOT LongOnMarket AND long AND strategyprofit>=equitycurve AND mydays>curveperiod THEN BUY 1 CONTRACTS AT MARKET ENDIF //exit positions IF short THEN SELL AT MARKET ENDIF GRAPH equitycurve coloured(255,0,0) as "profit curve" GRAPH strategyprofit as "strategy profit" |
and here is the strategy profit returns by ProBacktest :
So, here is the deal : we have a better straight profit curve, but we may have also not trade for a long period and miss a lot of good trades while the strategy profit were under its average. There is nothing perfect, but the strategy well perform most of the times.
Here is a profit curve comparison :
Because the average will never drop below the actual profit of the strategy, we need to trigger its activation when the average is equal to profit. This will lead to trade once and get back to non trade period if this trade is not a profitable one. In fact, this behaviour can be a strategy killer, it can results in slow profit drain if there are a lot of bad trades in the same row. This is the main con of this trading trick, but there are many more ways to deal with the strategyprofit curve, this article deal with the main idea behind it and i’m gonna talk again in future blog’s posts, i guess !
Many more ways to deal with the strategyprofit curve
Here are some ideas, that be can explored by this technique :
- trades volumes sized adapted to the equity curve values (more volumes or less when you are below/above it)
- use standard deviation of your strategy profit : when profit derivate more than 2% from its average, stop trading or adapt strategy
- rebalancing strategy on other instrument
- … your ideas !
I’ll appreciate discuss more about this with any one, please feel free to comment and share your ideas about it ! Thanks in advance.
Hi Nicolas,
What version of the software are you using/in which version(s) of the software is this supposed to work?
In my case, the moving average is not calculated/displayed correctly. It is just displayed on top of the strategyprofit line.
I am using PRT through IG Markets.
Regards
Stef
Hello Stef, when I wrote this article there were no possibility to do it correctly with IG datas. My own tests were made with Prorealtime Software 10.2. I know there are some differences between the kernel versions, even if they got the same version number though.. Also if you do not have a lot of trades, the moving average will be almost flat, so you have to adapt the MA period to the trades quantity already closed. Let me know if I can be of any assistance further more.
Hi Stef, The moving average plots based on the number of bars in the time period, rather than the number of trades you have taken in that time.So for example, if your algo takes 1 trade per day on a 5min chart, then anything less than 288 SMA is going to look like PRT is just plotting on top of your strategy profit line.I haven’t coded this in to know whether it works for exiting strategies yet, but I use it to manually compare (and know when to switch off) algos.For the sake of comparing apples with oranges, I use 5,760 SMA on 5min charts, 1,920 SMA on 15min charts, 120 SMA on 4hr charts… these examples all basically the previous 20 trading days average of my strategy profit line.Let me know if this works for an auto exit! I’m very interested… in the meantime its a good visual to see how your strategy profit is doing.
Bonsoir Nicolas
Existe un moyen de coder un reset quotidien de la variable strategycurve afin qu’elle soit à 0 lors de chaque nouvelle journée de trading (j ai un flatafter.. chaque fin de journée) ?
Merci par avance
Tof
Oui c’est possible en faisant ceci:
if intradaybarindex = 0 then
equitycurve = 0
endif
After a lot of testing I conclude that not only is the MA not displayed correctly (as Steff points out above) but also the Strategy above does not work on PRT provided through IG. I guess this is due to the MA not calculating correctly?
If I am wrong, please let me know?
Thought provoking how certain features that may reduce losses / drawdowns seem to not function through IG??
GraHal
I don’t know why it were not functioning through IG at the time I wrote this article. I’ll ask PRT if it works correctly now, asap, and I’ll give update here.
Hi Nicolas, I was looking forward to testing and using this feature but have found the same thing using IG/PRT and also the other way round by using the affiliated link through PRT that gives 200k of data. Hopefully they will fix this soon.
Bonjour Nicolas
En essayant d’appliquer ” trading the strategy profit curve” sur une de mes stratégies
le graph ne retourne pas la moyenne mais uniquement la courbe profit;
J’ai donc recopié ton code et réessayé avec ton code intégral pareil pas d’apparition de la moyenne en rouge??
Cependant quand ça va bien fonctionner ça me parait être intéressant
ce qui serait également très intéressant c’est qu’on puisse utiliser le procreener pour
détecter des phases pertinentes d’entrée ou de sortie.
Cela sera t il possible???
Bonne journée
Madrosat
Hey guys,
with the help of PRT programmers i solved the problem occuring on IG accounts.
Instead of
GRAPH strategyprofit as \"strategy profit\"
you have to use the following code
if not onmarket then
mystrategyprofit=strategyprofit
elsif longonmarket then
mystrategyprofit=strategyprofit+(close-tradeprice)/pointsize*pointvalue*countoflongshares
elsif shortonmarket then
mystrategyprofit=strategyprofit+(tradeprice-close)/pointsize*pointvalue*countofshortshares
endif
equitycurve = exponentialaverage[a](mystrategyprofit)
GRAPH mystrategyprofit as \"strategy profit\"
GRAPH equitycurve coloured(255,0,0) as \"profit curve\"
With this code i was able to use the strategy profit curve for trading decisions on an IG account. Unfortunately the use of an EMA was’t helpfull to increase performance.
Maybe you have a better idea to use it.
Great! Thank you very much for posting it here for everyone.
No Problem. Hope, someone can work out, how to use it. The EMA 1000 on my profit curve led to a clear reduction of profit
From my own experience, trading the equity curve is a dead-end. I used to make a lot of tries and experimentation on this on other trading software languages, with fictitious orders but the result is almost always the same :
you miss a lot of good trades, your strategy is “broken”..
even if a fictitious trade made good gain for the equity curve to be above the average, the next trade could a looser and same thing happen again: you need to make new fictitious trade, etc.
It results at the end that your strategy is not a looser one, but not a winner one. The equity curve of the overall strategy backtest is almost like a flat line. However, this is something very interesting for educational purpose.
Keep on searching about this!
Great idea @Nicolas! We are privileged to have the benefit of your creativity available to us – many thanks.
I agree that to many excellent strategies suffer from large draw downs, any anything that can reduce this turns a good strategy into an excellent one. I am currently testing your trailing stop loss code with a number of strategies and find it very successful in this regard.
Best regards to all traders who struggle – it is the best way to learn! As Google’s directive to their researchers goes….. “Fail early, fail often but fail forward”.
Mike
Couldn’t get this idea to work on 10.3 IG PRT, the GRAPH strategyprofit appears ok, but when i put GRAPH Average[X](strategyprofit) no moving average appears in my window. Any solutions?
There must be sufficient data to compute the average (X period used).
Copy that , thanks;)
Nice, we love you
this is an awesome tool and a great idea for it . thanks for that