Thank you for code.
I found a little bit better result with:
- max size for stop loss
- different values for adxval and atrmin between morning and afternoon (US open time 2:30PM or 3:30pm).
Regards
Thanks a lot Noisette, what do you mean by max size for stop loss?
Sorry, I mean max value fo stop loss.
Try to add:
If pl > xxx then
Pl = xxx
Endif
Best value for xxx seems to be around 80~85 points.
Regards.
My WF analysis has been stucked by the 12 hours limitations .. I should consider reduce the variables values ranges..
Anyway, @Noisette, could you kindly post here your settings to discuss about? Thanks.
Hi Nicolas,
yes unfortunatley there are a few variables.
I can suggest this variable ranges:
ADXVAL [18:28, 2]
M,N,M1,N1 = [1:4,1]
k,y [3:10,1]
atrmin :[15:40,5]
timestart and timeend I think can be optimized later, they dont have a big impact.
Hope this help
@Francesco78 sorry for taking so long to respond, been very busy with work!
Yes I’ve been running the 30 min and 1hr on my live account and had good results, although I have to admit that I tend to close positions manually when they show a good profit… Although I also run the same systems on my demo account too.
As for the optimisation are those variables you posted recently the ones to optimise for? I am just trying to understand the logic of the system so I can play around with it, once the volatility has been determined does it simply enter at a multiple of the ATR? What made you think to try a system such as this?
Once again thanks a lot and great work! 🙂
Here the modified code:
- Different values morning vs afternoon
- Maximum value for stop loss
- Positions can be stopped later (20h instead of 17h30)
I think that we can add trailing stop (Nicolas code) to improve this code.
Regards.
// dax - IG MARKETS
// TIME FRAME 30min
// SPREAD 1.0 PIPS
DEFPARAM CumulateOrders = False
DEFPARAM FLATBEFORE = 070000
DEFPARAM FLATAFTER = 200000
ONCE POSITION =1
timestart = 080000
timeend = 173000
timeenterbefore = time <= timeend
timeenterafter = time >= timestart
//highvolume = average[30](volume)<=volume//
//lowvolume = average[30](volume)>=volume
adxperiod =15//15
atrperiod = 17//17
indicator1 = adx[adxperiod]
atr = AverageTrueRange[atrperiod]
//exitafternbars = 1
//// OPTIMIZED VARIABLES/////
K = 8 //8
Y = 3 //5
MAXPL = 80
AFTERNOON = 143000
IF TIME < AFTERNOON THEN
adxval = AA//20//20
atrmin = BB//27//19
m = 3 // high vol coefficient for mean reversion
n = 2 //high vol coefficient for breakout
Z = 1 //1.4
ELSE
adxval = CC//26//20
atrmin = DD//22//19
m = 3 // high vol coefficient for mean reversion
n = 2 //high vol coefficient for breakout
Z = 1 //0.8
ENDIF
m1 = m- Z //1 // low vol coefficient for mean reversion
n1 = n// low vol coefficient for breakout
pr = K*atr
pl = Y*atr
IF PL > MAXPL THEN
PLL = MAXPL
ELSE
PLL = PL
ENDIF
///////////////////////////////////////
lowvolenvironment = atr<atrmin //define lowvol environment use m1 and n1 as coefficient of movement
highvolenvironment = atr> atrmin //define highvol environment use m and n as coefficient of movement
meanrevertingenv = indicator1< adxval //define meanreverting environment
trendenv = indicator1 > adxval// define trendy environment
//////description of the possible combinations
sellhighvolmeanreverting = abs(open-close) > (atr*m) and close > open and meanrevertingenv and highvolenvironment
buyhighvolmeanreverting = abs(open-close) > (atr*m) and close < open and meanrevertingenv and highvolenvironment
buyhighvoltrendy = abs(open-close) > (atr*n) and close > open and close> DOPEN(1) and trendenv and highvolenvironment
sellhighvoltrendy = abs(open-close) > (atr*n) and close < open and close< DOPEN(1) and trendenv and highvolenvironment
selllowvolmeanreverting = abs(open-close) > (atr*m1) and close > open and meanrevertingenv and lowvolenvironment
buylowvolmeanreverting = abs(open-close) > (atr*m1) and close < open and meanrevertingenv and lowvolenvironment
buylowvoltrendy = abs(open-close) > (atr*n1) and close > open and trendenv and lowvolenvironment
selllowvoltrendy = abs(open-close) > (atr*n1) and close < open and trendenv and lowvolenvironment
////////////////////////////////////////////////////////
//long
IF (buyhighvolmeanreverting or buyhighvoltrendy or buylowvolmeanreverting or buylowvoltrendy ) and timeenterbefore and timeenterafter THEN
buy POSITION CONTRACTS AT MARKET
ENDIF
// short
IF (sellhighvolmeanreverting or sellhighvoltrendy or selllowvolmeanreverting or selllowvoltrendy) and timeenterbefore and timeenterafter THEN
sellshort POSITION CONTRACTS AT MARKET
ENDIF
IF TIME > TIMEEND AND LONGONMARKET AND (sellhighvolmeanreverting or sellhighvoltrendy or selllowvolmeanreverting or selllowvoltrendy) THEN
SELL AT MARKET
ENDIF
IF TIME > TIMEEND AND SHORTONMARKET AND (buyhighvolmeanreverting or buyhighvoltrendy or buylowvolmeanreverting or buylowvoltrendy ) THEN
EXITSHORT AT MARKET
ENDIF
@Francesco78
I ran a 5 iterations Walk Forward analysis yesterday (on 100k bars only) with the variables ranges you gave me (for the 30 minutes version), PFA the results. Even if the equity curve is not steady, the WF study is not so “critical”. Remember that in its current state, the WF tool only give the result of the most profitable OOS settings at the end, it doesn’t mean that other settings wouldn’t have made a more “steady” curve..
Thank you very much Noisette will have a look this afternoon.
Thanks Nicolas for your time spent on the code. Just for my info can you tell me which version of the code you used for the wf? Thanks again
I used this one:
// dax - IG MARKETS
// TIME FRAME 30min
// SPREAD 1.0 PIPS
DEFPARAM CumulateOrders = False
timestart = 080000
timeend = 200000
timeenterbefore = time <= timeend
timeenterafter = time >= timestart
adxperiod = 14
atrperiod = 14
myADX = adx[adxperiod]
atr = AverageTrueRange[atrperiod]
//// OPTIMIZED VARIABLES/////
profitCoeff = 8
lossCoeff = 5
myprofit = profitCoeff*atr
myloss = lossCoeff*atr
//adxval = 20
//atrmin = 19
m = 3 // high vol coefficient for mean reversion
n = 2 //high vol coefficient for breakout
m1 = m-1 // low vol coefficient for mean reversion
n1 = n // low vol coefficient for breakout
///////////////////////////////////////
positionlong = 1 // define sixe of long trades
positionshort = 1 // define size of short trade
lowvolenvironment = atr < atrmin //define lowvol environment use m1 and n1 as coefficient of movement
highvolenvironment = atr > atrmin //define highvol environment use m and n as coefficient of movement
meanrevertingenv = myADX < adxval //define meanreverting environment
trendenv = myADX > adxval // define trendy environment
//////description of the possible combinations
//mean reverting
sellhighvolmeanreverting = abs(open-close) > (atr*m) and close > open and meanrevertingenv and highvolenvironment
buyhighvolmeanreverting = abs(open-close) > (atr*m) and close < open and meanrevertingenv and highvolenvironment
selllowvolmeanreverting = abs(open-close) > (atr*m1) and close > open and meanrevertingenv and lowvolenvironment
buylowvolmeanreverting = abs(open-close) > (atr*m1) and close < open and meanrevertingenv and lowvolenvironment
//trend following
buyhighvoltrendy = abs(open-close) > (atr*n) and close > open and close> DOPEN(1) and trendenv and highvolenvironment
sellhighvoltrendy = abs(open-close) > (atr*n) and close < open and close< DOPEN(1) and trendenv and highvolenvironment
buylowvoltrendy = abs(open-close) > (atr*n1) and close > open and trendenv and lowvolenvironment
selllowvoltrendy = abs(open-close) > (atr*n1) and close < open and trendenv and lowvolenvironment
////////////////////////////////////////////////////////
//long
IF (buyhighvolmeanreverting or buyhighvoltrendy or buylowvolmeanreverting or buylowvoltrendy ) and timeenterbefore and timeenterafter THEN
buy positionlong CONTRACTS AT MARKET
ENDIF
if longonmarket and time = timeend then
sell at market
endif
// short
IF (sellhighvolmeanreverting or sellhighvoltrendy or selllowvolmeanreverting or selllowvoltrendy) and timeenterbefore and timeenterafter THEN
sellshort positionshort CONTRACTS AT MARKET
endif
if shortonmarket and time = timeend then
exitshort at market
endif
set target pprofit myprofit
set stop ploss myloss
Noisette, I cant run it, can you make a version with only the relevant variables?
THanks a lot
Ok, I’ll post itf file tonight.
Please also note that conditions from line 79 to the end don’t modify results if you suppress them.
Regards.
Herewith the code without the last line of the code that don’t improve strategy.
kg6450
Sorry for the late reply.
As for the optimisation are those variables you posted recently the ones to optimise for?
yes that’s correct
I am just trying to understand the logic of the system so I can play around with it, once the volatility has been determined does it simply enter at a multiple of the ATR?
yes that’s correct, ATR is the measure of volatility that I like to use in my codes
What made you think to try a system such as this?
Honestly in this case is just logic, I wanted to create a system that could work on both mean reverting and trendy market so I just split my scenario in 2 parts depending on the ADX indicator that measure the trendiness of the market. As far as the ATR, I think in general it is very useful to smoothen the curve when you define your position size as inverse function of the ATR, so the system will automatically reduce the position in case of high volatility and viceversa.