Hello, this week was very bad for 5.5l in the short market in live mode. One should perhaps stick to a long and short variant. I am testing the 1min NAS 7.5 again, in any case 5.5l does not work if the market turns short in the long term, which is starting soon or is already there. nice weekend
this week was very bad for 5.5l
Hi, the “L” of V5.5L is for “Long” trade. So it means it’s a good code for long trade only. You can backtest it to observe the results for short and long rates.
Hello, yes i know it’s very good code. I just wanted to say that when the market goes short, what I think will happen soon, the code shouldn’t be used anymore. If you switch the code to long and short, short runs at a loss. Maybe someone has an idea how to get this under control?
Here’s the itf
Hello Noetheless,
I would like to know how you manage the optimization of a code. I mean you can’t walk forward all variable same time with large min / max variable so i would like to know how you manage it.
Thanks
I optimize 2 or 3 variables at a time, at first with large steps for a rough cut, then finer steps once I know what the range is going to be. Or I’ll do 4 – 6 at once, around 3000 iterations and let it run overnight.
I would usually do a rough cut on 100% of data so I can see and compare the results, but I don’t always take the top line (highest gain). If profit is similar I’d rather have a higher % win of more trades, or lower drawdown. Then I run a 70/30 WF with finer steps.
Hope this helps!
Thanks for your answer,
What about when there are MTF ? Do you test lower TF and add higher TF step by step ? There are often too much variables with these sorts of code.
What is “WF” in : Then I run a 70/30 WF with finer steps.
You use 100% data so you mean 1M barres ?
Thanks, it helps a lot in the way to test codes
Thanks for your answers 🙂
Good morning everyone,
I am running NAS Hull SAR v5.5L in demo and I’ve noticed that it opened positions on may 5th and 6th, but when the positions became positive enough to activate de TS, it did not trigger so I stopped the orders manually, did someone have the same issue?
Moreover, I also tried to BT and it does not return any operation since april 6th (see image attached), does someone have an explanation for that? I also try to BT 10k bars and PRT says its out of date and does not perform the BT.
Thanks everyone in advance!
Same here, somehow it changed some variables values when going from backtest into preparation for auto trading. Look at “tss”, mine was set at 3.2 instead of 0.2
In my case tss variable was correctly set at 0.2. Do you also have the same issue with the BT since april 6th?
tss = trailingpercentshort
as this is running long only, it’s irrelevant.
Hiya everyone, today the system opened a position without setting stop loss/take profit. I’m trying to figure out why but am quite clueless.
/ Main code : NAS 2m HULL-SAR v5.5 L
//-------------------------------------------------------------------------
// Definition of code parameters
DEFPARAM CumulateOrders = true // Cumulating positions activated
DEFPARAM preloadbars = 5000
//Money Management NAS
MM = 1 // = 0 for optimization
if MM = 0 then
positionsize= 1
ENDIF
ONCE acc = 0.028
ONCE acc2 = 0.022
ONCE e = 0.025
ONCE e1 = 0.02
ONCE e2 = 0.02
ONCE f = 8
ONCE lr = 5.0
ONCE ls = 4.0
ONCE mp = 5.0
ONCE p1 = 170.0
ONCE p2 = 17.0
ONCE p3 = 5.0
ONCE pm = 2.0
ONCE q = 0.01
ONCE q1 = 0.025
ONCE q2 = 0.005
ONCE sd = 2.0
ONCE sk = 8.0
ONCE sl = 1.6
ONCE tp = 2.3
ONCE tss = 0.2
ONCE tst = 0.29
ONCE w = 0.015
ONCE w1 = 0.005
ONCE w2 = 0.005
if MM = 1 then
ONCE startpositionsize = 0.5
ONCE factor = f // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE margin = (close*.05) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.05)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 200 // IG first tier margin limit
ONCE maxpositionsize = 2000 // IG tier 2 margin limit
ONCE minpositionsize = 0.5 // enter minimum position allowed
IF StrategyProfit <> StrategyProfit[1] THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF StrategyProfit <> StrategyProfit[1] THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF StrategyProfit <> StrategyProfit[1] THEN
if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
once tradetype = 2 // [1] long/short [2]long [3]short
once closeonreversal = 0 // active when tradetype=2 or tradetype=3
MaxPos = (pm*positionsize)
MaxPos2 = (mp*positionsize)
Ctime = time >=143000 and time <210000//UK time
//Ctime = time >=153000 and time <220000//Euro time
TIMEFRAME(12 minutes)
Perioda= p1
innera = 2*weightedaverage[round( Perioda/2)](typicalprice)-weightedaverage[Perioda](typicalprice)
HULLa = weightedaverage[round(sqrt(Perioda))](innera)
c1 = HULLa > HULLa[1]
c2 = HULLa < HULLa[1]
ST1 = SAR[q,w,e]
c1a = (close > ST1)
c2a = (close < ST1)
TIMEFRAME(6 minutes)
Periodb= p2
innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
c3 = HULLb > HULLb[1]
c4 = HULLb < HULLb[1]
c3b = HULLb > HULLb[1] and HULLb[1] < HULLb[2]
c4b = HULLb < HULLb[1] and HULLb[1] > HULLb[2]
ST2 = SAR[q1,w1,e1]
c3a = (close > ST2)
c4a = (close < ST2)
//Stochastic RSI | indicator
lengthRSI = lr //RSI period
lengthStoch = ls //Stochastic period
smoothK = sk //Smooth signal of stochastic RSI
smoothD = sd //Smooth signal of smoothed stochastic RSI
myRSI = RSI[lengthRSI](close)
MinRSI = lowest[lengthStoch](myrsi)
MaxRSI = highest[lengthStoch](myrsi)
StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)
K = average[smoothK](stochrsi)*100
D = average[smoothD](K)
c3c = K>D
c4c = K<D
TIMEFRAME(default)
Periodc= p3
innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
c5 = HULLc > HULLc[1] and HULLc[1] < HULLc[2]
c6 = HULLc < HULLc[1] and HULLc[1] > HULLc[2]
c5b = HULLc > HULLc[1]
c6b = HULLc < HULLc[1]
ST3 = SAR[q2,w2,e2]
c5a = (close > ST3)
c6a = (close < ST3)
CB = Ctime and c1 and c1a AND C3a and c3b and c3c AND C5a and c5b
CB2 = c1 and c1a and c3 and c3a and c5 AND C5a
CS = Ctime and c2 and c2a AND C4a and c4b and c4c AND C6a and c6
CS2 = c2 and c2a and c4 and c4a and c6 AND C6a
IF Not OnMarket THEN
Flag = 1
Flag1 = 1
Flag2 = 1
Flag3 = 1
ENDIF
// Conditions to enter long positions
if tradetype=1 or tradetype=2 then
IF not longonmarket and CB and Flag THEN
BUY positionsize CONTRACT AT MARKET
elsif Ctime and longonmarket and CB2 and COUNTOFLONGSHARES < MaxPos and Flag then
BUY positionsize CONTRACT AT MARKET
Flag = 0
elsif longonmarket and CB2 and positionperf <0 and COUNTOFLONGSHARES < MaxPos2 and Flag1 then
BUY positionsize CONTRACT AT MARKET
Flag1 = 0
elsif longonmarket and CB2 and positionperf <0 and COUNTOFLONGSHARES < MaxPos2 and Flag2 then
BUY positionsize CONTRACT AT MARKET
Flag2 = 0
elsif longonmarket and CB2 and positionperf <0 and COUNTOFLONGSHARES < MaxPos2 and Flag3 then
BUY positionsize CONTRACT AT MARKET
Flag3 = 0
SET STOP %LOSS sl
SET TARGET %PROFIT tp
ENDIF
ENDIF
if closeonreversal and tradetype=2 and CS then
sell at market
endif
// Conditions to enter short positions
if tradetype=1 or tradetype=3 then
IF not shortonmarket and CS THEN
sellshort positionsize CONTRACT AT MARKET
elsif Ctime and shortonmarket and CS2 and COUNTOFSHORTSHARES < MaxPos then
sellshort positionsize CONTRACT AT MARKET
SET STOP %LOSS 0.6
SET TARGET %PROFIT 2.3
ENDIF
ENDIF
// %trailing stop function incl. cumulative positions
once trailingstoptype1= 1
if trailingstoptype1 then
//====================
trailingpercentlong = tst // %
trailingpercentshort = tss // %
once acceleratorlong = acc // [1] default; always > 0 (i.e. 0.5-3)
once acceleratorshort= acc2 // 1 = default; always > 0 (i.e. 0.5-3)
ts2sensitivity = 2 // 1 = close 2 = High/Low 3 = Low/High 4 = typicalprice (not use once)
//====================
once steppercentlong = (trailingpercentlong/10)*acceleratorlong
once steppercentshort = (trailingpercentshort/10)*acceleratorshort
if onmarket then
trailingstartlong = positionprice*(trailingpercentlong/100)
trailingstartshort = positionprice*(trailingpercentshort/100)
trailingsteplong = positionprice*(steppercentlong/100)
trailingstepshort = positionprice*(steppercentshort/100)
endif
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
newsl = 0
mypositionprice = 0
endif
positioncount = abs(countofposition)
if newsl > 0 then
if positioncount > positioncount[1] then
if longonmarket then
newsl = max(newsl,positionprice * newsl / mypositionprice)
else
newsl = min(newsl,positionprice * newsl / mypositionprice)
endif
endif
endif
if ts2sensitivity=1 then
ts2sensitivitylong=close
ts2sensitivityshort=close
elsif ts2sensitivity=2 then
ts2sensitivitylong=high
ts2sensitivityshort=low
elsif ts2sensitivity=3 then
ts2sensitivitylong=low
ts2sensitivityshort=high
elsif ts2sensitivity=4 then
ts2sensitivitylong=typicalprice
ts2sensitivityshort=typicalprice
endif
if longonmarket then
if newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong*pipsize then
newsl = positionprice+trailingsteplong*pipsize
endif
if newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong*pipsize then
newsl = newsl+trailingsteplong*pipsize
endif
endif
if shortonmarket then
if newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort*pipsize then
newsl = positionprice-trailingstepshort*pipsize
endif
if newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort*pipsize then
newsl = newsl-trailingstepshort*pipsize
endif
endif
if barindex-tradeindex>1 then
if longonmarket then
if newsl>0 then
sell at newsl stop
endif
if newsl>0 then
if low crosses under newsl then
sell at market
endif
endif
endif
if shortonmarket then
if newsl>0 then
exitshort at newsl stop
endif
if newsl>0 then
if high crosses over newsl then
exitshort at market
endif
endif
endif
endif
mypositionprice = positionprice
endif
Try commenting out lines 150-151, then adding these lines at line 154:
If not OnMarket then
SET STOP %LOSS sl
SET TARGET %PROFIT tp
Endif