Trading system template
Forums › ProRealTime English forum › ProOrder support › Trading system template
- This topic has 23 replies, 5 voices, and was last updated 2 years ago by
Kev Monaghan.
-
-
01/24/2022 at 12:12 AM #186397
Hi all,
I have been using a template I created for my strategies which is based on some fundamental trading principles that I personally find important.
the concept for creation is that trade management is more important than how you enter a trade and the whole template is to operate under the fact that the market is always random, ie you can enter at any moment and the probability of the trade moving 1 tick in your direction is 50%, therefore:
I utilise scaling to increase probability at the cost of risk reward(on paper), scaling is utilised in both entries and exits.
the system starts by risking 50% of equity and the system will also auto scale up on size based on equity until it reaches a certain amount of contracts(r) and will then reduce overall risk by lowering the risk ratio on equity to avoid loosing to much money in a single trade as the account grows.
I have started working on a version that also includes predicting liquidity and scaling in to full size, but it is just preliminary thoughts put to basic code.
I have been applying this outline across multiple systems and time frames and found even a poor strategy can be reasonable profitable.
I will attach results and code for v5 and liquidity v6 below minus my custom entries and exits (which a merely price action breakout/failure based + a custom indictor on 1 min charts), there is no point sharing exact exits etc as liquidity would neutralise the strategy anyway.
I would appreciate some input on optimization and ideas for trade management as I am not a very experienced programmer (not even close) and maybe people might find applying some principles helps their systems.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879T = TIME > 160000 OR TIME < 080000DaysForbiddenEntry = OpenDayOfWeek = 0// THIS STRATEGY RISKS HALF ITS ACCOUNT EVERY TRADE UNTIL IT PASSES RISK ADJUST 1 TO 5 WHERE IT SCALES BACK TOTAL RISK//MINIMUM CAPITAL 2000 MINIMUM RISKSCALE 1000 FOR 1MIN CHARTS//USER SETTINGS / CUSTOMIZE FOR SYMBOLSTARTINGCAPITAL = 2000 //ADJUST FOR STARTING CAPITALRISKSCALE = 1000// $ AMOUNT OF EQUITY REQUIRED TO TRADE 1 CONTRACTPOSITIONSIZING = (STARTINGCAPITAL+STRATEGYPROFIT)/RISKSCALE //NUMBER OF CONTRACTS TRADED BASED ON EQUITY AND RISKCOSTPERPOINT = 20EXPONETIALRISKLIMIT = 0.025// PERCENT OF EQUITY TO RISK PER ENTRY: STOP LOSS = (LOSSLIMIT/RISKADJUST)*EXPONETIALRISKLIMIT = (TOTALEQUITY/TRADESIZE)*EXPONENTIALRISKLIMT EG (2000/2)*0.025 SETS STOPLOSS AT 25 POINTS OR $1000PROFITREQUIREDTOTP = (TICKSIZE*12)//WHEN TO START TAKING PROFITS, SO AS NOT TO 'TAKE PROFIT' WHEN NOT IN PROFIT// CAN ADJUST FOR SPREADS ETCR = 2 //RISK ADJUSTMENT FOR MAX CONTRACT VALUE BEFORE AUTO SCALING DOWN RISK INITIATES//SELF SCALING CAPITAL PROTECTION / ADJUST TO SCALE DOWN RISK AS PROFIT ACCUMULATE// ADJUST R FOR SELF SCALING RISK RATIORISKADJUST = POSITIONSIZINGIF POSITIONSIZING => R THENRISKADJUST = POSITIONSIZING*0.5IF POSITIONSIZING => R*5 THENRISKADJUST = POSITIONSIZING*0.25IF POSITIONSIZING => R*10 THENRISKADJUST = POSITIONSIZING*0.1IF POSITIONSIZING => R*20 THENRISKADJUST = POSITIONSIZING*0.05IF POSITIONSIZING => R*50 THENRISKADJUST = POSITIONSIZING*0.025ENDIFENDIFENDIFENDIFENDIF//SYSTEM EQUITY CHECK // ADJUST FOR TOTAL AMOUNT OF EQUITY TO RISK ON THIS SYSTEMLOSSLIMIT = STRATEGYPROFIT + STARTINGCAPITALIF LOSSLIMIT>0 THENSYSTEMPOSITIVE=1ELSIF LOSSLIMIT=<0 THENSYSTEMPOSITIVE=0ENDIFPROFITABLESTRATEGY = SYSTEMPOSITIVE=>1 // CONDITION TO ONLY TRADE WHEN SYSTEM HAS NEUTRAL TO POSITIVE EQUITY//ADDS AND ENTRIES // DECIDES IF AN ORDER IS AN ADD OR AN ENTRY AND WHAT SIZE TO BUY TO ACHIEVE FULL SIZEFULLSIZE = COUNTOFPOSITION => RISKADJUST[TRADEINDEX(1)]// USED TO PREVENT SCALING DOWN TO MUCH TO EARLY //NOT USED CURRENTLYADDSIZE = RISKADJUST - COUNTOFPOSITION //SIZE USED TO CALCULATE ADDS IN LINE WITH RISK RATIOINPROFIT = HIGH[1]>POSITIONPRICE+PROFITREQUIREDTOTP//INDICATORSTRENDFmyBC//OTHER FUNCTIONSCOP50 = COUNTOFPOSITION/2 //half of position// Conditions to enter long positionse1 =If NOT LONGONMARKET AND e1 AND PROFITABLESTRATEGY AND T AND NOT DaysForbiddenEntry THENBuy RISKADJUST CONTRACTS ROUNDEDUP AT CLOSE[1]+2 LIMITELSIf LONGONMARKET AND e1 AND PROFITABLESTRATEGY AND T AND NOT DaysForbiddenEntry AND COUNTOFPOSITION<RISKADJUST THENBuy ADDSIZE CONTRACTS ROUNDEDUP AT CLOSE[1]+2 LIMITENDIF// Conditions to exit long positionsex1 =EX2 =If ex1 and LONGONMARKET AND INPROFIT THENSell (Cop50) contract RoundedUP at high[1] limitELSIF ex2 and LONGONMARKET AND NOT INPROFIT THENSELL AT MARKETendif//USE 'IF AT FULLSIZE' TO SCALE OUT / USE ' IF NOT AT FULLSIZE' FOR FINAL TAKE PROFITS//SET STOP LOSS AND TAKE PROFIT REMOVE//TOACTIVATESTOPLOSS = (LOSSLIMIT/RISKADJUST)*EXPONETIALRISKLIMITSET STOP PLOSS STOPLOSSv6 liquidity123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293T = TIME > 160000 OR TIME < 080000DaysForbiddenEntry = OpenDayOfWeek = 0// THIS STRATEGY RISKS HALF ITS ACCOUNT EVERY TRADE UNTIL IT PASSES RISK ADJUST 1 TO 5 WHERE IT SCALES BACK TOTAL RISK//MINIMUM CAPITAL 2000 MINIMUM RISKSCALE 1000 FOR 1MIN CHARTS//USER SETTINGS / CUSTOMIZE FOR SYMBOLSTARTINGCAPITAL = 2000 //ADJUST FOR STARTING CAPITALRISKSCALE = 1000// $ AMOUNT OF EQUITY REQUIRED TO TRADE 1 CONTRACTPOSITIONSIZING = (STARTINGCAPITAL+STRATEGYPROFIT)/RISKSCALE //NUMBER OF CONTRACTS TRADED BASED ON EQUITY AND RISKCOSTPERPOINT = 20EXPONETIALRISKLIMIT = 0.025// PERCENT OF EQUITY TO RISK PER ENTRY: STOP LOSS = (LOSSLIMIT/RISKADJUST)*EXPONETIALRISKLIMIT = (TOTALEQUITY/TRADESIZE)*EXPONENTIALRISKLIMT EG (2000/2)*0.025 SETS STOPLOSS AT 25 POINTS OR $1000PROFITREQUIREDTOTP = (TICKSIZE*12)//WHEN TO START TAKING PROFITS, SO AS NOT TO 'TAKE PROFIT' WHEN NOT IN PROFIT// CAN ADJUST FOR SPREADS ETCR = 2 //RISK ADJUSTMENT FOR MAX CONTRACT VALUE BEFORE AUTO SCALING DOWN RISK INITIATES//SELF SCALING CAPITAL PROTECTION / ADJUST TO SCALE DOWN RISK AS PROFIT ACCUMULATE// ADJUST R FOR SELF SCALING RISK RATIORISKADJUST = POSITIONSIZINGIF POSITIONSIZING => R THENRISKADJUST = POSITIONSIZING*0.5IF POSITIONSIZING => R*5 THENRISKADJUST = POSITIONSIZING*0.25IF POSITIONSIZING => R*10 THENRISKADJUST = POSITIONSIZING*0.1IF POSITIONSIZING => R*20 THENRISKADJUST = POSITIONSIZING*0.05IF POSITIONSIZING => R*50 THENRISKADJUST = POSITIONSIZING*0.025ENDIFENDIFENDIFENDIFENDIF//PREDICTED LIQIDITYSPREADORDERS = 0PREDICTEDLIQUIDITY = HIGHEST[5](VOLUME)-LOWEST[5](VOLUME)IF RISKADJUST > PREDICTEDLIQUIDITY THENSPREADORDERS = 1ENDIF//SYSTEM EQUITY CHECK // ADJUST FOR TOTAL AMOUNT OF EQUITY TO RISK ON THIS SYSTEMLOSSLIMIT = STRATEGYPROFIT + STARTINGCAPITALIF LOSSLIMIT>0 THENSYSTEMPOSITIVE=1ELSIF LOSSLIMIT=<0 THENSYSTEMPOSITIVE=0ENDIFPROFITABLESTRATEGY = SYSTEMPOSITIVE=>1 // CONDITION TO ONLY TRADE WHEN SYSTEM HAS NEUTRAL TO POSITIVE EQUITY//ADDS AND ENTRIES // DECIDES IF AN ORDER IS AN ADD OR AN ENTRY AND WHAT SIZE TO BUY TO ACHIEVE FULL SIZEFULLSIZE = COUNTOFPOSITION => RISKADJUST[TRADEINDEX(1)]// USED TO PREVENT SCALING DOWN TO MUCH TO EARLY //NOT USED CURRENTLYADDSIZE = RISKADJUST - COUNTOFPOSITION //SIZE USED TO CALCULATE ADDS IN LINE WITH RISK RATIOINPROFIT = HIGH[1]>POSITIONPRICE+PROFITREQUIREDTOTP//INDICATORSTRENDF =myBC=//OTHER FUNCTIONSCOP50 = COUNTOFPOSITION/2 //half of position// Conditions to enter long positionse1 =If NOT LONGONMARKET AND SPREADORDERS =<0 AND e1 AND PROFITABLESTRATEGY AND T AND NOT DaysForbiddenEntry THENBuy RISKADJUST CONTRACTS ROUNDEDUP AT CLOSE[1]+2 LIMITELSIf LONGONMARKET AND SPREADORDERS =<0 AND e1 AND PROFITABLESTRATEGY AND T AND NOT DaysForbiddenEntry AND COUNTOFPOSITION<RISKADJUST THENBuy ADDSIZE CONTRACTS ROUNDEDUP AT CLOSE[1]+2 LIMITELSIF NOT LONGONMARKET AND SPREADORDERS =>0 AND e1 AND PROFITABLESTRATEGY AND T AND NOT DaysForbiddenEntry THENBuy RISKADJUST/2 CONTRACTS ROUNDEDUP AT CLOSE[1]+2 LIMITELSIf LONGONMARKET AND SPREADORDERS =>0 AND e1 AND PROFITABLESTRATEGY AND T AND NOT DaysForbiddenEntry AND COUNTOFPOSITION<RISKADJUST THENBuy ADDSIZE/2 CONTRACTS ROUNDEDUP AT CLOSE[1]+2 LIMITENDIFIF BARINDEX[1] = TRADEINDEX[1] AND LONGONMARKET AND SPREADORDERS >0 AND COUNTOFPOSITION<RISKADJUST[TRADEINDEX(1)] AND E1[TRADEINDEX(1)]AND PROFITABLESTRATEGY AND T AND NOT DaysForbiddenEntry THENBUY COUNTOFPOSITION-RISKADJUST[TRADEINDEX(1)] CONTRACT AT HIGH+(TICKSIZE*12) LIMIT //TO GET INTOMARKET WITH TIGHT LIQUIDITYENDIF// Conditions to exit long positionsex1 =EX2 =If ex1 and LONGONMARKET AND INPROFIT THENSell (Cop50) contract RoundedUP at high[1] limitELSIF ex2 and LONGONMARKET AND NOT INPROFIT THENSELL AT MARKETendif//USE 'IF AT FULLSIZE' TO SCALE OUT / USE ' IF NOT AT FULLSIZE' FOR FINAL TAKE PROFITS//SET STOP LOSS AND TAKE PROFIT REMOVE//TOACTIVATESTOPLOSS = (LOSSLIMIT/RISKADJUST)*EXPONETIALRISKLIMITSET STOP PLOSS STOPLOSS01/24/2022 at 12:24 AM #186402I forgot to mention risk increases and decreases exponentially so on a winning streak the strategies will step it up, and when loosing they will scale down until winning again.
01/24/2022 at 12:36 AM #186403I would also like to have user inputs on my strategies similar to indicators but I am bot sure if that is possible on v11, maybe on a later version we could have user input variables.
01/24/2022 at 1:27 AM #186410Some other things I would like to build in are.
Stop trading if system exceeds set max expected drawdown%
Stop trading if system exceeds max predicted simultaneously losses
And other data gained from system analysis.
01/24/2022 at 5:31 AM #186416Hopefully the mods (@JC_Bywan, @robertogozzi) can split this into its own dedicated topic before we start responding to a nice topic which is very much off-topic in the Trading Template topic from nonetheless ?
(and throw out this post from me 🙂01/24/2022 at 6:47 AM #186418I moved it to ProOrder support.
Despite a similar title, this is different from nonetheless’topic, there’s no need to change, I believe.
01/24/2022 at 8:31 AM #186428Hi there Kev,
A couple of responses from my side. Here is a first one :
I would also like to have user inputs on my strategies similar to indicators but I am bot sure if that is possible on v11
See the attachments;
The first one I assume you will recognise (top-left in the Editor).
The second one you will find in the right-hand pane of the Editor. Click that. You will all your defined “Optimisation” parameters in there. This is for BackTesting.If you now prepare for Automatic Trading (3rd attachment) you will find input fields for all the variables you left from optimisation. “Left there” or just created for the purpose.
So Yes, possible …
Regards,
Peter01/24/2022 at 8:44 AM #186432What you are doing there seems a nice approach. Mind you please, this is subjective.
What is subjective as well, is my idea that this does not work well in practice. This is from quite explicit experience, attempting the same. This does not mean it can’t work, but at least I could not do it. Also, theoretically if chances would be 50% indeed (and they are not because markets are trending) then you would always lose on the spread (or commission) to pay. Thus now theoretically it can not work. 🙂
But we are not (ever) here to debunk one’s theories or strategies, so I am not doing that either. The contrary, I am intrigued. And others may be too. However :
I will attach results and code for v5 and liquidity v6 below minus my custom entries and exits (which a merely price action breakout/failure based + a custom indictor on 1 min charts), there is no point sharing exact exits etc as liquidity would neutralise the strategy anyway.
I feel that you could be making a mistake there. I mean, people will always be eager to try something “new” and see what it brings them. From there they will bring the adjustments you may actually be asking for. But there it nothing much to do in this case; There is no beginning and no end to it (haha). So my advice would be to put something to your TRENDF, myBC, e1, ex1 and EX2 – so that people can paste your code and give it a try. And it should give some positive result to begin with.
So there’s your first 2c. 🙂
01/24/2022 at 9:44 AM #186437Stop trading if system exceeds set max expected drawdown% Stop trading if system exceeds max predicted simultaneously losses
This MM code by Vonasi includes a quit function for max drawdown and other safeguards:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970// Strategy Stopper and Money Management// By Vonasi// 20191011barsbeforenextcheck = 22 // number of bars between performance checksdrawdownquitting = 1 // drawdown quitting on or off (on=1 off=0)winratequit = 25 // minimum win rate allowed before quitting (0 = off)tradesbeforewrquit = 10 // number of trades required before a win rate stop of strategy is allowed to happenincrease = 1 // position size increasing on or off (on=1 off=0)decrease = 1 // position size decreasing on or off (on=1 off=0)capital = 10000 // starting capitalstartingsize = 1 // starting position sizeminpossize = 0.2 // minimum position size allowedgaintoinc = 5 // % profit rise needed before an increase in position size is madelosstodec = 5 // % loss needed before a decrease in position size is mademaxdrawdown = 25 // maximum % draw down allowed from highest ever equity before stopping strategymaxcapitaldrop = 60 // maximum % starting capital lost before stopping strategyonce positionsize = startingsizeonce psperc = positionsize / capitalif strategyprofit <> strategyprofit[1] thenhighestprofit = max(strategyprofit, highestprofit)if winratequit thencount = count + 1if strategyprofit > strategyprofit[1] thenwin = win + 1endifwinrate = win/countif count >= tradesbeforewrquit thenif winrate < winratequit/100 thenquitendifendifendifendifif barindex mod barsbeforenextcheck = 0 thenif drawdownquitting thenif highestprofit <> 0 thenif (capital + strategyprofit) <= (capital + highestprofit) - ((capital + highestprofit)*(maxdrawdown/100)) thenquitendifendifif highestprofit = 0 thenif (capital + strategyprofit) <= capital - (capital * (maxcapitaldrop/100)) thenquitendifendifendifequity = capital + strategyprofitif increase thenif equity/lastequity >= (1+(gaintoinc/100)) thenpositionsize = (max(minpossize,equity*psperc))lastequity = equityendifendifif decrease thenif equity/lastequity <= (1-(losstodec/100)) thenpositionsize = (max(minpossize,equity*psperc))lastequity = equityendifendifendif1 user thanked author for this post.
01/24/2022 at 10:31 PM #186514“What is s theoretically if chances would be 50% indeed (and they are not because markets are trending) then you would always lose on the spread (or commission) to pay. “
ah yes that was just an example, obviously we increase probability, but the ‘1 tick’ is just an example,
‘INPROFIT’ is the line I use to ensure a certain amount of ticks to cover commissions etc, I have a bit of an Al brooks type way of thinking about the market, but I am only 1 year into trading.
The thing I have found with these lower time frame strategies is they will only work for a short time, so I have made this template to maximise profits in that time but still finish in profit when the system becomes inefficient, the entry and exit signals were not curve fitted but when tested ‘out of sample’ the strategy would need roughly double the starting capital to begin.
The variables will have to be changed when using different entries and exits and on different symbols, it is best to start with only 1 entry and exit then add in a second one when the first is profitable, the scaling apporach will see a 50% win rate go to 80% most of the time, but on paper the risk reward will be worse so I am aiming for a good ‘gain loss ratio’ instead.
I have modified a double bottom detector that I got from prorealcode, to output a histogram of +1 or -1 for bull or bear breakouts and the results posted above are from that, combined with my own indicator ‘trendf’ the later I may share oneday but first i need to recoup the losses I have had in my first year of trading.
(attached modified double bottom, feel free to move it to that thread if you want)
01/25/2022 at 1:32 AM #186524thats great thanks Peter, I have only just gotten to the point where i understand how to run optimizations so i have not tried to launch a live strategy from post optimizing yet. thankyou.
01/25/2022 at 7:14 AM #186527Hi Kev – It is nice to read your deliberations. They may urge for a “please be cautious”, which idea I already had after reading your first post. To me it may seem that you too easily take it for granted that you will gain some money with this, while virtually nobody does.
Run your strategies in Demo for many months … and you will see (?) that after two days you are not satisfied because something unexpected happens, so you will never reach those “many months”. However, it will be the representation of what would have happened in Live.but first i need to recoup the losses I have had in my first year of trading.
I sure hope that you don’t think that you will be able to do that with an AuoTrading algorithm. The device is to first be able to trade with profit, so from there you can try to automate your knowledge and profit (indeed) from staying away from emotions and/or utilise the response speed of that algorithm. I think everybody will tell you similar.
Might you need the money (which is not what I expect ;-)) then stay out of this all together.
If you don’t need the money then take all the time it takes for running all in Demo. Does it work there ? then go for it !01/25/2022 at 8:45 AM #186538If you don’t need the money then take all the time it takes for running all in Demo. Does it work there ? then go for it !
yes i am only running in demo at the moment because i do need the money 🙂 i spent enough money trading this year, so I am even manually trading in simulator while doing a funded trader challenge, so i wont be spending any more of my own money (besides subscribtion)
I am curious how do you feel about automating on 1 min time frame? I have been running some of my algos this year with mixed results but I find it hard to get many to stay consistently profitable for more than a fraction of the backtest period when they are made live.
I do have some automated systems that have managed to stay profitable but they are just ridiculously selective and they are trading on 5 min+ time frames.
I will be sticking to just letting them run on backtest in real time for now.
I have been thinking that maybe the way i should be using lower time frame algos is like a toolset, build a few for different market conditions and then select the one for the job on the day…. maybe i need to buy a book on the subject.
01/25/2022 at 9:58 AM #186554I am curious how do you feel about automating on 1 min time frame?
Well, I could be about the only one in this community using a 1 second TimeFrame, but which is Forex. Personally I wouldn’t even be able to use longer timeframes, just because I wouldn’t be able to find the entries (with Forex), which I now find by technical means. Otherwise, and as I told before, I try to work quite exactly the same as you, but as told that doesn’t work out mostly (my code is fully stuffed with all such attempts).
Otherwise, the advantage I seem to have is the fact (?) that the Strategies I have are winning, so all it requires is adding new ideas and see whether they work out for the better. This is the most convenient …And, without much exception you will find everybody in here having difficulties with the shorter timeframes; it was a discussion only a few weeks back.
I find it hard to get many to stay consistently profitable for more than a fraction of the backtest period when they are made live.
May it help you, or anyone, look at the below two backtest results in the 1st and 2nd attachment. The first one is from today, and the second one from two weeks or so ago. Time span is always one month.
Both earn about equally, but it will be clear that the first one looks better. Btw, yours looks as good (from your first post), so nothing wrong there or anywhere. However, what I did the past two weeks, was only smoothing out them peaks and dips by means of looking what actually happens and do something about it. Not a single optimisation step in there. Only applying stuff. Stuff that would minimise subsequent losses (easy to see the result of it). You can also see that this is not about more gain (your thinking ;-)) and it is at the cost of Risk/Reward (your thinking again).
For further reference I added the third screenshot;
Gain is about the same, and this is only until last week (so one day less of “trading”). Watch closely how the start of it looks (compare with the most current one – in the first attachment) and where an occurring gain ever back on the 22nd must be lacking today because the backtest now starts at the 24th. What many people won’t “see” is that the different starting point will imply a different trading sequence. And oh, it will sync along the way (could last a day or more), but the start will never be the same. Anyway … what the third attachment shows is that the gain is “topping” – and this is something I don’t like. So what happened (compare with the first attachment again) is that the peak you see on the 14th is actually traded off with more gain after it. And yes, it will be hard to believe that such things can be done, but this is how things work out when one sort of thinks like you do. The mechanism is always the attempt to diminish the subsequent losses (and it will be easy to understand how they will create the dips). That mechanism is just a workable one (I mean, one can deal with that) – as long as it does not go by optimisation. An easy to understand (and known) example is to skip a trade (coding such a thing may not be for everyone). Two losses after all ? then apply something else again.
The fun (for me) is that all is a tradeoff. Thus, I could stop trading for an hour as a solution to the above, but with 175-200 trades per month, you can do the math on how much profitable trades I will miss and that thus the net gain goes less because of that (hey, once you have that “known” winning strategy to begin with – only then). I like these “tensions” the best, as it is all technical stuff and the only instance which would be able to trade like that will be the computer.2 users thanked author for this post.
01/25/2022 at 10:19 AM #186564That’s a great explanation thankyou, it will take me some time to process and understand everything you have said. I really appreciate it.
-
AuthorPosts
Find exclusive trading pro-tools on