NAS 2m HULL-SAR trading system
Forums › ProRealTime English forum › ProOrder support › NAS 2m HULL-SAR trading system
- This topic has 343 replies, 42 voices, and was last updated 1 year ago by bege.
-
-
10/09/2020 at 10:15 PM #146941
Try changing TradePrice in the TS snippets to PositionPrice (is that the correct term for the average trade price of all open positions)?
Just an idea before bed! 🙂
1 user thanked author for this post.
10/10/2020 at 12:16 AM #146946if you limit the number of open positions to i.e 5, an option would be maybe to have separeated individual trailing stops for tradeprice(1),tradeprice(2) etc
ive made in the past a ts for 2 cul. positions in some topic
not a nice way because you get lots of code
10/10/2020 at 12:21 AM #146949Grahal’s suggestion of using positionprice instead of tradeprice seems to make a big difference. TS should now start from the average price.
10/10/2020 at 1:38 AM #146953Revised with correction to the TS, tames the excesses – lower profit but better win %, optimized for max pos = 6
4 users thanked author for this post.
10/10/2020 at 12:38 PM #146965further revision to the TS (grazie Roberto) and re-optimized. Interestingly, there is now a sweet spot for max positions – it starts getting good at 4 and peaks at 8 (attached illustration). Above that performance falls off.
6 users thanked author for this post.
10/10/2020 at 1:39 PM #14697510/12/2020 at 4:17 AM #147095Hi Nonetheless,
I took the excellent cumulative trailingstop snippet of robertogozzi and splitted it for long & short, same as vectorial. This gives another nice improvement overall.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384// %trailing stop function incl. cumulative positionsonce trailingstoptype = 1if trailingstoptype then//====================once trailingpercentlong = 0.49 // %once trailingpercentshort = 0.28 // %once accelerator = 1 // 1 = default; always > 0 (i.e. 0.5-3)once ts2sensitivity = 0 // [0]close;[1]high/low;[2]low;high//====================once steppercentlong = (trailingpercentlong/10)*acceleratoronce steppercentshort = (trailingpercentshort/10)*acceleratorif onmarket thentrailingstartlong = positionprice[1]*(trailingpercentlong/100)trailingstartshort = positionprice[1]*(trailingpercentshort/100)trailingsteplong = positionprice[1]*(steppercentlong/100)trailingstepshort = positionprice[1]*(steppercentshort/100)endifif not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thennewsl = 0mypositionprice = 0endifpositioncount = abs(countofposition)if newsl > 0 thenif positioncount > positioncount[1] thenif longonmarket thennewsl = max(newsl,positionprice * newsl / mypositionprice)elsenewsl = min(newsl,positionprice * newsl / mypositionprice)endifendifendifif ts2sensitivity=1 thents2sensitivitylong=hights2sensitivityshort=lowelsif ts2sensitivity=2 thents2sensitivitylong=lowts2sensitivityshort=highelsets2sensitivitylong=closets2sensitivityshort=closeendifif longonmarket thenif newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong*pipsize thennewsl = positionprice+trailingsteplong*pipsizeendifif newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong*pipsize thennewsl = newsl+trailingsteplong*pipsizeendifendifif shortonmarket thenif newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort*pipsize thennewsl = positionprice-trailingstepshort*pipsizeendifif newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort*pipsize thennewsl = newsl-trailingstepshort*pipsizeendifendifif barindex-tradeindex>1 thenif longonmarket thenif newsl>0 thensell at newsl stopendifif newsl>0 thenif low crosses under newsl thensell at marketendifendifendifif shortonmarket thenif newsl>0 thenexitshort at newsl stopendifif newsl>0 thenif high crosses over newsl thenexitshort at marketendifendifendifendifmypositionprice = positionpriceendif3 users thanked author for this post.
10/12/2020 at 8:32 AM #14711810/12/2020 at 8:54 AM #147122Nice one Paul! I have also been working on long and short versions – your solution is more elegant, I just made 2 different algos.
But I’m also trying an alteration to the entry code so that the initial position is based on the 6min turnaround, with additional positions based on the 2min. Logically I think this makes more sense – to catch the bottom/top of the 6min run rather than entering anywhere along that trend. I’m running all these versions in demo to see what works better in actual trading.
10/12/2020 at 9:41 AM #147130I tried to optimized this parameters and the better one was 4
yes, 4 positions is still v profitable and needs a lot less capital to get going. you should try optimising max 4 on the Dow version as you can then run it at min size .2
10/12/2020 at 9:50 AM #147132IchI have a little bit better results with Paul´s Version with small changes.123456789101112Ctime = time >=143000 and time <213000BUY positionsize CONTRACT AT MARKETSET STOP %LOSS 1.1SET TARGET %PROFIT 2.0ENDIF// Conditions to enter short positionsIF Ctime and c2 and c2a AND C4 and c4a AND C6 and c6a and abs(CountOfPosition) < MaxPositionsAllowed THENSELLSHORT positionsize CONTRACT AT MARKETSET STOP %LOSS 1.1SET TARGET %PROFIT 2.010/12/2020 at 9:57 AM #147133Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read and try not to mix/use different languages.
Thanks 🙂
10/12/2020 at 10:01 AM #14713410/12/2020 at 2:50 PM #14716710/12/2020 at 5:53 PM #147195Hello
I have trust some modification SL and TP
the code :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143// Definition of code parametersDEFPARAM CumulateOrders = true // Cumulating positions deactivatedDEFPARAM preloadbars = 5000MaxPositionsAllowed = 100//Money Management NASMM = 0 // = 0 for optimizationif MM = 0 thenpositionsize=1ENDIFif MM = 1 thenONCE startpositionsize = 1ONCE factor = 60 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etcONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE tier1 = 200 // IG first tier margin limitONCE maxpositionsize = 2000 // IG tier 2 margin limitONCE minpositionsize = 1 // enter minimum position allowedIF StrategyProfit <> StrategyProfit[1] THENpositionsize = startpositionsize + Strategyprofit/(factor*margin)ENDIFIF StrategyProfit <> StrategyProfit[1] THENIF startpositionsize + Strategyprofit/(factor*margin) > tier1 thenpositionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 marginENDIFIF StrategyProfit <> StrategyProfit[1] THENif startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THENpositionsize = minpositionsize //keeps positionsize from going below allowed minimumENDIFIF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize thenpositionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limitENDIFENDIFENDIFENDIFCtime = time >=143000 and time <210000TIMEFRAME(18 minutes)Period= 155inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)HULLa = weightedaverage[round(sqrt(Period))](inner)c1 = HULLa > HULLa[1]c2 = HULLa < HULLa[1]ST1 = SAR[.005,.005,.02]c1a = (close > ST1)c2a = (close < ST1)TIMEFRAME(6 minutes)Periodb= 29innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)HULLb = weightedaverage[round(sqrt(Periodb))](innerb)c3 = HULLb > HULLb[1]c4 = HULLb < HULLb[1]ST2 = SAR[.005,.005,.02]c3a = (close > ST2)c4a = (close < ST2)TIMEFRAME(default)Periodc= 4innerc = 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]ST3 = SAR[.01,.01,.005]c5a = (close > ST3)c6a = (close < ST3)// Conditions to enter long positionsIF not longonmarket and Ctime and c1 and c1a AND C3 and c3a AND C5 and c5a THENBUY positionsize CONTRACT AT MARKETSET STOP pLOSS 15SET TARGET pPROFIT 55elsif longonmarket and Ctime and c1 and c1a AND C3 and c3a AND C5 and c5a and abs(CountOfPosition) < MaxPositionsAllowed THENif positionperf(0)*100>0 thenBUY positionsize CONTRACT AT MARKETSET STOP pLOSS 282SET TARGET pPROFIT 322endifendif// Conditions to enter short positionsIF not shortonmarket and Ctime and c2 and c2a AND C4 and c4a AND C6 and c6a THENSELLSHORT positionsize CONTRACT AT MARKETSET STOP pLOSS 68SET TARGET pPROFIT 21elsif shortonmarket and Ctime and c2 and c2a AND C4 and c4a AND C6 and c6a and abs(CountOfPosition) < MaxPositionsAllowed THENif positionperf(0)*100>0 thenSELLSHORT positionsize CONTRACT AT MARKETSET STOP pLOSS 159SET TARGET pPROFIT 411endifendif//%trailing stop functiontrailingstop = 1if trailingstop =1 thenonce trailingPercent = 0.38once stepPercent = 0.006if onmarket thentrailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailingstart points profittrailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stoplossendif//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close-newSL>trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFendif -
AuthorPosts
Find exclusive trading pro-tools on