Using MTF for trailing stop
Forums › ProRealTime English forum › ProOrder support › Using MTF for trailing stop
- This topic has 6 replies, 3 voices, and was last updated 6 years ago by Toto le Heros.
Tagged: mtf, multitimeframe, timeframe, trailing, trailing stop
-
-
09/15/2018 at 7:55 AM #80547
Hi,
First of all, big thanks again for the quality of this forum and the excellence of PRT in implementing progressively new functionalities.
MTF (MultiTimeFrame) looks like a very promising one.
I got the idea of using it for a purpose which is not exactly the one it was built for, as far as I understand.
My idea would be to have a strategy opening positions in a TIME FRAME #1 (ie : 15 minutes), BUT to have an associated trailing stop function managed in a (shorter) TIME FRAME #2 (ie. : 1 minute)
In my example 15′ should be the “default” time frame… but based on my trial it looks like it is not working because TimeFrame#2 should be a multiple of TIMEFRAME#1 (default).
Does somebody think there would be a way to manage it so that it is working as per my expectation ?
Any ideas welcome.
BR,
09/15/2018 at 8:42 AM #80548TF # 1 – 15 mins is a multiple of TF 2 – 1 mins so either I have misunderstood what you are saying or your problem is something else??
You would need to be running the System on a Chart TF of 1 min.
If you are trying run on Chart TF of 15 mins then you would get the error message that you got.
09/15/2018 at 11:05 AM #80557You cannot have a 1-minute TF to do something, then launch the default mode on a 15-minute TF, because of these two requirements:
- all TFs need to be multiple of the default TF
- the default (which is the main one, the one to which BarIndex, TradeIndex, history data, …. are related) TF has to be be the lowest one
You’ll have to do the opposite, use the 15-minute TF to run your strategy and launch the default TF on a 1-minute chart to trail SL.
1 user thanked author for this post.
09/17/2018 at 1:22 PM #80695Thank you for your answers. I will try to explain better my case and for this I will use a real example.
So let’s imagine that my goal is to run a strategy which would be the following : from 9am, on DAX UT=15min, I am looking to go short as soon as the lowest and the highest of the current candle are lower than the previous highest and lowest. As soon as the condition is there, the system sets a STOP order 1 point below the close of the current candle. And then I am willing to drive this with a classical “10 points trailing stop”, on a 1 minute timeframe basis (to make a closer monitoring of my position). Clear enough ?
Well, my 1st approach of this is to build the program in the default TF = 15′. And to add at the beginning of the program a TF=1′ section including the trailing stop function only.
If I do this, I am unable to even run a back test : the system returns an error. Somethin like : “All timeframes in the code must be multiples of the graph’s timeframe”
So that I try it the other way around (code attached) with 1′ time frame as default (trailing stop only) and 15′ time frame including main part of the code. Running this program on the 1′ TF leads to positions taken in the 1′ timeframe in fact… (ie. : 5th September at 9.14am, 5th Sept at 11.25am, at 11.38 am, etc.)
Is there a way to program in order to obtain what I am willing to get :
- 15′ TF for positions opening
- 1′ TF for trailing stop management on open positions
MTF SHORT TF TRAILING TEST12345678910111213141516171819202122232425262728293031323334353637383940DEFPARAM CumulateOrders = False // Cumul des positions désactivéDEFPARAM FLATAFTER = 171500//-->15 minutes TFtimeframe(15minutes,updateonclose)noEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTimenoEntryAfterTime = 163000timeEnterAfter = time < noEntryAfterTimedaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions pour ouvrir une position en vente à découvertc1 = high<high[1] and low<low[1]IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT close-1 STOPENDIF// Stops et objectifsSET STOP pLOSS 50SET TARGET pPROFIT 100//-->-->default TF (1 minute)timeframe(default)//trailing stoptrailingstop = 10if not onmarket thenMINPRICE = closepriceexit = 0endifif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=trailingstop*pointsize thenpriceexit = MINPRICE+trailingstop*pointsizeendifendifif onmarket and priceexit>0 thenEXITSHORT AT priceexit STOPendif
09/17/2018 at 2:12 PM #80700It’s because the code is read each minute. Since conditions on the 15-minute TF are valid 15 times, lines 16-18 will be executed each minute. You cannot rely on BARINDEX, since it always refers to the default TF (UT), so you have to work it around as follows:
1. at line 6 insert these lines to mimick BARINDEX:
12ONCE Bar15minute = 0Bar15Minute = Bar15Minute + 12. replace line 16 with
1IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AND TradeON THEN3. between line 25 and 26 insert these lines:
1234567891011ONCE TradeON = 1 //1=trading enabled 0=trading disabledIF IntraDayBarIndex = 0 THENTradeON = 1 //trading enabled at the beginnin of each new dayENDIFTradeBar = Bar15MinuteIF Not OnMarket AND TradeBar <> TradeBar[1] THEN //When not on market and the 15-minute bar changes then reenable tradingTradeON = 1ENDIFIF OnMarket THENTradeON = 0 //disable trading once on marketENDIFThis will prevent more than one trade to be entered within the same 15-minute bar.
09/17/2018 at 2:22 PM #80701This is the complete code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152DEFPARAM CumulateOrders = False // Cumul des positions désactivéDEFPARAM FLATAFTER = 171500//-->15 minutes TFtimeframe(15minutes,updateonclose)ONCE Bar15minute = 0Bar15Minute = Bar15Minute + 1noEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTimenoEntryAfterTime = 163000timeEnterAfter = time < noEntryAfterTimedaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions pour ouvrir une position en vente à découvertc1 = high<high[1] and low<low[1]IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AND TradeON THENSELLSHORT 1 CONTRACT AT close-1 STOPENDIF// Stops et objectifsSET STOP pLOSS 50SET TARGET pPROFIT 100//-->-->default TF (1 minute)timeframe(default)ONCE TradeON = 1 //1=trading enabled 0=trading disabledIF IntraDayBarIndex = 0 THENTradeON = 1 //trading enabled at the beginnin of each new dayENDIFTradeBar = Bar15MinuteIF Not OnMarket AND TradeBar <> TradeBar[1] THEN //When not on market and the 15-minute bar changes then reenable tradingTradeON = 1ENDIFIF OnMarket THENTradeON = 0 //disable trading once on marketENDIF//trailing stoptrailingstop = 10if not onmarket thenMINPRICE = closepriceexit = 0endifif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=trailingstop*pointsize thenpriceexit = MINPRICE+trailingstop*pointsizeendifendifif onmarket and priceexit>0 thenEXITSHORT AT priceexit STOPendif1 user thanked author for this post.
09/17/2018 at 2:22 PM #80702Smart !
Thank you very much Roberto !
-
AuthorPosts
Find exclusive trading pro-tools on