ProRealCode - Trading & Coding with ProRealTime™
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?
I 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.
Hi
@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)
Where 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.
I 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.
Nicolas,
” 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
Maybe 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!
In the meanwhile, you should always use the below instruction for the lowest timeframe, which in this case is the “default”:
timeframe(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.
Hi
would be possible use daily timeframe and a second time frame of 5 minutes?
How I cuold try my strategy?
thanks a lot
l
Yes, 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
Mes 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
Guys 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 ?????????????
[attachment file=”84082″]
i will post the code as example:
// 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 parameter
DEFPARAM CUMULATEORDERS = true // cumulate orders if not turned off
DEFPARAM PRELOADBARS = 10000
timeframe (1H)
MT = CALL "Main Trend"
FILTROL= MT>CLOSE
timeframe (default)
graph MT COLOURED (229, 43, 80)
// define intraday trading window
ONCE startTime = 90000 // start time of trading window in CET
ONCE endTime = 210000 // end time of trading window in CET
// define instrument signalline with help of multiple smoothed averages
ONCE periodFirstMA = 5 // 5 is center of gravity, do not change
ONCE periodSecondMA = 10 // 10 is center of gravity, do not change
ONCE periodThirdMA = 3 // heartbeat of the instrument
// define filter parameter
ONCE periodLongMA = 150 // period lenght of the long moving average that works as filter
ONCE 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 size
ONCE startRisk = 1//1 // start risk level e.g 0.25 - 25%, 0.5 - 50%, 0.75 - 75%, 1 - 100% and so on
ONCE maxRisk = 1 // max risk level e.g 1.5 - 150%
ONCE increaseRiskLevel = 2000 // amount of profit from which the risk is to be increased
ONCE increaseRiskStep = 1.5//1//1//1 // step by which the risk should be increased
// size calculation: size = positionSize * trendMultiplier * saisonalPatternMultiplier * scaleFactor
ONCE positionSize = 1 // default start size
ONCE trendMultiplier = 2 // >1 with dynamic position sizing; 1 without
ONCE maxPositionSizePerTrade = 500 // maximum size per trade
ONCE maxPositionSizeLong = 500 // maximum size for long positions
ONCE maxPositionSizeShort = 500 // maximum size for short positions
ONCE 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 candles
ONCE maxCandlesShortWithProfit = 2//2 // take short profit latest after x candles
ONCE maxCandlesLongWithoutProfit = 18 // limit long loss latest after x candles
ONCE 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 = 3
ONCE January2 = 0
ONCE February1 = 1
ONCE February2 = 3
ONCE March1 = 0
ONCE March2 = 3
ONCE April1 = 3
ONCE April2 = 3
ONCE May1 = 3
ONCE May2 = 1
ONCE June1 = 3
ONCE June2 = 3
ONCE July1 = 0
ONCE July2 = 0
ONCE August1 = 3
ONCE August2 = 3
ONCE September1 = 3
ONCE September2 = 0
ONCE October1 = 3
ONCE October2 = 3
ONCE November1 = 3
ONCE November2 = 2
ONCE December1 = 3
ONCE December2 = 3
// calculate the scaling factor based on the parameter
scaleFactor = MIN(maxRisk, MAX(startRisk, ROUND(StrategyProfit / increaseRiskLevel) * increaseRiskStep))
// dynamic position sizing based on weekly performance
ONCE profitLastWeek = 0
IF DayOfWeek <> DayOfWeek[1] AND DayOfWeek = 1 THEN
IF StrategyProfit > profitLastWeek + 1 THEN
positionSize = MIN(trendMultiplier, positionSize + 1) // increase risk
ELSE
positionSize = MAX(1, positionSize - 1) // decrease risk
ENDIF
profitLastWeek = strategyProfit
ENDIF
// 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 signal
If DayOfWeek < DayOfWeek[1] AND lastweekbarindex = 0 THEN
lastWeekBarIndex = BarIndex
ELSE
IF DayOfWeek < DayOfWeek[1] THEN
weeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)
lastWeekBarIndex = BarIndex
ENDIF
ENDIF
// calculate monthly high/low
IF Month <> Month[1] AND lastMonthBarIndex=0 THEN
lastMonthBarIndex=barindex
ELSIF Month <> Month[1] THEN
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
lastMonthBarIndex = BarIndex
ENDIF
// calculate instrument signalline with multiple smoothed averages
firstMA = WilderAverage[periodFirstMA](close)
secondMA = TimeSeriesAverage[periodSecondMA](firstMA)
signalline = TimeSeriesAverage[periodThirdMA](secondMA)
// save position before trading window is open
IF Time < startTime THEN
startPositionLong = COUNTOFLONGSHARES
startPositionShort = COUNTOFSHORTSHARES
ENDIF
// trade only in defined trading window
IF Time >= startTime AND Time <= endTime THEN
// set saisonal multiplier
currentDayOfTheMonth = OpenDay
midOfMonth = 15
IF CurrentMonth = 1 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = January1
ELSE
saisonalPatternMultiplier = January2
ENDIF
ELSIF CurrentMonth = 2 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = February1
ELSE
saisonalPatternMultiplier = February2
ENDIF
ELSIF CurrentMonth = 3 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = March1
ELSE
saisonalPatternMultiplier = March2
ENDIF
ELSIF CurrentMonth = 4 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = April1
ELSE
saisonalPatternMultiplier = April2
ENDIF
ELSIF CurrentMonth = 5 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = May1
ELSE
saisonalPatternMultiplier = May2
ENDIF
ELSIF CurrentMonth = 6 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = June1
ELSE
saisonalPatternMultiplier = June2
ENDIF
ELSIF CurrentMonth = 7 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = July1
ELSE
saisonalPatternMultiplier = July2
ENDIF
ELSIF CurrentMonth = 8 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = August1
ELSE
saisonalPatternMultiplier = August2
ENDIF
ELSIF CurrentMonth = 9 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = September1
ELSE
saisonalPatternMultiplier = September2
ENDIF
ELSIF CurrentMonth = 10 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = October1
ELSE
saisonalPatternMultiplier = October2
ENDIF
ELSIF CurrentMonth = 11 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = November1
ELSE
saisonalPatternMultiplier = November2
ENDIF
ELSIF CurrentMonth = 12 THEN
IF currentDayOfTheMonth <= midOfMonth THEN
saisonalPatternMultiplier = December1
ELSE
saisonalPatternMultiplier = December2
ENDIF
ENDIF
// define trading filters
// 1. use fast and slow averages as filter because not every breakout is profitable
f1 = 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 criteria
alreadyReducedLongPosition = COUNTOFLONGSHARES < startPositionLong
alreadyReducedShortPosition = COUNTOFSHORTSHARES < startPositionShort
// long position conditions
l1 = signalline CROSSES OVER monthlyHigh
l2 = signalline CROSSES OVER weeklyHigh
l3 = signalline CROSSES OVER dailyHigh
l4 = signalline CROSSES OVER monthlyLow
// short position conditions
s1 = signalline CROSSES UNDER monthlyHigh
s2 = signalline CROSSES UNDER dailyLow
s3 = signalline CROSSES UNDER previousDailyHigh
// long entry with order cumulation
IF ( l1 OR l4 OR l2 OR (l3 AND f2) ) AND NOT alreadyReducedLongPosition THEN
// check saisonal booster setup and max position size
IF saisonalPatternMultiplier > 0 THEN
numberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize * saisonalPatternMultiplier) * scaleFactor)
IF (COUNTOFPOSITION + numberContracts) <= maxPositionSizeLong * scaleFactor THEN
IF SHORTONMARKET THEN
EXITSHORT AT MARKET
ENDIF
IF FILTROL THEN
BUY numberContracts CONTRACT AT MARKET
ENDIF
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
numberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize) * scaleFactor)
IF (COUNTOFPOSITION + numberContracts) <= maxPositionSizeLong * scaleFactor THEN
IF SHORTONMARKET THEN
EXITSHORT AT MARKET
ENDIF
BUY numberContracts CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stopLossLong
takeProfit = takeProfitLong
ENDIF
// short entry with order cumulation
IF ( (s1 AND f3) OR (s2 AND f1) OR (s3 AND f3) ) AND NOT alreadyReducedShortPosition THEN
// check saisonal booster setup and max position size
IF saisonalPatternMultiplier < 0 THEN
numberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize * ABS(saisonalPatternMultiplier)) * scaleFactor)
IF (ABS(COUNTOFPOSITION) + numberContracts) <= maxPositionSizeShort * scaleFactor THEN
IF LONGONMARKET THEN
SELL AT MARKET
ENDIF
SELLSHORT numberContracts CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
numberContracts = MAX(1, MIN(maxPositionSizePerTrade, positionSize) * scaleFactor)
IF (ABS(COUNTOFPOSITION) + numberContracts) <= maxPositionSizeShort * scaleFactor THEN
IF LONGONMARKET THEN
SELL AT MARKET
ENDIF
SELLSHORT numberContracts CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stopLossShort
takeProfit = takeProfitShort
ENDIF
// superordinate stop and take profit
SET STOP %LOSS stopLoss
SET TARGET %PROFIT takeProfit
// stop and profit management
posProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsize
numberCandles = (BarIndex - TradeIndex)
m1 = posProfit > 0 AND numberCandles >= maxCandlesLongWithProfit
m2 = posProfit > 0 AND numberCandles >= maxCandlesShortWithProfit
m3 = posProfit < 0 AND numberCandles >= maxCandlesLongWithoutProfit
m4 = posProfit < 0 AND numberCandles >= maxCandlesShortWithoutProfit
// take profit after max candles
IF LONGONMARKET AND (m1 OR m3) THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET AND (m2 OR m4) THEN
EXITSHORT AT MARKET
ENDIF
// trailing stop function (convert % to pips)
trailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100
trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100
trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100
trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100
// reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
ENDIF
// manage long positions
IF LONGONMARKET THEN
// first move (breakeven)
IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THEN
newSL = tradeprice(1) + trailingStepLongInPoints * pipsize
stopLoss = stopLossLong * 0.1
takeProfit = takeProfitLong * 2
ENDIF
// next moves
IF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THEN
newSL = newSL + trailingStepLongInPoints * pipsize
ENDIF
ENDIF
// manage short positions
IF SHORTONMARKET THEN
// first move (breakeven)
IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THEN
newSL = tradeprice(1) - trailingStepShortInPoints * pipsize
ENDIF
// next moves
IF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THEN
newSL = newSL - trailingStepShortInPoints * pipsize
ENDIF
ENDIF
// stop order to exit the positions
IF newSL > 0 THEN
IF LONGONMARKET THEN
SELL AT newSL STOP
ENDIF
IF SHORTONMARKET THEN
EXITSHORT AT newSL STOP
ENDIF
ENDIF
ENDIF
Gianluca 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.
ou 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?
[beta-testing] multi timeframe support for automatic trading, ideas are welcome!
This topic contains 287 replies,
has 47 voices, and was last updated by Brianoshea
5 years, 10 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 03/19/2018 |
| Status: | Active |
| Attachments: | 48 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.