Strategy TrendImpulse v1
Forums › ProRealTime English forum › ProOrder support › Strategy TrendImpulse v1
- This topic has 74 replies, 6 voices, and was last updated 1 year ago by thomas2004ch.
-
-
05/10/2020 at 1:30 PM #13089205/10/2020 at 2:03 PM #130898
Hi @vonasi,
This is the complete code. I’ve managed to get it working by removing SlowLength and FastLength as the error stated the code did not use either variable. Also I’m not sure if i have the UKDSL correct as i’ve removed the US version. Would really appreciate it if someone could just check over that section just to make sure its correct:
Full UK version123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398DEFPARAM CumulateOrders = falseDEFPARAM PRELOADBARS = 1000SL = 200SlowPipDisplace = 0FastPipDisplace = 0length = 200startingvalue = 50startingvalue2 = 5// --------- UK DAY LIGHT SAVINGS MONTHS ---------------- //mar = month = 3 // MONTH STARToct = month = 10 // MONTH ENDIF ( dayofweek >= 0 and mar AND 31-day<7 ) OR ( month > 3 AND month < 10 ) OR ( oct AND 31-day > 6 ) OR (dayofweek = 4 AND oct AND day<31) OR (dayofweek = 3 AND oct AND day+1<31) OR (dayofweek = 2 AND oct AND day+2<31) OR (dayofweek = 1 AND oct AND day+3<31) OR (dayofweek = 0 AND oct AND day+4<31) OR (dayofweek = 5 AND oct AND 31-day<7) THENUKDLS=1ELSEUKDLS=0ENDIFtimeok = NOT(time >051500- UKDLS AND time <053000 - UKDLS) AND NOT(time >060000 - UKDLS AND time <070000 - UKDLS)//startingvalue = 15 //5, 100, 10 boxsizeincrement = 5 //5, 20, 10maxincrement = 7 //5, 10 limit of no of increments either up or downreps = 3 //1 number of trades to use for analysis //2maxvalue = 70 //20, 300, 150 //maximum allowed valueminvalue = 50 //5, minimum allowed value//startingvalue2 = 55 //5, 100, 50 stop lossincrement2 = 3 //5, 10maxincrement2 = 7 //1, 30 limit of no of increments either up/down //4reps2 = 3 //1, 2 nos of trades to use for analysis //3maxvalue2 = 25 //20, 300, 200 maximum allowed valueminvalue2 = 5 //5, minimum allowed valueheuristicscyclelimit = 2once heuristicscycle = 0once heuristicsalgo1 = 1once heuristicsalgo2 = 0if heuristicscycle >= heuristicscyclelimit thenif heuristicsalgo1 = 1 thenheuristicsalgo2 = 1heuristicsalgo1 = 0elsif heuristicsalgo2 = 1 thenheuristicsalgo1 = 1heuristicsalgo2 = 0endifheuristicscycle = 0elseonce valuex = startingvalueonce valuey = startingvalue2endifif heuristicsalgo1 = 1 then//heuristics algorithm 1 startif (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) thenoptimise = optimise + 1endifonce valuex = startingvalueonce pincpos = 1 //positive increment positiononce nincpos = 1 //negative increment positiononce optimise = 0 //initialize heuristicks engine counter (must be incremented at position start or exit)once mode1 = 1 //switches between negative and positive increments//once wincountb = 3 //initialize best win count//graph wincountb coloured (0,0,0) as "wincountb"//once stratavgb = 4353 //initialize best avg strategy profit//graph stratavgb coloured (0,0,0) as "stratavgb"if optimise = reps thenwincounta = 0 //initialize current win countstratavga = 0 //initialize current avg strategy profitheuristicscycle = heuristicscycle + 1for i = 1 to reps doif positionperf(i) > 0 thenwincounta = wincounta + 1 //increment current wincountendifstratavga = stratavga + (((positionperf(i)*countofposition[i]*close)*-1)*-1)nextstratavga = stratavga/reps //calculate current avg strategy profit//graph (positionperf(1)*countofposition[1]*100000)*-1 as "posperf1"//graph (positionperf(2)*countofposition[2]*100000)*-1 as "posperf2"//graph stratavga*-1 as "stratavga"//once besta = 300//graph besta coloured (0,0,0) as "besta"if stratavga >= stratavgb thenstratavgb = stratavga //update best strategy profitbesta = valuexendif//once bestb = 300//graph bestb coloured (0,0,0) as "bestb"if wincounta >= wincountb thenwincountb = wincounta //update best win countbestb = valuexendifif wincounta > wincountb and stratavga > stratavgb thenmode1 = 0elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 1 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 2elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 1 thenvaluex = valuex + (increment*pincpos)pincpos = pincpos + 1mode1 = 1elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 2 thenvaluex = valuex + (increment*pincpos)pincpos = pincpos + 1mode1 = 1elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 2 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 2endifif nincpos > maxincrement or pincpos > maxincrement thenif besta = bestb thenvaluex = bestaelseif reps >= 10 thenweightedscore = 10elseweightedscore = round((reps/100)*100)endifvaluex = round(((besta*(20-weightedscore)) + (bestb*weightedscore))/20) //lower reps = less weight assigned to win%endifnincpos = 1pincpos = 1elsif valuex > maxvalue thenvaluex = maxvalueelsif valuex < minvalue thenvaluex = minvalueendifoptimise = 0endif// heuristics algorithm 1 endelsif heuristicsalgo2 = 1 then// heuristics algorithm 2 startif (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) thenoptimise2 = optimise2 + 1endifonce valuey = startingvalue2once pincpos2 = 1 //positive increment positiononce nincpos2 = 1 //negative increment positiononce optimise2 = 0 //initialize heuristicks engine counter (must be incremented at position start or exit)once mode2 = 1 //switches between negative and positive increments//once wincountb2 = 3 //initialize best win count//graph wincountb2 coloured (0,0,0) as "wincountb2"//once stratavgb2 = 4353 //initialize best avg strategy profit//graph stratavgb2 coloured (0,0,0) as "stratavgb2"if optimise2 = reps2 thenwincounta2 = 0 //initialize current win countstratavga2 = 0 //initialize current avg strategy profitheuristicscycle = heuristicscycle + 1for i2 = 1 to reps2 doif positionperf(i2) > 0 thenwincounta2 = wincounta2 + 1 //increment current wincountendifstratavga2 = stratavga2 + (((positionperf(i2)*countofposition[i2]*close)*-1)*-1)nextstratavga2 = stratavga2/reps2 //calculate current avg strategy profit//graph (positionperf(1)*countofposition[1]*100000)*-1 as "posperf1-2"//graph (positionperf(2)*countofposition[2]*100000)*-1 as "posperf2-2"//graph stratavga2*-1 as "stratavga2"//once besta2 = 300//graph besta2 coloured (0,0,0) as "besta2"if stratavga2 >= stratavgb2 thenstratavgb2 = stratavga2 //update best strategy profitbesta2 = valueyendif//once bestb2 = 300//graph bestb2 coloured (0,0,0) as "bestb2"if wincounta2 >= wincountb2 thenwincountb2 = wincounta2 //update best win countbestb2 = valueyendifif wincounta2 > wincountb2 and stratavga2 > stratavgb2 thenmode2 = 0elsif wincounta2 < wincountb2 and stratavga2 < stratavgb2 and mode2 = 1 thenvaluey = valuey - (increment2*nincpos2)nincpos2 = nincpos2 + 1mode2 = 2elsif wincounta2 >= wincountb2 or stratavga2 >= stratavgb2 and mode2 = 1 thenvaluey = valuey + (increment2*pincpos2)pincpos2 = pincpos2 + 1mode2 = 1elsif wincounta2 < wincountb2 and stratavga2 < stratavgb2 and mode2 = 2 thenvaluey = valuey + (increment2*pincpos2)pincpos2 = pincpos2 + 1mode2 = 1elsif wincounta2 >= wincountb2 or stratavga2 >= stratavgb2 and mode2 = 2 thenvaluey = valuey - (increment2*nincpos2)nincpos2 = nincpos2 + 1mode2 = 2endifif nincpos2 > maxincrement2 or pincpos2 > maxincrement2 thenif besta2 = bestb2 thenvaluey = besta2elseif reps2 >= 10 thenweightedscore2 = 10elseweightedscore2 = round((reps2/100)*100)endifvaluey = round(((besta2*(20-weightedscore2)) + (bestb2*weightedscore2))/20) //lower reps = less weight assigned to win%endifnincpos2 = 1pincpos2 = 1elsif valuey > maxvalue2 thenvaluey = maxvalue2elsif valuey < minvalue2 thenvaluey = minvalue2endifoptimise2 = 0endif// heuristics algorithm 2 endendif//GRAPH valuex//GRAPH valueytimeframe(1 day)volindic = (averagetruerange[5](close)/close)*100timeframe(5 minute)thigh1 = Highest[valuex](high)+ SlowPipDisplace*pointsizetlow1 = Lowest[valuex](low)- SlowPipDisplace*pointsizethigh2 = Highest[valuey](high)+ FastPipDisplace*pointsizetlow2 = Lowest[valuey](low)- FastPipDisplace*pointsizeif barindex>2 thenif Close>line1[1] thenline1 = tlow1elseline1 = thigh1endifif Close>line2[1] thenline2 = tlow2elseline2 = thigh2endifendifif (Close[0]<line1[0] and Close[0]<line2[0]) thentrend = 1endifif (Close[0]>line1[0] and Close[0]>line2[0]) thentrend = -1endifif (line1[0]>line2[0] or trend[0] = 1) thentrena = 1endifif (line1[0]<line2[0] or trend[0] = -1) thentrena = -1endifif trena<>trena[1] thenif trena=1 then//bearprefecttrend = 2else//bullprefecttrend = 1endifendiftimeframe(default)bollMA = average[length, 1](close)//50,1STDDEV = STD[length]bollUP = bollMA + 2 * STDDEVbollDOWN = bollMA - 2 * STDDEVbollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)//====== Enter market - start =====// LONG sideC1 = bollPercent > 60 AND prefecttrend[1] = 2 AND prefecttrend = 1IF timeok AND Not OnMarket AND C1 AND volindic < 3.5 THENBUY 1 CONTRACT AT MARKETSET STOP pLOSS SLENDIF// SHORT sideC2 = bollPercent < 40 AND prefecttrend[1] = 1 AND prefecttrend = 2IF timeok AND Not OnMarket AND C2 AND volindic < 3.5 THENSELLSHORT 1 CONTRACT AT MARKETSET STOP pLOSS SLENDIF//====== Enter market - end =====//====== Exit market - start =====X1 = prefecttrend[1] = 1 AND prefecttrend = 2IF LONGONMARKET AND X1 THENSELL AT MARKETENDIFX2 = prefecttrend[1] = 2 AND prefecttrend = 1IF SHORTONMARKET AND X2 THENEXITSHORT AT MARKETENDIF// Avoid losing trade not caught by trainingtradegain = POSITIONPERF * 100rangelevel = 100* (range)/closegainenough = summation[barindex - tradeindex](tradegain > 0.2) > 1closefast = gainenough AND rangelevel < 0.5 AND POSITIONPERF * 100 <= 0.1IF closefast THENEXITSHORT AT MARKETSELL AT MARKETENDIF//====== Exit market - end =====//====== Trailing Stop mechanism - start =====trailingstart = (0.5 * SL ) / pointsizetrailingstep = (0.25 * SL ) / pointsize//resetting variables when no trades are on marketif not onmarket thenpriceexit = 0endif//case LONG orderif longonmarket then//first move (breakeven)IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THENpriceexit = tradeprice(1) + trailingstep*pointsizeENDIF//next movesIF priceexit>0 THENP2 = close-priceexit >= trailingstart*pointsizeIF P2 THENpriceexit = priceexit + trailingstep*pointsizeENDIFENDIFendif//case SHORT orderif shortonmarket then//first move (breakeven)IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THENpriceexit = tradeprice(1) - trailingstep*pointsizeENDIF//next movesIF priceexit>0 THENP2 = priceexit-close >= trailingstart*pointsizeIF P2 THENpriceexit = priceexit - trailingstep*pointsizeENDIFENDIFendif//exit on trailing stop price levelsif onmarket and priceexit>0 thenEXITSHORT AT priceexit STOPSELL AT priceexit STOPendif//====== Trailing Stop mechanism - end =====05/10/2020 at 8:30 PM #131023Could you please explain in simple terms what this section of the code is doing and should the same values be used with the UKDLS code?
1timeok = NOT(time >051500- USDLS AND time <053000 - USDLS) AND NOT(time >060000 - USDLS AND time <070000 - USDLS)Best Wishes,
Plaedies
05/11/2020 at 10:08 AM #131087Hi Guys,
On reflection of my last post i’m assuming this piece of software holds off from any trades during 2 periods :
05:15 – 05:30
06:00 – 07:00
As this is considered too much volitility? Would that be correct?
Best wishes,
Plaedies
05/11/2020 at 10:33 AM #13110105/11/2020 at 10:36 AM #131104Thanks @Yomihou,
As I live in the UK I have deleted the USDLS code and instead used the below.. Would that be correct for the Wall Street DJI?
123456789101112// --------- UK DAY LIGHT SAVINGS MONTHS ---------------- //mar = month = 3 // MONTH STARToct = month = 10 // MONTH ENDIF ( dayofweek >= 0 and mar AND 31-day<7 ) OR ( month > 3 AND month < 10 ) OR ( oct AND 31-day > 6 ) OR (dayofweek = 4 AND oct AND day<31) OR (dayofweek = 3 AND oct AND day+1<31) OR (dayofweek = 2 AND oct AND day+2<31) OR (dayofweek = 1 AND oct AND day+3<31) OR (dayofweek = 0 AND oct AND day+4<31) OR (dayofweek = 5 AND oct AND 31-day<7) THENUKDLS=1ELSEUKDLS=0ENDIFtimeok = NOT(time >051500- UKDLS AND time <053000 - UKDLS) AND NOT(time >060000 - UKDLS AND time <070000 - UKDLS)05/11/2020 at 4:53 PM #131164Hello All,
Sorry that I wasn’t available for couple of days. Thank you @Vonasi for helping to answer those question.
Due to much confusion with the time zone, let me create another version change to new york time zone, it will probably remove the need of conversion of daylight saving.
05/12/2020 at 7:38 PM #131381In fact, I realize I should not need to do that. You can actually change the Time Zone from Options -> Platform options -> Time zones & Trading hours -> Display all data in this time zone: <select the UTC+0800>
You can also prepare it into the ProOrder for demo or live account. Once prepared, it will record the preset UTC+0800. Then you may change back to your original time zone if you wish for other strategies.
05/12/2020 at 7:47 PM #131383Great, so should I revert back to the original USDLS code and use the platform to add the UTC+8 ?
Kind regards,
Plaedies
05/15/2020 at 3:16 AM #131728Great, so should I revert back to the original USDLS code and use the platform to add the UTC+8 ?
@Plaedies, yes, should revert it back.05/15/2020 at 7:24 AM #131729Hi I am also new and having trouble. When trying to automate it says I need to edit the code. I tried doing as below but it didnt work?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123DEFPARAM CumulateOrders = falseDEFPARAM PRELOADBARS = 1000SL = 100SlowPipDisplace = 0FastPipDisplace = 0SlowLength = 15FastLength = 85centertrend = 1length = 27// --------- US DAY LIGHT SAVINGS MONTHS ---------------- //mar = month = 3 // MONTH STARTnov = month = 11 // MONTH ENDIF (month > 3 AND month < 11) OR (mar AND day>14) OR (mar AND day-dayofweek>7) OR (nov AND day<=dayofweek AND day<7) THENUSDLS=010000ELSEUSDLS=0ENDIFtimeok = NOT(time >051500- USDLS AND time <053000 - USDLS) AND NOT(time >060000 - USDLS AND time <070000 - USDLS)timeframe(5 minute)thigh1 = Highest[SlowLength](high)+ SlowPipDisplace*pointsizetlow1 = Lowest[SlowLength](low)- SlowPipDisplace*pointsizethigh2 = Highest[FastLength](high)+ FastPipDisplace*pointsizetlow2 = Lowest[FastLength](low)- FastPipDisplace*pointsizeif barindex>2 thenif Close>line1[1] thenline1 = tlow1elseline1 = thigh1endifif Close>line2[1] thenline2 = tlow2elseline2 = thigh2endifendifif (Close[0]<line1[0] and Close[0]<line2[0]) thentrend = 1endifif (Close[0]>line1[0] and Close[0]>line2[0]) thentrend = -1endifif (line1[0]>line2[0] or trend[0] = 1) thentrena = 1endifif (line1[0]<line2[0] or trend[0] = -1) thentrena = -1endifif trena<>trena[1] thenif trena=1 then//bearprefecttrend = 2else//bullprefecttrend = 1endifendiftimeframe(default)once bb = srcif barindex>length thensrc = (highest[length](high)+lowest[length](low))/2rising = src-src[length]>0falling = src-src[length]<0aa = rising or fallingbb = exponentialaverage[centertrend](aa*src+(1-aa)*bb[1])//—-if bb>bb[1] then//bulltrendimpulse = 1elsif bb<bb[1] then//beartrendimpulse = 2endifendif//====== Enter market - start =====// LONG sideC1 = trendimpulse = 1 AND prefecttrend[1] = 2 AND prefecttrend = 1IF timeok AND Not OnMarket AND C1 THENBUY 1 CONTRACT AT MARKETSET STOP pLOSS SLENDIF// SHORT sideC2 = trendimpulse = 2 AND prefecttrend[1] = 1 AND prefecttrend = 2IF timeok AND Not OnMarket AND C2 THENSELLSHORT 1 CONTRACT AT MARKETSET STOP pLOSS SLENDIF//====== Enter market - end =====//====== Exit market - start =====X1 = prefecttrend[1] = 1 AND prefecttrend = 2IF LONGONMARKET AND X1 THENSELL AT MARKETENDIFX2 = prefecttrend[1] = 2 AND prefecttrend = 1IF SHORTONMARKET AND X2 THENEXITSHORT AT MARKETENDIF//====== Exit market - end =====05/15/2020 at 11:51 AM #13175205/15/2020 at 2:17 PM #13177405/16/2020 at 8:21 AM #13185305/26/2020 at 10:25 AM #133285I’m confused about this part of the code:
define trena123456if (line1[0]>line2[0] or trend[0] = 1) thentrena = 1endifif (line1[0]<line2[0] or trend[0] = -1) thentrena = -1endifIts logic seem to favor trena=-1 (since it’s only 1 if trend = 1 and line1>=line2). How does this make sense?
Also, I’m confused by the numbers switching from 1 for bullish to -1 for bullish to 2 for bearish, etc. It would make more sense to just use 1 for bullish and -1 for bearish imho.
Does anyone else have any comments about the code? Maybe we can improve it together 😉
-
AuthorPosts
Find exclusive trading pro-tools on