Hi.
There’s a way to have average on equity line inside a trading system code?
Thanks.
Andrea
Of course, you can add any value arrays in AVERAGE function. Just compute your equity variable and average it on n periods.
Thanks.
How can i compute my equity variabile?
myequity = (((close-positionprice)*pointvalue)*countofposition)/pipsize + strategyprofit
avg = average[20](myequity)
Hi
Thank you for the code. What I have to do if I want that the strategy only trade if the equity curve is above the moving average (of the Equity curve)? I tried it with this one but it doesn`t work:
myequity = (((close-positionprice)*pointvalue)*countofposition)/pipsize + strategyprofit
avg = average[20](myequity)
IF NOT OnMarket AND l10 AND l20 AND (strategyprofit > avg) THEN
BUY 1 CONTRACTS AT MARKET NEXTBAROPEN
ENDIF
I’m sorry, I forgot something important. It’s more complicated than I thought. I have inserted a picture to illustrate it.
If the equity curve is above the MA, then the system trades (it`s online). If the equity curve is below the MA then the system must be offline. The problem is, however, that the strategy have to make “fictitious order” (without really buying contracts) so you can get back in the system as soon as the strategy is again over the MA. Hope you understand what I mean.
Hi, did you work a way around this problem?
I did not test the code Skubidu made, but 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, I may write something about it in the blog.
For your information, Wisko have solved the problem of not displaying correctly the equity curve for the IG accounts users, you can have a look it here:
http://www.prorealcode.com/blog/trading-strategy-profit-curve/#comment-2189
Here is the full code he get from PRT to fix this issue:
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"
Hope it helps here too 🙂