Multi-Timeframe trailing stop
Forums › ProRealTime English forum › ProOrder support › Multi-Timeframe trailing stop
- This topic has 15 replies, 5 voices, and was last updated 5 years ago by
GraHal.
-
-
10/06/2020 at 7:26 PM #146597
Hello every one,
I hope you are well!
i have a strategy on the DJI in UT3min. In this strategy I have a trailing stop that is, for now and obviously, calculated every 3 minutes which is the UT of the code.
I would like to know if I could code the trailing stop with a smaller timeframe for it to be more reactive or if you think of another solution!
Thank you so much!
10/06/2020 at 8:31 PM #14659810/06/2020 at 9:09 PM #146599Thanks @Eckaw! However if I optimise my stratégie in 3 minutes and launch it in 10 seconds for example it would be execute in 10 seconds and not 3 minutes as optimise and it can change everything..!
what I’d like to know if only the trailing stop part could be on a smaller UT, like 1 minutes or 10 seconds for instance 😉
Do you get it? 🙂
10/06/2020 at 9:47 PM #14660310/06/2020 at 11:22 PM #14660710/07/2020 at 10:15 AM #14663810/07/2020 at 10:23 AM #14664310/07/2020 at 10:51 AM #14664510/07/2020 at 10:56 AM #146646I don’t quite get what you mean by Barhunter…
Paul is referring you to the Algo on the link below, but re which snippet of code … maybe Paul will describe so you can find the snippet?
https://www.prorealcode.com/topic/strategy-barhunter-dax-v1p/
10/07/2020 at 10:56 AM #146647Thanks @GraHal. However I tried to write the trailing stop part in a smaller UT but when I try to bakctest it, the system keeps telling me that I have to use a mutliple of 3 minutes and that’s the problem, I can’t find a multiple of 3minutes which is smaller. I tried 6 / 3 / 9 seconds but it doesn’t want it… Do you know any multiple smaller of 3 minutes but lower?
Thanks so much! 😀
10/07/2020 at 11:16 AM #14664810/07/2020 at 11:49 AM #14665310/07/2020 at 12:02 PM #146657Your chart needs to show the 10 second-TF (or whatever else you prefer, provided 3 minutes is a multiple of that TF).
10/07/2020 at 12:16 PM #146659For instance with this code:
R3 4H123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990//-------------------------------------------------------------------------// Code principal : R3 4H//-------------------------------------------------------------------------//-------------------------------------------------------------------------// Code principal : R3 4H//-------------------------------------------------------------------------DEFPARAM Preloadbars = 5000// Définition des paramètres du code// Cumul des positions désactivéDEFPARAM CumulateOrders = False//************************************************************************//Horaires de trading// Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".DEFPARAM FLATBEFORE = 090000// Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"DEFPARAM FLATAFTER = 170000// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiéenoEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTime// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 170000timeEnterAfter = time < noEntryAfterTime// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiésdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//************************************************************************FOR THE EXAMPLE I'D LIKE THIS PART TO BE IN 3 MINUTES//************************************************************************// Calcul Points Pivots 4hInt = (OpenTime[1] < 010000 AND OpenTime > 010000) OR (OpenTime[1] < 050000 AND OpenTime > 050000) OR (OpenTime[1] < 090000 AND OpenTime > 090000) OR (OpenTime[1] < 130000 AND OpenTime > 130000) OR (OpenTime[1] < 170000 AND OpenTime > 170000) OR (OpenTime[1] < 210000 AND OpenTime > 210000) OR (Openday <> Openday[1] AND DayOfWeek < DayOfWeek[1])IF (OpenTime Mod 40000 = 10000) OR Int THENmyLastHigh = myHighmyLastLow = myLowmyLastClose = Close[1]myHigh = HighmyLow = LowPremierpassage=0ELSEmyHigh = Max(myHigh, High)myLow = Min(myLow, Low)ENDIFPP = (myLastHigh + myLastLow + myLastClose) / 3Res3 = myLastHigh + 2 * (PP - myLastLow)// Conditions pour ouvrir une position en vente à découvertc2 = (close CROSSES OVER Res3)IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT MARKETPremierpassage=1SET STOP pLOSS 35ENDIF//************************************************************************HERE I WOULD LIKE A SMALLER UT THAN THE REST OF THE PREVIOUS CODE//************************************************************************//trailing stop functiontrailingstart = 3 //trailing will start @trailinstart points profittrailingstep = 2 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFAs I wrote it in the code I’d like to get the first part in 3 minutes and the bottom of the code in a smallerUT. I don’t succeed to make it for now.
Could you give me an example with this code? What do you write and in which UT should be the graph?
Thank you so much one more time 🙂
10/07/2020 at 12:34 PM #146661hi Tanou
Now I reread your question, you want it probably different then I thought.
In barhunter, the backtest is done on a 1 hour timerframe, but runs live on 1 minute. The trailing stop is split in the timeframes to work correctly.
Here’s the file if you want to have a look.
-
AuthorPosts
Find exclusive trading pro-tools on