[beta-testing] multi timeframe support for automatic trading, ideas are welcome!
Forums › ProRealTime English forum › ProOrder support › [beta-testing] multi timeframe support for automatic trading, ideas are welcome!
- This topic has 287 replies, 47 voices, and was last updated 4 years ago by Brianoshea.
Tagged: mtf, multitimeframe
-
-
10/09/2018 at 9:58 PM #8240310/10/2018 at 4:48 AM #82412
Recently (within a couple of weeks), I have experienced several strategies stopping nighttime due to unknown errors, but they ALL are MTF strategies launched on DAX from 1-minute or 15-second TFs and referencing other higher TFs.
It’s not always the same strategy.
Setting custom trading hours didn’t help.
Has anyone experienced similar problems dealing with MTF or DAX?
10/10/2018 at 7:07 AM #82418I can see now that you wrote the code O-jay8 (Vonasi did not share his code).
As you possibly already know I am not big on giving away complete fish. I prefer handing out fishing rods and the odd hook and line and some tips on how to fish rather than giving away whole fish.
I have now had two minutes to import O-Jay8’s code and compare it with mine. It was a very interesting thing to do to see how someone else goes about attacking the same idea. The codes are quite different!
I use a much simpler long term trend filter and as per all my codes I do not use stop loss or take profit levels – I sell when conditions are met. I also use a totally different RSI setting. I also do not use any time filter. Both strategies are profitable over the back test period so neither is right or wrong or better than the other – forward testing will tell us whether either of them are any good. I will put a note in my calender to re-test both strategies in a months time I think.
1 user thanked author for this post.
10/10/2018 at 12:09 PM #82450Hi
@Grahal, you are welcome. I have not a big problem to share a strategy code mainly as I am still a novice and hope somebody is able to improve my code.
My codes are usually just bits and pieces from other strategies, I have seen here in the forum. I still have so much to learn.
My overall picture what is even possible is still very limited.@ Vonasi, I understand that you dont want to share a complete strategy especially if you invested a lot of time and effort in it. I am already thankful for your tips and ideas.
i.e. your MTF RSI strategy, which I tried to replicate in my own way.
Often I dont even know where to start (initial strategy) so your idea with the MTF RSI was a good task for me to see whether I can get somehow similar results.I do like MTF strategies a lot and it opens up so many possibilities. Unfortunately I dont have so much time as I try to code more or less in my spare time.
Where do you guys get your ideas for strategies?
Personally it would be nice if we could share more ideas. Unfortunately I lack imagination.I tried to code stochastic overbought/oversold for MTF for forex pairs as well. (4h,1h,30m and 15 min)
I would say it was medium successful but I dont feel really confident about the future success rate in live but lets see. (attached the picture)1 user thanked author for this post.
10/10/2018 at 3:18 PM #82474Where do you guys get your ideas for strategies? Personally it would be nice if we could share more ideas. Unfortunately I lack imagination.
A lot of my ideas come from statistical/probability studies of price action or price action along with one indicator value. I’m not interested in complicated strategies or strategies with masses of indicators. If you look at my library posts you will see that a lot of them are more analysis tools than true indicators. It is from analysis that ideas blossom!
I enjoy writing my own indicators and sometimes spot something that can be used from these. For example the Mean Reversal Equity Curve Indicator that I posted recently has turned out to give some very positive filtering results – but I still need a few months of forward testing to be certain of it – if only PRT/IG would fix the end of day and end of week live testing problem!
Sometimes I will read something online or in a magazine that I had not thought of testing. 99% of the time after testing and analysing I dispose of the idea but 1% of the time there is a little gem that can be used.
10/15/2018 at 11:30 AM #82775I receive complete different trade results varying the code at Time Frame of 15 minutes. I am using the 15 minutes graph, which is the lowest timeframe for my testing I would expect the code behind Time Frame, //update on close// and //default// used in the lowest timeframe to give exactly the same trading results. Why NOT is for me a question. timeframe(15 minutes,updateonclose) gives a much higher trade result as timeframe(15 minutes, default)
Problem spotted and identified, should be fixed in a near update.
2 users thanked author for this post.
10/16/2018 at 8:35 PM #82926Nicolas,
” Problem spotted and identified, should be fixed in a near update. ”
In the meanwhile, what to use for the lowest timeframe ( in my case 15 minutes timeframe) ==> (Timeframe 15 minutes, default) or (Timeframe 15 minutes, updateonclose) ?
Maybe I should test it myself in a live situation, but do you know what the trading algoritme in real live trading will follow when I would use (Timeframe 15 minutes, updateonclose) with a live trading time frame of 15 minutes ? Would it give the higher results as backtested or will it give the lower results as backtested with (Timeframe 15 minutes, default) ?
Thanks for the answer.
Kind regards, Jan
10/17/2018 at 8:03 AM #82935Maybe I should test it myself in a live situation
I would test it in live demo only. MTF is still only in beta testing for exactly this reason so risking real money on it would be a bit like being a jet fighter test pilot – exciting but potentially very dangerous!
10/17/2018 at 8:06 AM #82936In the meanwhile, you should always use the below instruction for the lowest timeframe, which in this case is the “default”:
1timeframe(default)The lowest timeframe, the one on which the strategy is read and executed, will obviously always be read at the end of the bar, so specifying “updateonclose” or “default” doesn’t matter.
11/01/2018 at 11:11 AM #8391011/01/2018 at 4:38 PM #83952Yes, that’s possible, this is the purpose of the MTF functionnality. There is a simple and good example of a MTF strategy in this thread: https://www.prorealcode.com/topic/echelle-de-temps-multiples/#post-82039
11/02/2018 at 9:24 AM #84031Mes salutations .
Comment adapter les indicateurs aux Cryptomonnaies qui n’ont pas d’ouverture ni de cloture ? lequel choisir Cloture , Ouverture , plus haut, plus bas , Typique , Pondéré,Médian ou Total ?
Merci par avance pour cette précision
Cordialement 🙂
———————————————————————————————————————————————————————–
edit: Veuillez utiliser l’anglais sur le forum anglais. Merci. Cependant, j’ai fait la traduction avec Google Transaltor:
My greetings
How to adapt the indicators to cryptocurrencies that have no opening or closing? Which to choose between Closing, Opening, Upper, Lower, Typical, Weighted, Median or Total?
Thanks in advance for this clarification
Sincerely 🙂
Roberto
11/03/2018 at 11:42 AM #84081Guys i am finding a problem today with the MTF, i have several strategies with Default time frame 4h and inside the code i use the 1h time frame to find some filters. Now i have 6 strategies live like this, but today when i try to work on the backtest and others PRT told me that the lower Timeframe is not a multiply of the higher, but thats is not true and specially how is possible that my strategies are working ?????????????
i will post the code as example:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359// Pathfinder Trading System based on ProRealTime 10.3// Reiner @ www.prorealcode.com// Breakout system triggered by previous daily, weekly and monthly high/low crossings with smart position management// ProOrder code parameterDEFPARAM CUMULATEORDERS = true // cumulate orders if not turned offDEFPARAM PRELOADBARS = 10000timeframe (1H)MT = CALL "Main Trend"FILTROL= MT>CLOSEtimeframe (default)graph MT COLOURED (229, 43, 80)// define intraday trading windowONCE startTime = 90000 // start time of trading window in CETONCE endTime = 210000 // end time of trading window in CET// define instrument signalline with help of multiple smoothed averagesONCE periodFirstMA = 5 // 5 is center of gravity, do not changeONCE periodSecondMA = 10 // 10 is center of gravity, do not changeONCE periodThirdMA = 3 // heartbeat of the instrument// define filter parameterONCE periodLongMA = 150 // period lenght of the long moving average that works as filterONCE periodShortMA = 210 // period lenght of the short moving average that works as filter// define money and position management parameter// dynamic scaling of the chance/risk profile depending on account sizeONCE startRisk = 1//1 // start risk level e.g 0.25 - 25%, 0.5 - 50%, 0.75 - 75%, 1 - 100% and so onONCE maxRisk = 1 // max risk level e.g 1.5 - 150%ONCE increaseRiskLevel = 2000 // amount of profit from which the risk is to be increasedONCE increaseRiskStep = 1.5//1//1//1 // step by which the risk should be increased// size calculation: size = positionSize * trendMultiplier * saisonalPatternMultiplier * scaleFactorONCE positionSize = 1 // default start sizeONCE trendMultiplier = 2 // >1 with dynamic position sizing; 1 withoutONCE maxPositionSizePerTrade = 500 // maximum size per tradeONCE maxPositionSizeLong = 500 // maximum size for long positionsONCE maxPositionSizeShort = 500 // maximum size for short positionsONCE stopLossLong = 1.6//2.8 //in %ONCE stopLossShort = 2.4//2.4 //in %ONCE takeProfitLong = 1.7//1 //in %ONCE takeProfitShort =0.8// 0.8 //in %ONCE trailingStartLong = 0.2 //in %ONCE trailingStartShort = 0.1 //in %ONCE trailingStepLong = 0.1 //in %ONCE trailingStepShort = 0.1 //in %ONCE maxCandlesLongWithProfit = 1//1//1 //take long profit latest after x candlesONCE maxCandlesShortWithProfit = 2//2 // take short profit latest after x candlesONCE maxCandlesLongWithoutProfit = 18 // limit long loss latest after x candlesONCE maxCandlesShortWithoutProfit = 25 // limit short loss latest after x candles// define saisonal position multiplier for each month 1-15 / 16-31 (>0 - long / <0 - short / 0 no trade)ONCE January1 = 3ONCE January2 = 0ONCE February1 = 1ONCE February2 = 3ONCE March1 = 0ONCE March2 = 3ONCE April1 = 3ONCE April2 = 3ONCE May1 = 3ONCE May2 = 1ONCE June1 = 3ONCE June2 = 3ONCE July1 = 0ONCE July2 = 0ONCE August1 = 3ONCE August2 = 3ONCE September1 = 3ONCE September2 = 0ONCE October1 = 3ONCE October2 = 3ONCE November1 = 3ONCE November2 = 2ONCE December1 = 3ONCE December2 = 3// calculate the scaling factor based on the parameterscaleFactor = MIN(maxRisk, MAX(startRisk, ROUND(StrategyProfit / increaseRiskLevel) * increaseRiskStep))// dynamic position sizing based on weekly performanceONCE profitLastWeek = 0IF DayOfWeek <> DayOfWeek[1] AND DayOfWeek = 1 THENIF StrategyProfit > profitLastWeek + 1 THENpositionSize = MIN(trendMultiplier, positionSize + 1) // increase riskELSEpositionSize = MAX(1, positionSize - 1) // decrease riskENDIFprofitLastWeek = strategyProfitENDIF// calculate daily high/low (include sunday values if available)dailyHigh = DHigh(1)dailyLow = DLow(1)previousDailyHigh = DHigh(2)// calculate weekly high, weekly low is a poor signalIf DayOfWeek < DayOfWeek[1] AND lastweekbarindex = 0 THENlastWeekBarIndex = BarIndexELSEIF DayOfWeek < DayOfWeek[1] THENweeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)lastWeekBarIndex = BarIndexENDIFENDIF// calculate monthly high/lowIF Month <> Month[1] AND lastMonthBarIndex=0 THENlastMonthBarIndex=barindexELSIF Month <> Month[1] THENmonthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)lastMonthBarIndex = BarIndexENDIF// calculate instrument signalline with multiple smoothed averagesfirstMA = WilderAverage[periodFirstMA](close)secondMA = TimeSeriesAverage[periodSecondMA](firstMA)signalline = TimeSeriesAverage[periodThirdMA](secondMA)// save position before trading window is openIF Time < startTime THENstartPositionLong = COUNTOFLONGSHARESstartPositionShort = COUNTOFSHORTSHARESENDIF// trade only in defined trading windowIF Time >= startTime AND Time <= endTime THEN// set saisonal multipliercurrentDayOfTheMonth = OpenDaymidOfMonth = 15IF CurrentMonth = 1 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = January1ELSEsaisonalPatternMultiplier = January2ENDIFELSIF CurrentMonth = 2 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = February1ELSEsaisonalPatternMultiplier = February2ENDIFELSIF CurrentMonth = 3 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = March1ELSEsaisonalPatternMultiplier = March2ENDIFELSIF CurrentMonth = 4 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = April1ELSEsaisonalPatternMultiplier = April2ENDIFELSIF CurrentMonth = 5 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = May1ELSEsaisonalPatternMultiplier = May2ENDIFELSIF CurrentMonth = 6 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = June1ELSEsaisonalPatternMultiplier = June2ENDIFELSIF CurrentMonth = 7 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = July1ELSEsaisonalPatternMultiplier = July2ENDIFELSIF CurrentMonth = 8 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = August1ELSEsaisonalPatternMultiplier = August2ENDIFELSIF CurrentMonth = 9 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = September1ELSEsaisonalPatternMultiplier = September2ENDIFELSIF CurrentMonth = 10 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = October1ELSEsaisonalPatternMultiplier = October2ENDIFELSIF CurrentMonth = 11 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = November1ELSEsaisonalPatternMultiplier = November2ENDIFELSIF CurrentMonth = 12 THENIF currentDayOfTheMonth <= midOfMonth THENsaisonalPatternMultiplier = December1ELSEsaisonalPatternMultiplier = December2ENDIFENDIF// define trading filters// 1. use fast and slow averages as filter because not every breakout is profitablef1 = close > Average[periodLongMA](close)f2 = close < Average[periodLongMA](close)f3 = close > Average[periodShortMA](close)// 2. check if position already reduced in trading window as additonal filter criteriaalreadyReducedLongPosition = COUNTOFLONGSHARES < startPositionLongalreadyReducedShortPosition = COUNTOFSHORTSHARES < startPositionShort// long position conditionsl1 = signalline CROSSES OVER monthlyHighl2 = signalline CROSSES OVER weeklyHighl3 = signalline CROSSES OVER dailyHighl4 = signalline CROSSES OVER monthlyLow// short position conditionss1 = signalline CROSSES UNDER monthlyHighs2 = signalline CROSSES UNDER dailyLows3 = signalline CROSSES UNDER previousDailyHigh// long entry with order cumulationIF ( l1 OR l4 OR l2 OR (l3 AND f2) ) AND NOT alreadyReducedLongPosition THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier > 0 THENnumberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize * saisonalPatternMultiplier) * scaleFactor)IF (COUNTOFPOSITION + numberContracts) <= maxPositionSizeLong * scaleFactor THENIF SHORTONMARKET THENEXITSHORT AT MARKETENDIFIF FILTROL THENBUY numberContracts CONTRACT AT MARKETENDIFENDIFELSIF saisonalPatternMultiplier <> 0 THENnumberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize) * scaleFactor)IF (COUNTOFPOSITION + numberContracts) <= maxPositionSizeLong * scaleFactor THENIF SHORTONMARKET THENEXITSHORT AT MARKETENDIFBUY numberContracts CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossLongtakeProfit = takeProfitLongENDIF// short entry with order cumulationIF ( (s1 AND f3) OR (s2 AND f1) OR (s3 AND f3) ) AND NOT alreadyReducedShortPosition THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier < 0 THENnumberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize * ABS(saisonalPatternMultiplier)) * scaleFactor)IF (ABS(COUNTOFPOSITION) + numberContracts) <= maxPositionSizeShort * scaleFactor THENIF LONGONMARKET THENSELL AT MARKETENDIFSELLSHORT numberContracts CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENnumberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize) * scaleFactor)IF (ABS(COUNTOFPOSITION) + numberContracts) <= maxPositionSizeShort * scaleFactor THENIF LONGONMARKET THENSELL AT MARKETENDIFSELLSHORT numberContracts CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossShorttakeProfit = takeProfitShortENDIF// superordinate stop and take profitSET STOP %LOSS stopLossSET TARGET %PROFIT takeProfit// stop and profit managementposProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsizenumberCandles = (BarIndex - TradeIndex)m1 = posProfit > 0 AND numberCandles >= maxCandlesLongWithProfitm2 = posProfit > 0 AND numberCandles >= maxCandlesShortWithProfitm3 = posProfit < 0 AND numberCandles >= maxCandlesLongWithoutProfitm4 = posProfit < 0 AND numberCandles >= maxCandlesShortWithoutProfit// take profit after max candlesIF LONGONMARKET AND (m1 OR m3) THENSELL AT MARKETENDIFIF SHORTONMARKET AND (m2 OR m4) THENEXITSHORT AT MARKETENDIF// trailing stop function (convert % to pips)trailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100// reset the stoploss valueIF NOT ONMARKET THENnewSL = 0ENDIF// manage long positionsIF LONGONMARKET THEN// first move (breakeven)IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THENnewSL = tradeprice(1) + trailingStepLongInPoints * pipsizestopLoss = stopLossLong * 0.1takeProfit = takeProfitLong * 2ENDIF// next movesIF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THENnewSL = newSL + trailingStepLongInPoints * pipsizeENDIFENDIF// manage short positionsIF SHORTONMARKET THEN// first move (breakeven)IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THENnewSL = tradeprice(1) - trailingStepShortInPoints * pipsizeENDIF// next movesIF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THENnewSL = newSL - trailingStepShortInPoints * pipsizeENDIFENDIF// stop order to exit the positionsIF newSL > 0 THENIF LONGONMARKET THENSELL AT newSL STOPENDIFIF SHORTONMARKET THENEXITSHORT AT newSL STOPENDIFENDIFENDIF11/03/2018 at 12:18 PM #84085Gianluca it’s the other way round… all TF’s must be multiple of the main one, which is the lowest one from where the strategy is launched and which must be the current TF on the chart. In your case your default TF CANNOT be 4h! Your code has nothing to do with this issue.
You cannot launch or backtest your MTF strategy from a 4-hour TF if you are using lower TF’s.
If you want to use 4h and 1h, or even 1min, you must launch your strategy from the lowest one!
And you cannot use 4h, 1h and 7mins together, because 4h (240 mins) and 1h (60 mins) are not multiple of 7 minutes! You should use 245/238mins, 63/56mins and 7mins.
11/03/2018 at 5:20 PM #84096ou cannot launch or backtest your MTF strategy from a 4-hour TF if you are using lower TF’s.
If you want to use 4h and 1h, or even 1min, you must launch your strategy from the lowest one!
i have live 5 strategies in this way so how you explain it?
-
AuthorPosts
Find exclusive trading pro-tools on