Trading the 5 Min Bar
Forums › ProRealTime English forum › ProOrder support › Trading the 5 Min Bar
- This topic has 66 replies, 8 voices, and was last updated 6 years ago by Gertrade.
-
-
07/21/2017 at 4:52 PM #41295
Finally the last strategy, Strategy #3 of group 3, along with the 3 indicators:
Klinger-Rvi-Lsma DAX 5 min123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081//-------------------------------------------------------------------------// Klinger-Rvi-Lsma DAX 5 min//-------------------------------------------------------------------------DEFPARAM CumulateOrders = FalseDEFPARAM FlatBefore = 090000 //no trades before 09:00:00DEFPARAM FlatAfter = 213000 //no trades after 21:30:00ONCE nLots = 1 //number of LOTs tradedONCE TP = 23 //23 pips Take ProfitONCE SL = 16 //16 pips Stop LossRviVal, RviSignal = CALL "RVI by John Ehlers"[7] //7KlingerVal, KlingerTrigger = CALL "Klinger oscillator"[25,44,55,1] //25,44,55,1 (ema)LeastSquareEMA = CALL "ELSMA - Least Square EMA"[11,4] //11,4//***************************************************************************************IF LongOnMarket THENIF close < LeastSquareEMA THENSELL AT MARKET //Exit LONGs when MACD reverses southwardsENDIFENDIFIF ShortOnMarket THENIF close > LeastSquareEMA THENEXITSHORT AT MARKET //Exit SHORTs when MACD reverses northwardsENDIFENDIF//***************************************************************************************trailingstart = 10 //10 trailing will start @trailinstart points profittrailingstep = 13 //13 trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//***************************************************************************************// LONG trades//***************************************************************************************a1 = close > open //BULLish bara2 = KlingerTrigger CROSSES OVER KlingerVal //Klinger trigger is going northa3 = RviSignal CROSSES OVER RviVal //RVI long signal occurredIF a1 AND a2 AND a3 THENBUY nLots CONTRACT AT MARKETENDIF//***************************************************************************************// SHORT trades//***************************************************************************************b1 = close < open //BEARish barb2 = KlingerTrigger CROSSES UNDER KlingerVal //Klinger trigger is going southb3 = RviSignal CROSSES UNDER RviVal //RVI short signal occurredIF b1 AND b2 AND b3 THENSELLSHORT nLots CONTRACT AT MARKETENDIF//SET TARGET PPROFIT TPSET STOP PLOSS SLElSMA indicator:
Exponential Least Square Moving Average1234567891011//-------------------------------------------------//// ELSMA - Exponential Least Square Moving Average ////-------------------------------------------------//DEFPARAM CalculateOnLastBars = 200Period = MAX(Period, 1)if NumBars < 1 thenNumBars = 4endifLR = LinearRegression[NumBars](close)AFR = ExponentialAverage[Period](LR)RETURN AFRRVI indicator:
RVI by John Ehler12345678910111213141516171819202122// Relative Vigor Index (RVI) by John Ehlers// Paramètres:// Per = periods for summation (12 as défault)DEFPARAM CalculateOnLastBars = 200diff = close - openind1 = (diff + 2*diff[1] + 2*diff[2] + diff[3]) / 6ind2 = (Range + 2*Range[1] + 2*Range[2] + Range[3]) / 6cond = Summation[per](ind2)IF cond = 0 THENtemp = 0.0001ELSEtemp = condENDIFRVI = Summation[per](ind1) / tempRVIsig = (RVI + 2*RVI[1] + 2*RVI[2] + RVI[3]) / 6RETURN RVI COLOURED (255, 0, 0) AS"Relative Vigor Index", RVIsig COLOURED (0, 0, 255) AS"Relative Vigor Index Signal"KLINGER oscillator:
Klinger oscillator1234567891011121314151617181920212223242526272829303132// KLINGER oscillator// variable AVGTYPE can hold values://// 0 = SMA// 1 = EMA// 2 = WMA// 3 = Wilder MA// 4 = Triangular MA// 5 = End point MA// 6 = Time series MA//------------------------------------------------DEFPARAM CalculateOnLastBars = 200hlc3= (high + low + close)/3if(hlc3>hlc3[1]) THENxTrend = volume * 100ELSExTrend = -volume * 100ENDIFif (AvgType < 0) OR (AvgType > 6) then //default to ONE if parameter isAvgType = 1 // out of range 0-6endifxFast = average[FastX,AvgType](xTrend)xSlow = average[SlowX,AvgType](xTrend)xKvO = xFast-xSlowxTrigger = average[TrigLen,AvgType](xKvO)RETURN xKvO AS "Klinger oscillator", xTrigger AS "trigger"This strategy is not performing like the first two in the group.
Any suggestion for improvements is highly welcome!
07/21/2017 at 4:53 PM #41300Performance attached.
07/21/2017 at 5:49 PM #41303Wow busy again Roberto! Looks good, I’ll try it out later, thank you for sharing.
I’m ‘licking my wounds’ at the mo as I got on the wrong side of the DAX rout today and I let it run thinking the price drop would pull back! 🙁
Cheers
GraHal07/21/2017 at 6:10 PM #41304Sorry to hear that!
That’s why I am spending time and efforts on automated trading, I fear my mind… I’ve experienced your same situation several times before and want to find a way to skip over emotions.
I am just demoing some strategies, some not good, some seem good, but I am waiting for a better engine from PRT, multi timeframe and more data and speed for backtests!
Roberto
07/21/2017 at 7:46 PM #4131807/21/2017 at 9:30 PM #41330Hello Nicolas, welcome back. Hope you enjoyed your leave!
The code is the one posted here https://www.prorealcode.com/topic/trading-the-5-min-bar/#post-40790
it uses the Money Flow Index, which I had never used before. When added to a chart it behaves correctly, within the limits (80 – 20), but when referenced in a strategy its values yields odd results, ranging from, say, +20000 to -10000.
Also, at night the strategy has been always closed due to “divide by zero” error.
At that point I, and GraHal, did not know what to do. I found an alternate MFI, the Twiggs MFI (post https://www.prorealcode.com/topic/trading-the-5-min-bar/page/2/#post-41060), which has no divide by zero issues and returns very different values.
The strategy works, but I fear that is not what the original strategy is all about (strategy #2 of group 3 from post https://www.prorealcode.com/topic/trading-the-5-min-bar/#post-40591).
07/21/2017 at 9:37 PM #41331We would like to know about your experience with Money Flow Index, why the “divide by zero” error was returned and what is the difference between the built-in Money Flow Index and the Twiggs MFI I used.
As for the other two strategies posted, there are being demoed with no error.
Thank you.
07/22/2017 at 9:49 AM #4135607/22/2017 at 2:23 PM #41371You mean this way:
12345IF time >= 080000 AND time <= 210000 THEN.. //my strategy goes here.ENDIF?
In this case BARS outside that time range ARE not evaluated by ProOrder?
Because if they are evaluated nonetheless, so will be the oscillator and the outcome wouldn’t change!!!
08/01/2017 at 10:11 AM #4216808/01/2017 at 10:15 AM #4216908/01/2017 at 10:39 AM #4217301/09/2018 at 12:17 PM #58568I’m back on this @robertogozzi
What is your opinion now (after saying) … I’ll run it in my demo account till the end of the year!
I got the divide by zero error yesterday (again) … did we ever get a cure to the issue? Do you still get the divide by zero issue?
What version code incorporates the fix (if any?) please?
Many Thanks
GraHal01/09/2018 at 12:23 PM #5857501/09/2018 at 12:30 PM #58578I was getting a ‘divide by zero’ error in one of my strategies the other day and so just threw in a quick fix which seems to have done the job. Just turn the offending variable into something close to zero that is not zero.
12345678910111213141516UpBar = close > openDownBar = close < openOL = Open - LowHO = High - OpenIF OL <= 0 THENOL = 0.0000001ENDIFIF HO <= 0 THENHO = 0.0000001ENDIFUpTen = OL/HO < PercDownTen = HO/OL < Perc1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on