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) / 10000
How can integrate this in the maincode?
Attached the maincode
// MainCode : DailyOpenlong
// Dax 1 Euro
// TimeFrame4H
// created by JohnScher
//..............................................................
// maincode
//..............................................................
defparam cumulateorders = false
position = 1
TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5
TradingtimeLong = time = 090000 //or time = 130000 or time = 170000
c1 = TR (close) > 25
c2 = TEMA [4] (close) > ExponentialAverage [4] (close)
IF TradingDayLong and TradingTimeLong Then
If c1 and c2 THEN
buy position CONTRACT AT MARKET
Endif
ENDIF
// set stop loss
IF time = 090000 or time = 130000 or time = 170000 or time = 210000 then
If Repulse[3](close)< -0.3 Then
sell at market
Endif
ENDIF
// set target profit
set target %profit 3
//..............................................................
// end maincode
Capital = 10000
Equity = Capital + StrategyProfit
Position = Max(1,Equity/Capital)
the same code without Re-Invest but with SaisonalPatternMultiplier from Pathfinder-Systems
// MainCode : DailyOpenlong
// Dax 1 Euro
// TimeFrame4H
// created by JohnScher
// with SaisonalPatternMultiplier from Pathfinder-Systems
//..............................................................
// maincode
//..............................................................
defparam cumulateorders = false
// begin Pathfinder Multiplier
ONCE January1 = 3 //0 risk(3)
ONCE January2 = 0 //3 ok
ONCE February1 = 3 //3 ok
ONCE February2 = 3 //0 risk(3)
ONCE March1 = 3 //0 risk(3)
ONCE March2 = 2 //3 ok
ONCE April1 = 3 //3 ok
ONCE April2 = 3 //3 ok
ONCE May1 = 1 //0 risk(1)
ONCE May2 = 1 //0 risk(1)
ONCE June1 = 1 //1 ok 2
ONCE June2 = 2 //3 ok
ONCE July1 = 3 //1 chance
ONCE July2 = 2 //3 ok
ONCE August1 = 2 //1 chance 1
ONCE August2 = 3 //3 ok
ONCE September1 = 3 //0 risk(3)
ONCE September2 = 0 //0 ok
ONCE October1 = 3 //0 risk(3)
ONCE October2 = 2 //3 ok
ONCE November1 = 1 //1 ok
ONCE November2 = 3 //3 ok
ONCE December1 = 3 // 1 chance
ONCE December2 = 2 //3 ok
// set saisonal multiplier
currentDayOfTheMonth = Day
midOfMonth = 15
IF CurrentMonth = 1 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = January1
ELSE
saisonalPatternMultiplier = January2
ENDIF
ELSIF CurrentMonth = 2 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = February1
ELSE
saisonalPatternMultiplier = February2
ENDIF
ELSIF CurrentMonth = 3 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = March1
ELSE
saisonalPatternMultiplier = March2
ENDIF
ELSIF CurrentMonth = 4 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = April1
ELSE
saisonalPatternMultiplier = April2
ENDIF
ELSIF CurrentMonth = 5 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = May1
ELSE
saisonalPatternMultiplier = May2
ENDIF
ELSIF CurrentMonth = 6 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = June1
ELSE
saisonalPatternMultiplier = June2
ENDIF
ELSIF CurrentMonth = 7 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = July1
ELSE
saisonalPatternMultiplier = July2
ENDIF
ELSIF CurrentMonth = 8 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = August1
ELSE
saisonalPatternMultiplier = August2
ENDIF
ELSIF CurrentMonth = 9 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = September1
ELSE
saisonalPatternMultiplier = September2
ENDIF
ELSIF CurrentMonth = 10 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = October1
ELSE
saisonalPatternMultiplier = October2
ENDIF
ELSIF CurrentMonth = 11 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = November1
ELSE
saisonalPatternMultiplier = November2
ENDIF
ELSIF CurrentMonth = 12 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = December1
ELSE
saisonalPatternMultiplier = December2
ENDIF
Endif
// end Pathfinder Multiplier
// start maincode
position = 1
TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5
TradingtimeLong = time = 090000 //or time = 130000 or time = 170000
c1 = TR (close) > 25
c2 = TEMA [4] (close) > ExponentialAverage [4] (close)
IF TradingDayLong and TradingTimeLong Then
If c1 and c2 THEN
buy position*saisonalpatternmultiplier CONTRACT AT MARKET
Endif
ENDIF
// set stop loss
IF time = 090000 or time = 130000 or time = 170000 or time = 210000 then
If Repulse[3](close)< -0.3 Then
sell at market
Endif
ENDIF
// set target profit
set target %profit 3
//..............................................................
// end maincode
// end
kind regards an thanks to vonasi
at 01.01.17 the programm will run in demo and live for 1 year, after that 1 will post results
i will add
set stop %loss 5%
for insurance against all damage, e. g. an exploding nuclear power plant or something the likes
No 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.
I 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.
IF time = 090000 or time = 130000 or time = 170000 or time = 210000 then
Did you use different times than the ones posted on here?
Just for interest I sometimes use this for position sizing.
Capital = 10000
Equity = Capital + StrategyProfit
Position = Max(1, Equity * (1/Capital))
Position = Round(Position*100)
Position = Position/100
It 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.
Out 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.
Hello 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
JohnScher
Translated with http://www.DeepL.com/Translator
Hello 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.
c1 = TR (close) > 25
c2 = TEMA[4](close) > ExponentialAverage[4](close)
c3 = Repulse[3](close) > 0.3
IF TradingDayLong and TradingTimeLong Then
If c1 and c2 and c3 THEN
buy position CONTRACT AT MARKET
Endif
ENDIF
This stops entries that can quickly be closed out if Repulse is too close. Improves win rate and profitability. Hope this helps.
Another possibility if running the seasonal adjustment on a small starting bank is to only allow the seasonal adjustment to be added if funds allow.
IF (Your Conditions) THEN
Equity = Capital + StrategyProfit
Position = Max(1, Equity * (1/Capital))
Position = Position * saisonalpatternmultiplier
Position = Round(Position*100)
Position = Position/100
IF Position > Equity * 0.0001 THEN
Position = 1
ENDIF
Buy Position Contracts AT Market
ENDIF
@vonasi
I would never have made it without you.
see it https://www.prorealcode.com/library/
my first publication here in the library
Thanks so lot !!
No 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.
//-------------------------------------------------------------------------
// Main code : Daily Open Long with Season
//-------------------------------------------------------------------------
// MainCode : DailyOpenlong
// Dax 1 Euro
// TimeFrame4H
// created by JohnScher
// with SaisonalPatternMultiplier from Pathfinder-Systems
DEFPARAM cumulateorders = false
// begin Pathfinder Multiplier
ONCE January1 = 3 //0 risk(3)
ONCE January2 = 0 //3 ok
ONCE February1 = 3 //3 ok
ONCE February2 = 3 //0 risk(3)
ONCE March1 = 3 //0 risk(3)
ONCE March2 = 2 //3 ok
ONCE April1 = 3 //3 ok
ONCE April2 = 3 //3 ok
ONCE May1 = 1 //0 risk(1)
ONCE May2 = 1 //0 risk(1)
ONCE June1 = 1 //1 ok 2
ONCE June2 = 2 //3 ok
ONCE July1 = 3 //1 chance
ONCE July2 = 2 //3 ok
ONCE August1 = 2 //1 chance 1
ONCE August2 = 3 //3 ok
ONCE September1 = 3 //0 risk(3)
ONCE September2 = 0 //0 ok
ONCE October1 = 3 //0 risk(3)
ONCE October2 = 2 //3 ok
ONCE November1 = 1 //1 ok
ONCE November2 = 3 //3 ok
ONCE December1 = 3 // 1 chance
ONCE December2 = 2 //3 ok
// set saisonal multiplier
currentDayOfTheMonth = Day
midOfMonth = 15
IF CurrentMonth = 1 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = January1
ELSE
saisonalPatternMultiplier = January2
ENDIF
ELSIF CurrentMonth = 2 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = February1
ELSE
saisonalPatternMultiplier = February2
ENDIF
ELSIF CurrentMonth = 3 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = March1
ELSE
saisonalPatternMultiplier = March2
ENDIF
ELSIF CurrentMonth = 4 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = April1
ELSE
saisonalPatternMultiplier = April2
ENDIF
ELSIF CurrentMonth = 5 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = May1
ELSE
saisonalPatternMultiplier = May2
ENDIF
ELSIF CurrentMonth = 6 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = June1
ELSE
saisonalPatternMultiplier = June2
ENDIF
ELSIF CurrentMonth = 7 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = July1
ELSE
saisonalPatternMultiplier = July2
ENDIF
ELSIF CurrentMonth = 8 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = August1
ELSE
saisonalPatternMultiplier = August2
ENDIF
ELSIF CurrentMonth = 9 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = September1
ELSE
saisonalPatternMultiplier = September2
ENDIF
ELSIF CurrentMonth = 10 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = October1
ELSE
saisonalPatternMultiplier = October2
ENDIF
ELSIF CurrentMonth = 11 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = November1
ELSE
saisonalPatternMultiplier = November2
ENDIF
ELSIF CurrentMonth = 12 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = December1
ELSE
saisonalPatternMultiplier = December2
ENDIF
Endif
// end Pathfinder Multiplier
// start maincode
Capital = 10000
Equity = Capital + StrategyProfit
Position = Max(1, Equity * (1/Capital))
Position = Round(Position*100)
Position = Position/100
//Position = 1
TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayofweek = 5
TradingtimeLong = time = 080000 //or time = 130000 or time = 170000
c1 = TR (close) > 25
c2 = TEMA [4] (close) > ExponentialAverage [4] (close)
c3 = Repulse[3](close) > 0.3
IF TradingDayLong and TradingTimeLong Then
If c1 and c2 and c3 THEN
buy position*saisonalpatternmultiplier CONTRACT AT MARKET
ENDIF
ENDIF
// set stop loss
IF time = 080000 or time = 120000 or time = 160000 or time = 200000 then
If Repulse[3](close) < -0.3 Then
sell at market
Endif
ENDIF
// set target profit
set target %profit 3
set stop %loss 5