Wanted: small code snippet for reinvestment
Forums › ProRealTime English forum › ProOrder support › Wanted: small code snippet for reinvestment
- This topic has 68 replies, 7 voices, and was last updated 7 years ago by Nicolas.
-
-
12/31/2017 at 11:25 AM #56939
Hello.
Who can help out with a surely simple code?
The following strategy is to be extended by a re-investment strategy in the sense, so that
the size of the position changes based on the initial capital.capital = 10000
for Trade 1
Position = capital/capital
for all following trades
if capital (new) <= 10000 then
position = 1
if capital (new) >10000 then
position = capital (new) / 10000How can integrate this in the maincode?
Attached the maincode
Dax DailyOpenLong123456789101112131415161718192021222324252627282930313233343536373839404142// MainCode : DailyOpenlong// Dax 1 Euro// TimeFrame4H// created by JohnScher//..............................................................// maincode//..............................................................defparam cumulateorders = falseposition = 1TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5TradingtimeLong = time = 090000 //or time = 130000 or time = 170000c1 = TR (close) > 25c2 = TEMA [4] (close) > ExponentialAverage [4] (close)IF TradingDayLong and TradingTimeLong ThenIf c1 and c2 THENbuy position CONTRACT AT MARKETEndifENDIF// set stop lossIF time = 090000 or time = 130000 or time = 170000 or time = 210000 thenIf Repulse[3](close)< -0.3 Thensell at marketEndifENDIF// set target profitset target %profit 3//..............................................................// end maincode12/31/2017 at 11:55 AM #5694712/31/2017 at 12:00 PM #5694812/31/2017 at 12:09 PM #5694912/31/2017 at 12:20 PM #56953the same code without Re-Invest but with SaisonalPatternMultiplier from Pathfinder-Systems
Dax DailyOpenLong with PF123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152// MainCode : DailyOpenlong// Dax 1 Euro// TimeFrame4H// created by JohnScher// with SaisonalPatternMultiplier from Pathfinder-Systems//..............................................................// maincode//..............................................................defparam cumulateorders = false// begin Pathfinder MultiplierONCE January1 = 3 //0 risk(3)ONCE January2 = 0 //3 okONCE February1 = 3 //3 okONCE February2 = 3 //0 risk(3)ONCE March1 = 3 //0 risk(3)ONCE March2 = 2 //3 okONCE April1 = 3 //3 okONCE April2 = 3 //3 okONCE May1 = 1 //0 risk(1)ONCE May2 = 1 //0 risk(1)ONCE June1 = 1 //1 ok 2ONCE June2 = 2 //3 okONCE July1 = 3 //1 chanceONCE July2 = 2 //3 okONCE August1 = 2 //1 chance 1ONCE August2 = 3 //3 okONCE September1 = 3 //0 risk(3)ONCE September2 = 0 //0 okONCE October1 = 3 //0 risk(3)ONCE October2 = 2 //3 okONCE November1 = 1 //1 okONCE November2 = 3 //3 okONCE December1 = 3 // 1 chanceONCE December2 = 2 //3 ok// set saisonal multipliercurrentDayOfTheMonth = DaymidOfMonth = 15IF CurrentMonth = 1 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = January1ELSEsaisonalPatternMultiplier = January2ENDIFELSIF CurrentMonth = 2 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = February1ELSEsaisonalPatternMultiplier = February2ENDIFELSIF CurrentMonth = 3 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = March1ELSEsaisonalPatternMultiplier = March2ENDIFELSIF CurrentMonth = 4 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = April1ELSEsaisonalPatternMultiplier = April2ENDIFELSIF CurrentMonth = 5 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = May1ELSEsaisonalPatternMultiplier = May2ENDIFELSIF CurrentMonth = 6 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = June1ELSEsaisonalPatternMultiplier = June2ENDIFELSIF CurrentMonth = 7 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = July1ELSEsaisonalPatternMultiplier = July2ENDIFELSIF CurrentMonth = 8 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = August1ELSEsaisonalPatternMultiplier = August2ENDIFELSIF CurrentMonth = 9 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = September1ELSEsaisonalPatternMultiplier = September2ENDIFELSIF CurrentMonth = 10 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = October1ELSEsaisonalPatternMultiplier = October2ENDIFELSIF CurrentMonth = 11 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = November1ELSEsaisonalPatternMultiplier = November2ENDIFELSIF CurrentMonth = 12 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = December1ELSEsaisonalPatternMultiplier = December2ENDIFEndif// end Pathfinder Multiplier// start maincodeposition = 1TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5TradingtimeLong = time = 090000 //or time = 130000 or time = 170000c1 = TR (close) > 25c2 = TEMA [4] (close) > ExponentialAverage [4] (close)IF TradingDayLong and TradingTimeLong ThenIf c1 and c2 THENbuy position*saisonalpatternmultiplier CONTRACT AT MARKETEndifENDIF// set stop lossIF time = 090000 or time = 130000 or time = 170000 or time = 210000 thenIf Repulse[3](close)< -0.3 Thensell at marketEndifENDIF// set target profitset target %profit 3//..............................................................// end maincode// endkind regards an thanks to vonasi
12/31/2017 at 12:24 PM #56955at 01.01.17 the programm will run in demo and live for 1 year, after that 1 will post results
i will add
insurance1set stop %loss 5%for insurance against all damage, e. g. an exploding nuclear power plant or something the likes
12/31/2017 at 12:32 PM #56956No problem. your strategy kicks straight into profit and never dips into a loss so the re-investment snippet never gets the opportunity to reduce the position size to 1 in reality.
Interesting strategy – thanks for sharing it. I find myself writing a lot of long only strategies on the DAX 4 hour at the moment and they all seem to be easy to make profitable and all back test and walk forward test OK which leaves me with a slight sense of ‘it all seems too good to be true’. I hope I am wrong.
12/31/2017 at 12:44 PM #56957I notice that your test results are on the 4 hour chart but you have entry/exit criteria set on times that cannot be achieved in a 4 hour chart.
1IF time = 090000 or time = 130000 or time = 170000 or time = 210000 thenDid you use different times than the ones posted on here?
12/31/2017 at 12:57 PM #56961Just for interest I sometimes use this for position sizing.
12345Capital = 10000Equity = Capital + StrategyProfitPosition = Max(1, Equity * (1/Capital))Position = Round(Position*100)Position = Position/100It starts with a position size of one and increases position size as equity increases and reduces it as equity decreases. It protects your capital better at the expense of overall profit. The last two lines are to ensure that decimal sizes work live on IG. The only downside to this if you start with a small capital as it sticks with the same % of equity so a starting stake of 1 with capital of 5000 is 2% per position as opposed to the 1% with starting capital of 10000.
12/31/2017 at 1:25 PM #56963Out of interest I just did a quick comparison of true returns comparing the strategy with seasonal adjustment to the one without. I set position size to 1 and then in the seasonally adjusted strategy I totalled up the total amount staked and then divided it by the number of bets and then divided the amount won by this to be able to compare apples with apples. Interestingly the seasonally adjusted strategy added 15.7% to profits. For me the only downside of this is the increase in initial position size from 1 to an average of 2.75 meaning that the losses can be pretty big ones – on the bright side the winners are too but you need a good bank size and a strong heart to run it live starting with such big stake sizes.
12/31/2017 at 1:25 PM #56964Hello again.
I wasn’t really so concerned with the strategy presented here. Rather, coding the re-investment caused me problems, somehow I didn’t quite get through it. Now, however, I have one of you here. With it I will now be able to examine my other strategies to see whether it is worthwhile to use the Re-Invest.
The Dax DailyOpenLong strategy presented here is thus a benefit for the Re-Invest coder and, of course, for the PRT community.
Thanks to all of you!Kind regards
JohnScherTranslated with http://www.DeepL.com/Translator
12/31/2017 at 2:50 PM #56971Hello again JohnScher. Your code has interested me and I have been trying a few things out. You might want to change your entry criteria to include a third one.
123456789c1 = TR (close) > 25c2 = TEMA[4](close) > ExponentialAverage[4](close)c3 = Repulse[3](close) > 0.3IF TradingDayLong and TradingTimeLong ThenIf c1 and c2 and c3 THENbuy position CONTRACT AT MARKETEndifENDIFThis stops entries that can quickly be closed out if Repulse is too close. Improves win rate and profitability. Hope this helps.
12/31/2017 at 4:08 PM #56975Another possibility if running the seasonal adjustment on a small starting bank is to only allow the seasonal adjustment to be added if funds allow.
1234567891011IF (Your Conditions) THENEquity = Capital + StrategyProfitPosition = Max(1, Equity * (1/Capital))Position = Position * saisonalpatternmultiplierPosition = Round(Position*100)Position = Position/100IF Position > Equity * 0.0001 THENPosition = 1ENDIFBuy Position Contracts AT MarketENDIF01/03/2018 at 4:18 PM #57145I would never have made it without you.
see it https://www.prorealcode.com/library/
my first publication here in the library
Thanks so lot !!
01/03/2018 at 4:56 PM #57152No problem JohnScher. You did all the hardwork and testing!
I’m running this slightly adjusted version with a third entry condition (as suggested above) that gives some differential to the Repulse exit conditions so that an entry is not made if Repulse is too close to the exit criteria. It gave me a better win rate and higher profit over your version posted above.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148//-------------------------------------------------------------------------// Main code : Daily Open Long with Season//-------------------------------------------------------------------------// MainCode : DailyOpenlong// Dax 1 Euro// TimeFrame4H// created by JohnScher// with SaisonalPatternMultiplier from Pathfinder-SystemsDEFPARAM cumulateorders = false// begin Pathfinder MultiplierONCE January1 = 3 //0 risk(3)ONCE January2 = 0 //3 okONCE February1 = 3 //3 okONCE February2 = 3 //0 risk(3)ONCE March1 = 3 //0 risk(3)ONCE March2 = 2 //3 okONCE April1 = 3 //3 okONCE April2 = 3 //3 okONCE May1 = 1 //0 risk(1)ONCE May2 = 1 //0 risk(1)ONCE June1 = 1 //1 ok 2ONCE June2 = 2 //3 okONCE July1 = 3 //1 chanceONCE July2 = 2 //3 okONCE August1 = 2 //1 chance 1ONCE August2 = 3 //3 okONCE September1 = 3 //0 risk(3)ONCE September2 = 0 //0 okONCE October1 = 3 //0 risk(3)ONCE October2 = 2 //3 okONCE November1 = 1 //1 okONCE November2 = 3 //3 okONCE December1 = 3 // 1 chanceONCE December2 = 2 //3 ok// set saisonal multipliercurrentDayOfTheMonth = DaymidOfMonth = 15IF CurrentMonth = 1 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = January1ELSEsaisonalPatternMultiplier = January2ENDIFELSIF CurrentMonth = 2 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = February1ELSEsaisonalPatternMultiplier = February2ENDIFELSIF CurrentMonth = 3 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = March1ELSEsaisonalPatternMultiplier = March2ENDIFELSIF CurrentMonth = 4 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = April1ELSEsaisonalPatternMultiplier = April2ENDIFELSIF CurrentMonth = 5 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = May1ELSEsaisonalPatternMultiplier = May2ENDIFELSIF CurrentMonth = 6 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = June1ELSEsaisonalPatternMultiplier = June2ENDIFELSIF CurrentMonth = 7 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = July1ELSEsaisonalPatternMultiplier = July2ENDIFELSIF CurrentMonth = 8 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = August1ELSEsaisonalPatternMultiplier = August2ENDIFELSIF CurrentMonth = 9 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = September1ELSEsaisonalPatternMultiplier = September2ENDIFELSIF CurrentMonth = 10 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = October1ELSEsaisonalPatternMultiplier = October2ENDIFELSIF CurrentMonth = 11 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = November1ELSEsaisonalPatternMultiplier = November2ENDIFELSIF CurrentMonth = 12 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = December1ELSEsaisonalPatternMultiplier = December2ENDIFEndif// end Pathfinder Multiplier// start maincodeCapital = 10000Equity = Capital + StrategyProfitPosition = Max(1, Equity * (1/Capital))Position = Round(Position*100)Position = Position/100//Position = 1TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5TradingtimeLong = time = 080000 //or time = 130000 or time = 170000c1 = TR (close) > 25c2 = TEMA [4] (close) > ExponentialAverage [4] (close)c3 = Repulse[3](close) > 0.3IF TradingDayLong and TradingTimeLong ThenIf c1 and c2 and c3 THENbuy position*saisonalpatternmultiplier CONTRACT AT MARKETENDIFENDIF// set stop lossIF time = 080000 or time = 120000 or time = 160000 or time = 200000 thenIf Repulse[3](close) < -0.3 Thensell at marketEndifENDIF// set target profitset target %profit 3set stop %loss 5 -
AuthorPosts