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!
Hi Tanou
You can run the 3min strategy on a smaller timeframe to get a faster trailing stop. Just make sure you put your main code within the 3min timeframe and launch the script in the smaller timeframe.
Thanks
@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? 🙂
Yes, easy to do as below … very rough, but you get the idea?
Timeframe (3mn, updateonclose)
If Buycond then
Buy at market
Endif
Timeframe (10sec)
Sell at TSCond Stop
PaulParticipant
Master
hi perhaps have a look at barhunter strategy for an idea
Thanks to both of you! 🙂
That’s exactly what I’ve wanted to try @GraHal but I wanted to know if it was possible. I’ll try that then 😉
@Paul, I don’t quite get what you mean by Barhunter…
Do you know which smaller UT than 3 minutes and is a multiple?
You can use any of the selectable Timeframes but the lower one has to divide into the higher TF.
So for example you cant use 2 min as lower and 15 min as higher TF as 2 does not divide into 15.
I 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?
strategy BarHunter DAX v1p
Thanks @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! 😀
9 seconds is no good for anything as it doesn’t divide into 1 minute.
Try 1 min as the lower TF just to get your code working?
30 seconds should work also, and 15 secs and 5 secs.
I just tried one minute and still.. I don’t know which smaller UT I could use.. Seconds doesn’t match with minutes?
@
Tanou
Your chart needs to show the 10 second-TF (or whatever else you prefer, provided 3 minutes is a multiple of that TF).
For instance with this code:
//-------------------------------------------------------------------------
// 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ée
noEntryBeforeTime = 090000
timeEnterBefore = 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ée
noEntryAfterTime = 170000
timeEnterAfter = time < noEntryAfterTime
// Empêche le système de placer de nouveaux ordres sur les jours de la semaine spécifiés
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
//************************************************************************
FOR THE EXAMPLE I'D LIKE THIS PART TO BE IN 3 MINUTES
//************************************************************************
// Calcul Points Pivots 4h
Int = (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 THEN
myLastHigh = myHigh
myLastLow = myLow
myLastClose = Close[1]
myHigh = High
myLow = Low
Premierpassage=0
ELSE
myHigh = Max(myHigh, High)
myLow = Min(myLow, Low)
ENDIF
PP = (myLastHigh + myLastLow + myLastClose) / 3
Res3 = myLastHigh + 2 * (PP - myLastLow)
// Conditions pour ouvrir une position en vente à découvert
c2 = (close CROSSES OVER Res3)
IF c2 AND timeEnterBefore AND timeEnterAfter AND Premierpassage=0 AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
Premierpassage=1
SET STOP pLOSS 35
ENDIF
//************************************************************************
HERE I WOULD LIKE A SMALLER UT THAN THE REST OF THE PREVIOUS CODE
//************************************************************************
//trailing stop function
trailingstart = 3 //trailing will start @trailinstart points profit
trailingstep = 2 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
newSL = tradeprice(1)-trailingstep
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep THEN
newSL = newSL-trailingstep
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
As 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 🙂
PaulParticipant
Master
hi
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.