Multi time frame and trailing stop management
Forums › ProRealTime English forum › ProOrder support › Multi time frame and trailing stop management
- This topic has 62 replies, 5 voices, and was last updated 6 years ago by
robertogozzi.
-
-
05/21/2019 at 2:03 PM #99017
Ciao Nicolas,After a lot of posts and the very precious help from Roberto, finally my system works well. But now it remains a BIG problem concerning the management of the trailing stop. I understand that PRT has to wait for the current candle to close in order to carry out the processing and if necessary move the value of the trailing stop. In many cases this delay leads to major differences in the overall performance of the system. The solution to this problem could be the new PRT multi timeframe function. I would therefore need your kind help in this regard to understand how to proceed with the modification of my active system. Up until line 43 everything works fine. However, at this point I would like to switch from the daily time frame to a 1 minute time frame to more quickly check price changes and quickly adjust the level of trailing stops. Could you please tell me what to write in the system in order to use the 1 minute timeframe from line 49. Thank you very much for your kind help. Thank you. GRAZIE !
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162//PARAMETRI//inserire qui sotto tutti i parametri BASE del codice// Definizione dei parametri del codiceDEFPARAM CumulateOrders = False // Posizioni cumulate disattivateMioRischio = 100 //importo massimo in euro che voglio rischiare per ogni singola operazionePercStop1 = 0.50 //attiva il pareggio al 50% del profittoPercStop2 = 0.80 //attiva lo SL a metà del profitto quanto questo ragguinge la seconda %PagoSpese = 0.0005 //numero di pips che aggiungo al breakeven per ripagarmi delle spese//DEFPARAM FlatAfter = 220000 //Range orario DOPO il quale non bisogna più essere in posizione (eventuale)//DEFPARAM FLATBEFORE = 090000 //Range orario PRIMA del quale non bisogna ancora essere in posizione (eventuale)//INSERIRE EVENTUALE PARAMETRO DAY OF THE WEEK PER ULTERIORE FILTRO DA TESTAREIF Not OnMarket THENBreakEven = 0ENDIFONCE Flag = 0IF OnMarket OR LOW < MinimoPat THENFlag=0 //Azzerare il prezzo serve a non inserire ancora l'ordine pendente...ENDIF //... una volta entrato oppure quando non ci sono più le condizioni//IF Not OnMarket THEN//BreakEven = 0//ENDIF//CONDIZIONI//inserire qui sotto tutte le condizioni che caratterizzano il pattern o la strategia da tradareAO=Average[5](MedianPrice)-Average[34](MedianPrice)Cond1 = AO[0]>0Cond2 = AO[1]<0CondTOT = Cond1 AND Cond2 //Condizione globale da tradareIF CondTOT THENFlag = 1ENDIF//COMPORTAMENTI//inserire qui sotto come si deve comportare la strategia quando è ONMARKETIF CondTOT AND Not LongOnMarket THENTargetProfit = (HIGH - LOW)/pipsize //VALORE in PIPS del mio TARGET INIZIALEPrezzo = HIGH //VALORE al quale si entra in posizione se vengono soddisfatte TUTTE le CONDIZIONIStopLoss = (HIGH - LOW)/pipsize //VALORE in PIPS dello STOP LOSS INIZIALEMinimoPat = LOWENDIFMoltiplicatore = (MioRischio/(StopLoss/Prezzo)/pipsize) //QUANTITA' dello strumento da negoziare per avere in caso di perdita un valore//corrispondente a MIORISCHIO (nei parametri iniziali)IF not onmarket AND Flag THENBUY Moltiplicatore lots AT (Prezzo+0.0000) STOP //Ordine automatico di ENTRATA LONG in posizione con eventuale aggiunta di pipsENDIF//IF LongOnMarket AND ((close - Tradeprice) >= (TargetProfit * PercStop2)) THEN//IF LongOnMarket THEN//Breakeven = max(BreakEven,Tradeprice + (TargetProfit / 2)) //mettere al sicuro il 50% del profitto (è un BreakEven + metà profitto)//ENDIF//ENDIFIF LongOnMarket THENIF Breakeven=0 AND ((High - Tradeprice) >= (TargetProfit * PercStop1)*pipsize) THENBreakeven = Tradeprice + PagoSpeseENDIFIF Breakeven>0 AND ((High - Tradeprice) >= (TargetProfit * PercStop2)*pipsize) AND High >= Breakeven + ((TargetProfit * (PercStop2 - PercStop1))*pipsize) THENBreakeven = Tradeprice + (TargetProfit/2)ENDIFENDIFIF OnMarket AND Breakeven>0 THENSELL AT Breakeven STOPENDIFSET STOP pLOSS StopLoss05/21/2019 at 3:30 PM #99030I did not test the below code, but you only need to add the TIMEFRAME instructions to embed the desired code in the desired timeframe!
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667//PARAMETRI//inserire qui sotto tutti i parametri BASE del codice// Definizione dei parametri del codiceDEFPARAM CumulateOrders = False // Posizioni cumulate disattivateMioRischio = 100 //importo massimo in euro che voglio rischiare per ogni singola operazionePercStop1 = 0.50 //attiva il pareggio al 50% del profittoPercStop2 = 0.80 //attiva lo SL a metà del profitto quanto questo ragguinge la seconda %PagoSpese = 0.0005 //numero di pips che aggiungo al breakeven per ripagarmi delle spese//DEFPARAM FlatAfter = 220000 //Range orario DOPO il quale non bisogna più essere in posizione (eventuale)//DEFPARAM FLATBEFORE = 090000 //Range orario PRIMA del quale non bisogna ancora essere in posizione (eventuale)//INSERIRE EVENTUALE PARAMETRO DAY OF THE WEEK PER ULTERIORE FILTRO DA TESTAREtimeframe(daily,updateonclose)ONCE Flag = 0IF OnMarket OR LOW < MinimoPat THENFlag=0 //Azzerare il prezzo serve a non inserire ancora l'ordine pendente...ENDIF //... una volta entrato oppure quando non ci sono più le condizioni//IF Not OnMarket THEN//BreakEven = 0//ENDIF//CONDIZIONI//inserire qui sotto tutte le condizioni che caratterizzano il pattern o la strategia da tradareAO=Average[5](MedianPrice)-Average[34](MedianPrice)Cond1 = AO[0]>0Cond2 = AO[1]<0CondTOT = Cond1 AND Cond2 //Condizione globale da tradareIF CondTOT THENFlag = 1ENDIF//COMPORTAMENTI//inserire qui sotto come si deve comportare la strategia quando è ONMARKETIF CondTOT AND Not LongOnMarket THENTargetProfit = (HIGH - LOW)/pipsize //VALORE in PIPS del mio TARGET INIZIALEPrezzo = HIGH //VALORE al quale si entra in posizione se vengono soddisfatte TUTTE le CONDIZIONIStopLoss = (HIGH - LOW)/pipsize //VALORE in PIPS dello STOP LOSS INIZIALEMinimoPat = LOWENDIFMoltiplicatore = (MioRischio/(StopLoss/Prezzo)/pipsize) //QUANTITA' dello strumento da negoziare per avere in caso di perdita un valore//corrispondente a MIORISCHIO (nei parametri iniziali)IF not onmarket AND Flag THENBUY Moltiplicatore lots AT (Prezzo+0.0000) STOP //Ordine automatico di ENTRATA LONG in posizione con eventuale aggiunta di pipsENDIF//IF LongOnMarket AND ((close - Tradeprice) >= (TargetProfit * PercStop2)) THEN//IF LongOnMarket THEN//Breakeven = max(BreakEven,Tradeprice + (TargetProfit / 2)) //mettere al sicuro il 50% del profitto (è un BreakEven + metà profitto)//ENDIF//ENDIFtimeframe(default)IF Not OnMarket THENBreakEven = 0ENDIFIF LongOnMarket THENIF Breakeven=0 AND ((High - Tradeprice) >= (TargetProfit * PercStop1)*pipsize) THENBreakeven = Tradeprice + PagoSpeseENDIFIF Breakeven>0 AND ((High - Tradeprice) >= (TargetProfit * PercStop2)*pipsize) AND High >= Breakeven + ((TargetProfit * (PercStop2 - PercStop1))*pipsize) THENBreakeven = Tradeprice + (TargetProfit/2)ENDIFENDIFIF OnMarket AND Breakeven>0 THENSELL AT Breakeven STOPENDIFSET STOP pLOSS StopLossOf course, you’ll have to launch it in the lowest timeframe.
05/21/2019 at 3:36 PM #99035At Line 5
1Timeframe (Daily,updateonclose)and at Line 49
1Timeframe (1mn)You will need to run the System on 1 min Timeframe.
You will also need to rename (e.g. add 1mn to the variable name) the variables occuring / being used in the two TFs as you can’t use the same variable name in 2 TF’s.
Let us know how you get onplease
05/22/2019 at 1:32 PM #99162Thank you very much for your answers. You are very kind and I really appreciate your help. I will try as soon as possible to modify my system following your instructions. Using multi timeframes is the only way to quickly check price changes and adjust the trailing stop value without delay or are there other ways to move trailing quickly? How do you manage the trailing stop values in your systems? My trailing stop management is very simple. When I reach half of my initial target I move the stop loss to the entry price and when I reach 80% of the initial target I move the stop loss to half of the initial target and at the same time start the trailing stop. What do you think of this my risk management? Is it possible to get it without using the multi timeframe? do you have any other suggestions to give me or is the 1 minute time frame still the best solution? (I refer to lines 49 to 55). Thank you again for your answers and I will let you know how my tests progress. Grazie. Ciao.
05/26/2019 at 10:36 AM #99446Did you get this System at least trading Albert FX?
I still had it in my List and I am having a clearout … they build up so quickly! 🙂
I had a play for 10 mins and got it trading, attached is the .itf file running on 4 hour default and Daily.
Attached may be useful and you can improve.
There is something very strange … the equity curve shows a profit, but the Detailed Report shows a loss.
I feel like my coffee has not woken me up yet and I am missing something very obvious!? 🙂
05/27/2019 at 2:33 PM #99527Indeed it is very strange. I’ll try some more tests. In reality the system was designed to trade Forex with 4 hour timeframes using the signals of Bill Williams fractals and in this way it should work well with good profits but I don’t know if it could work just as well with other instruments. Then I had big money management problems because after many tests I realized that the system waits for the completion of the candle to calculate and eventually shift the level of trailingstop, and the results I obtained were not real. Fortunately, now with the new multitimeframe version this kind of problem should be solved, and thanks to your help I’m going in the right direction. The current version of this my system is just a simple example with few conditions created just to understand the operation of the trailingstop in order not to have a too complex code that could create confusion by publishing the various requests on the forum. Initially I had thought of dividing my system into three parts. The first are the basic parameters (and I would also like to use the day of the week as a filter as Larry Williams does to see if there are more profitable days than others). The second part contains the entry conditions, so it is sufficient to replace them to try many price patterns (hikkake, IDNR4, Pop Gun, 123 Joe Ross …) and see if there are better configurations than others. The last part concerns the money management which currently has a take profit and a stop loss which correspond to the range of the setup candle but which in the final version will be replaced by the ATR trying to optimize them in the various combinations with steps of 0.5 (1ATR TP + 1ATR SL or 1.5 ATR TP + 1ATR SL etc …) with the trailing stop that starts when 50% of the initial target is reached, as I wrote in my previous post. This is why my system is not 100% functional but for the moment it has only a didactic purpose. When I understand well, planning the trailing stop I will start with the real tests with the Fractals and the ATR for money management. I will surely keep you informed on how my trials proceed and if in the meantime you have any suggestions for me I am always ready to listen to you. GRAZIE !!05/27/2019 at 4:13 PM #9953505/28/2019 at 11:21 AM #99583I thank you for the answer and I’m glad you appreciate my method of code management. I think that it is much easier to make changes and make quick tests when a new trading idea comes to us. I will keep you fully informed of any development of my system in order to share my experiences with you and possibly with other forum members. I wanted to ask you if you had discovered the reason for the difference between the result of equity curve and the list of trades. When maybe you have a minute you could please try running my code on EURUSD (4 hour timeframe, with the trailingstop check in 1 minute) and see what happens? I will do my best to fix my code as soon as possible, putting the fractal as the entry condition and the ATR as an indicator for the profit target so you can, if you like, check if everything is correct and maybe give me some important advice on how to possibly improve it. When the system is working properly, I will immediately start trying all the possible combinations between the main currency pairs, the days of the week and the size of the ATR as take profit and stop loss, so we can finally also talk about system performances and not just how to make it work.CIAO, GRAZIE !!05/28/2019 at 12:37 PM #99589Using the code I attached above called Albert.itf
eurusd
1 min default T
spread = 2
100k bars…1st Image is with this …
1Timeframe (4 Hour, updateonclose)2nd image is with this (for comparison)
1Timeframe (Daily, updateonclose)05/28/2019 at 1:53 PM #99597Thank you for trying to run my code, you are very kind, but as I wrote to you before this is just an example code to understand the function of the various commands. As you have surely seen, in lines 24-25-26 the entry conditions are simply based on crossing the zero line of Bill Williams’ Awesome oscillators. Now that I will replace this type of entry with the crossing of the fractal line and I will (I hope) fix the trailing stop, most likely we will get the results we expect. I take this opportunity to ask you again for a little help. In lines 58 and 59 of my code I tried to set my trailing stop by replicating the one created by Nicolas. But I think I didn’t understand one thing … Does the value called “trailing start” represent the number of pips to which the trailing stop is added? Or is it the point from which it begins to move automatically? I’ll give you a practical example: my trade price is 1,1200 and my initial target is 1,1300. When I reach 50% of my initial target (ie 1.1250) I move my stop loss to the value of the trade price (and this is done from lines 55 and 56 and currently works well). When I reach 80% of my initial target (ie 1.1280) I would like to start the trailing stop from the 1.1250 level. In this case the “trailingstart” value is 1.1280 or 1.1250 ?? And if the trailingstart is 1.1280 how can I tell the system to start going up from 1.1250? Thank you very much for the help you are giving me and I hope as soon as possible to share an updated version of my code with you so we can see the results and any improvements together. CIAO, GRAZIE.05/28/2019 at 2:04 PM #99599You should use both GRAPH and GRAPHONPRICE extensively to monitor all the variables you need to, candle by candle.
You’ll find out easily and faster their behavior.
1 user thanked author for this post.
05/29/2019 at 7:49 AM #99645With this line at the end of the code:
1GRAPHONPRICE breakeven as "my trailing stop price"you’ll get the exact price of your trailing stop plotted on the price chart, in order to understand how it behaves.
1 user thanked author for this post.
05/29/2019 at 9:43 AM #9965105/29/2019 at 1:39 PM #99660CIAO, Thank you very much for your kind answers. I followed your advice and I put the values of the “breakeven” variable on the chart and I can confirm that unfortunately it still doesn’t work. My system correctly moves the initial stoploss to the value of the trade price when I reach 50% of the initial target. When then I reach 80% of the initial target the system moves the stop from my trade price to 50% of the target but then this value does not move anymore. I am attaching two screens where this big problem is clearly seen. In the list of completed trades, there are some trades with an abnormal duration, for example 36 days and also 10, 11, 20, 15 days. In all these operations the stop loss has been correctly shifted to 50% of my initial target (in fact the Abs Perf corresponds to around 50 euros which is half of my target) but then it remained there. In the graph that I attach, it is clear that I opened a position on April 27th 2015. Then the price rose a lot, producing a considerable profit but the trailing did not follow this climb. In fact, the transaction was closed on 25 May 2015 when the price turned back and touched the stop positioned at 50% of the initial target. This could have been a very profitable operation and instead it would have earned me only 50 euros. And like this all the other operations that last many days. Surely the problem is found in lines 58 and 59. I hope that NIcolas who invented the coding of the trailing stop or anyone else can help me correct this strange and wrong behavior. As soon as possible I will modify the entry conditions by putting the fractal and the target profit using the ATR and then I will send you the new code. In the meantime, I hope someone can help me fix the trailing. GRAZIE !!!123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566//PARAMETRI//inserire qui sotto tutti i parametri BASE del codice// Definizione dei parametri del codiceDEFPARAM CumulateOrders = False // Posizioni cumulate disattivateMioRischio = 100 //importo massimo in euro che voglio rischiare per ogni singola operazionePercStop1 = 0.50 //attiva il pareggio al 50% del profittoPercStop2 = 0.80 //attiva lo SL a metà del profitto quanto questo ragguinge la seconda %PagoSpese = 0.0005 //numero di pips che aggiungo al breakeven per ripagarmi delle spese//DEFPARAM FlatAfter = 220000 //Range orario DOPO il quale non bisogna più essere in posizione (eventuale)//DEFPARAM FLATBEFORE = 090000 //Range orario PRIMA del quale non bisogna ancora essere in posizione (eventuale)//INSERIRE EVENTUALE PARAMETRO DAY OF THE WEEK PER ULTERIORE FILTRO DA TESTAREIF Not OnMarket THENBreakEven = 0ENDIFONCE Flag = 0IF OnMarket OR LOW < MinimoPat THENFlag=0 //Azzerare il prezzo serve a non inserire ancora l'ordine pendente...ENDIF //... una volta entrato oppure quando non ci sono più le condizioni//IF Not OnMarket THEN//BreakEven = 0//ENDIF//CONDIZIONI//inserire qui sotto tutte le condizioni che caratterizzano il pattern o la strategia da tradareAO=Average[5](MedianPrice)-Average[34](MedianPrice)Cond1 = AO[0]>0Cond2 = AO[1]<0CondTOT = Cond1 AND Cond2 //Condizione globale da tradareIF CondTOT THENFlag = 1ENDIF//COMPORTAMENTI//inserire qui sotto come si deve comportare la strategia quando è ONMARKETIF CondTOT AND Not LongOnMarket THENTargetProfit = (HIGH - LOW)/pipsize //VALORE in PIPS del mio TARGET INIZIALEPrezzo = HIGH //VALORE al quale si entra in posizione se vengono soddisfatte TUTTE le CONDIZIONIStopLoss = (HIGH - LOW)/pipsize //VALORE in PIPS dello STOP LOSS INIZIALEMinimoPat = LOWENDIFMoltiplicatore = (MioRischio/(StopLoss/Prezzo)/pipsize) //QUANTITA' dello strumento da negoziare per avere in caso di perdita un valore//corrispondente a MIORISCHIO (nei parametri iniziali)IF not onmarket AND Flag THENBUY Moltiplicatore lots AT (Prezzo+0.0000) STOP //Ordine automatico di ENTRATA LONG in posizione con eventuale aggiunta di pipsENDIF//IF LongOnMarket AND ((close - Tradeprice) >= (TargetProfit * PercStop2)) THEN//IF LongOnMarket THEN//Breakeven = max(BreakEven,Tradeprice + (TargetProfit / 2)) //mettere al sicuro il 50% del profitto (è un BreakEven + metà profitto)//ENDIF//ENDIFIF LongOnMarket THENIF Breakeven=0 AND ((High[0] - Tradeprice) >= (TargetProfit * PercStop1)*pipsize) THENBreakeven = Tradeprice + PagoSpeseENDIFIF Breakeven>0 AND ((High[0] - Tradeprice) >= (TargetProfit * PercStop2)*pipsize) AND High[0] >= Breakeven + ((TargetProfit * (PercStop2 - PercStop1))*pipsize) THENBreakeven = Tradeprice + ((TargetProfit/2)*pipsize)ENDIFENDIFIF OnMarket AND Breakeven>0 THENSELL AT Breakeven STOPENDIFSET STOP pLOSS StopLoss//SET TARGET pPROFIT TargetProfit//SET STOP pTRAILING TargetProfitgraph Breakeven05/29/2019 at 1:41 PM #99663 -
AuthorPosts
Find exclusive trading pro-tools on