So comments welcome, mods for other scenarios, but here I got to thinking about keeping my profits reasonably safe and increasing trade amounts without stopping the program. so below is the code. It works on backtest and sould reduce trade amount based on your profit elvel and setting for tolerance.. Comments and additions welcomed but for me this works well I think.. I’ve yet to backtest with losses but think it should work based on the logic.
Mystartamount = 1 //your risk tolerance start amount based on stoploss
SL=300// your stoploss
tp=28 //your take profit level
mydiv=2 //factor by which to increase the trade amount by to limit stoploss but increase it with profits safely which will depend on stopout factors
Myabsloss=0 //the amount you want to tolerate as an absolute loss.
x=strategyprofit/(SL*mystartamount)
If strategyprofit<=(SL*mystartamount) then
Myamount=mystartamount
Endif
If x>=2 then //x=the factor to increase risk calculation by when the profit has reached the stoploss multiple of x
myamount=(x*((mystartamount/mydiv))) //(x*mystartamount/2) is exponential growth and keeps stoploss at less than profits when profits above SL*2.
endif
If strategyprofit<0 then
quit
endif
IF "your conditions" then
BUY Myamount contracts at market
set stop ploss SL
Set target pprofit tp
ENDIF
If strategyprofit<myabsloss then
quit
endif
You will find that if you use an absolute gain it can increase yield and having a Mydiv greater than 2 will limit gains initially but minimise losses if it starts to fail and as it grows good wins/runs can become exponential in meeting absolute gains though thats in backtesting of course. Currently if you apply to the Dax Kama program I’ll have to dig out a link, it turns 9K to 21K with a £15K absolute gain when running from Jan 2019 and then quit the program.
Any suggestions on resetting the strategyprofit=0 would be appreciated as that could reset the program to restart from scratch after hitting target. If there’s any code snipbit for that be good i.e telling the program to set to strategyprofit=0 for a fresh start without closing the program.
Anyone looking I’m adding a margin tolerance and minimum trade tolerance level which will stop program shutting down if that became a factor but a means of strategy profit resetting or calculating strategy profit to rest be useful. I’ll scour the forum but a pointer be useful if its there
So this is a pic of my initial idea and how it works. I’ve not included the code yet thats been modded as it’s not quite finished owing to tweaking the margin tolerance, and snagging out any scenarious where calculation may stop the program continuing, but it’s looking promising – if needing refinement..
The idea is that when running well it will increase the trade amount in increments, and when experiencing a loss reduce the trade amount accordingly up to the initial trade amount starting the program. Potentially it could be reduced as well if experiencing too much program drawdown..
The 100% data in the pic attached highlights the incremental change, and it reduces back to the intial trade amount once it has hit a target amount which I call my absolute gain = myabsgain in the code.
As a reasonably newby I think its important to optimise potential success of a strategy at startup and put in risk tolerance before quitting, so this is to look to optimise profitable runs and it can be tweaked with the myabsgain, some code, and reduces trade amount accordingly if dropping profits… Not much interest in the idea It seems, so I’ll limit posting unless some interest shown..