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/13/2017 at 9:22 PM #40591
Came across the link below … it explains 3 Strategies in detail for trading on 5 Min Timeframe. Would be a good basis for coding 3 separate Bots.
If the Strategies exist on here already, then it be very useful if you could provide a link?
https://tradingsim.com/blog/5-minute-bar/
GraHal
07/14/2017 at 12:47 PM #40637I tried #1, Stochastic+Rsi+TEMA, on DAX 5-min TF (I added Nicolas’ trailing stop code):
Stochastic+Rsi+Tema123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990//-------------------------------------------------------------------------// Stochastic+Rsi+Tema 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 = 30 //30 pips Take ProfitONCE SL = 9 //9 pips Stop LossTemaVal = Tema[4](close) //4ONCE StocLimitBuy = 22 //OS 22ONCE StocLimitSell = 100 - StocLimitBuy //OB (difference)ONCE RsiLimitBuy = 31 //OS 31ONCE RsiLimitSell = 100 - RsiLimitBuy //OB (difference)StocD = Stochastic[8,6](close) //8, 6StocK = Average[13](StocD) //13RsiVal = Rsi[3](close) //3//***************************************************************************************IF LongOnMarket THENIF Close < TemaVal THENSELL AT MARKET //Exit LONGs when Bar closes below TEMAENDIFENDIFIF ShortOnMarket THENIF Close > TemaVal THENEXITSHORT AT MARKET //Exit SHORTs when Bar closes above TEMAENDIFENDIF//***************************************************************************************trailingstart = 2 //2 trailing will start @trailinstart points profittrailingstep = 1 //1 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 = (RsiVal < RsiLimitBuy) AND (RsiVal > RsiVal[1]) //Rsi in OS and North bounda3 = (StocK < StocLimitBuy) AND (StocK > StocD) //Stoch in OS and North boundIF a1 AND a2 AND a3 THENBUY nLots CONTRACT AT MARKETENDIF//***************************************************************************************// SHORT trades//***************************************************************************************b1 = close < open //BEARish barb2 = (RsiVal > RsiLimitSell) AND (RsiVal < RsiVal[1]) //Rsi in OB and South boundb3 = (StocK > StocLimitSell) AND (StocK < StocD) //Stoch in OB and South boundIF b1 AND b2 AND b3 THENSELLSHORT nLots CONTRACT AT MARKETENDIF//SET TARGET PPROFIT TPSET STOP PLOSS SLIt is over optimized, though. I’ll demo it for a while.
1 user thanked author for this post.
07/14/2017 at 8:59 PM #40676Wow Robert that looks great! Would have taken me all next week to get that sorted, if even then! 🙂
Results stats look healthy … ‘gain to loss ratio’ and % winning trades. Love how your variables and comments line up … I have trouble with lack of ‘text contrast’ on the PRT Coding window and vertical alignment makes it so much easier.
I’ll check it out further over the weekend.
Many Thanks for your time, effort and for sharing
GraHal07/16/2017 at 4:49 PM #40789Actually the above strategy was Strategy #1 (of group 3).
07/16/2017 at 4:54 PM #40790Here is another one, Strategy #2 (of group 3), still using Nicolas’trailing stop code:
Macd-Mfi DAX 5 min1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586//-------------------------------------------------------------------------// Macd-Mfi 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 = 60 //60 pips Take ProfitONCE SL = 40 //40 pips Stop LossONCE Macd1 = 14 //14ONCE Macd2 = 32 //32ONCE Macd3 = 9 //9MacdVal = MACD[Macd1,Macd2,Macd3](close)MacdSignal = MACDline[Macd1,Macd2,Macd3](close)MfiVal = MoneyFlow[23](close) //23//***************************************************************************************IF LongOnMarket THENIF MacdSignal CROSSES UNDER MacdVal THENSELL AT MARKET //Exit LONGs when MACD reverses southwardsENDIFENDIFIF ShortOnMarket THENIF MacdSignal CROSSES OVER MacdVal THENEXITSHORT AT MARKET //Exit SHORTs when MACD reverses northwardsENDIFENDIF//***************************************************************************************trailingstart = 2 //2 trailing will start @trailinstart points profittrailingstep = 8 //8 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 = MacdSignal CROSSES OVER MacdVal //MACD goes Northa3 = (MfiVal > 3200) AND (MfiVal > MfiVal[1]) //3200 Mfi limitIF a1 AND a2 AND a3 THENBUY nLots CONTRACT AT MARKETENDIF//***************************************************************************************// SHORT trades//***************************************************************************************b1 = close < open //BEARish barb2 = MacdSignal CROSSES UNDER MacdVal //MACD goes Southb3 = (MfiVal < -3200) AND (MfiVal < MfiVal[1]) //-3200 Mfi limitIF b1 AND b2 AND b3 THENSELLSHORT nLots CONTRACT AT MARKETENDIF//SET TARGET PPROFIT TPSET STOP PLOSS SL//GRAPH MfiVal AS "Mfi"Tested on DAX 5-min TF.
07/16/2017 at 5:19 PM #40793It’s the first time I tackle with MFI and I’d like a confirmation that this is the correct way it should be used.
Thank you.
Roberto
07/16/2017 at 11:33 PM #40836Wow you’ve been busy again!
I knocked 1 hour off the times to change from UTC +2 (Italy) to UTC +1 (UK).
Attached are the equity curves I get on the DAX at 100k bars.
Re Strategy #2 (of group 3) … are your results over 200k bars Robert?
Thank You
Graham07/16/2017 at 11:57 PM #40839No, I only started from Jan. 1, 2017 through last friday. Anyway I am using IG, so my limit would be 100k.
I am planning to try to build the strategy #3 of group 3, but it involves oscillators/indicators not built-in so its execution will be slower, but I still wanna have a try over the next couple of days.
1 user thanked author for this post.
07/17/2017 at 9:57 AM #40846Right I’ve got my results for Strategy #2 (of group 3) exact same as yours now … 16 Trades all winners since 4 Jan 17 … see attached.
I’m on spreadbet with IG so I increased Lot size to 25 to get exact same figures as you (I would only trade £1 per point to see how it goes).
I love both Strats cos they’re in and out in a few bars (they don’t sit there for hours (while I’m stressing! :)) as losers hoping ‘all will come right in the end’!) To my logic, this is what a short TF Strat should do … ride the short term cycles!?
Onward and Upward … looking good!
Many Thanks for your ongoing work Roberto (apols for Robert in previous)
GraHal1 user thanked author for this post.
07/17/2017 at 11:27 AM #40851As to strategy #3 of group 3, it involves a Relative Vigor Index which I haven’t found around here.
In a new post I’ll ask Nicolas if he can translate it from a Metastock code I have found over the internet.
07/17/2017 at 1:28 PM #4086607/17/2017 at 1:55 PM #40870That’s the code how I understood the description in mql5 page
RVI123456789101112131415161718192021222324252627282930// === RVI Relative Vigor Indicator//VALUE1 = ((CLOSE - OPEN) + 2 * (CLOSE (1)) - OPEN (1)) + 2*(CLOSE (2) - OPEN (2)) + (CLOSE (3) - OPEN (3))) / 6//VALUE2 = ((HIGH - LOW) + 2 * (HIGH (1) - LOW (1)) + 2*(HIGH (2)- LOW (2)) + (HIGH (3) - LOW (3))) / 6//NUM = SUM (VALUE1, N)//DENUM = SUM (VALUE2, N)//RVI = NUM / DENUM//RVISig = (RVI + 2 * RVI (1) + 2 * RVI (2) + RVI (3)) / 6// ..........................//OPEN — is the opening price;//HIGH — is the maximum price;//LOW — is the minimum price;//CLOSE — is the closing price;//VALUE1 — symmetrically weighted moving average of the differences of the closing and openings prices;//VALUE2 — symmetrically weighted moving average of the differences of the maximum and minimum prices;//NUM — amount N importances of VALUE1;//DENUM —amount N importances of VALUE2;//RVI — value of the Relative Vigor Index indicator for the current bar;//RVISig — value of the RVI signal line for the current bar;//N — period of the smoothing// ..............................period=10VALUE1 = ((CLOSE - OPEN) + 2*(CLOSE[1] - OPEN[1]) + 2*(CLOSE[2] - OPEN[2]) + (CLOSE[3] - OPEN[3])) / 6VALUE2 = ((HIGH - LOW) + 2*(HIGH[1] - LOW[1]) + 2*(HIGH[2]- LOW[2]) + (HIGH[3] - LOW[3])) / 6NUM = VALUE1 * periodDENUM = VALUE2 * periodRVI = NUM / DENUMRVISig = (RVI + 2 * RVI[1] + 2 * RVI[2] + RVI[3]) / 6return RVI as "rvi", RVISig as "rvi signal"1 user thanked author for this post.
07/18/2017 at 8:03 AM #4092407/18/2017 at 10:34 AM #40938I incurred the same error this morning (nighttime) at 02:00 (gmt +0) as from attached pics.
Pic (1) is just the error; Pic(2) is the screenshot of the DAX 5-min chart at that time; Pic(3) is the screenshot where I outlined variable MFI with a value of -0, which is likely to be the problem.
I tried to replicate the error with ProBackTest, extending the final time to the last current bar, but it did not work, I don’t know why ProOrder behaves differently from ProBackTest.
I am afraid the oscillator MFI is not used correctly (it was the first time I used it). Also, this may happen due to overnight closure of DAX, because the strategy keeps running and evaluating each bar continuosly. What’s the data contained in a NON-exixting 5-min bar?
I hope Nicolas will help when back from his leave.
1 user thanked author for this post.
07/18/2017 at 11:59 AM #40951In the Strategy No 2: where do you get these border values from?
Snip Strategy 2123456789101112131415161718//***************************************************************************************// LONG trades//***************************************************************************************a1 = close > open //BULLish bara2 = MacdSignal CROSSES OVER MacdVal //MACD goes Northa3 = (MfiVal > 3200) AND (MfiVal > MfiVal[1]) //3200 Mfi limitIF a1 AND a2 AND a3 THENBUY nLots CONTRACT AT MARKETENDIF//***************************************************************************************// SHORT trades//***************************************************************************************b1 = close < open //BEARish barb2 = MacdSignal CROSSES UNDER MacdVal //MACD goes Southb3 = (MfiVal < -3200) AND (MfiVal < MfiVal[1]) //-3200 Mfi limitIF b1 AND b2 AND b3 THENSELLSHORT nLots CONTRACT AT MARKETENDIFIf I open the MFI Indicator in PRT, it has default borders of 20/80 and looking at the picture in the original article, it’s the same there. Thanks.
-
AuthorPosts
Find exclusive trading pro-tools on