ProRealCode - Trading & Coding with ProRealTime™
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 !
//PARAMETRI
//inserire qui sotto tutti i parametri BASE del codice
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
MioRischio = 100 //importo massimo in euro che voglio rischiare per ogni singola operazione
PercStop1 = 0.50 //attiva il pareggio al 50% del profitto
PercStop2 = 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 TESTARE
IF Not OnMarket THEN
BreakEven = 0
ENDIF
ONCE Flag = 0
IF OnMarket OR LOW < MinimoPat THEN
Flag=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 tradare
AO=Average[5](MedianPrice)-Average[34](MedianPrice)
Cond1 = AO[0]>0
Cond2 = AO[1]<0
CondTOT = Cond1 AND Cond2 //Condizione globale da tradare
IF CondTOT THEN
Flag = 1
ENDIF
//COMPORTAMENTI
//inserire qui sotto come si deve comportare la strategia quando è ONMARKET
IF CondTOT AND Not LongOnMarket THEN
TargetProfit = (HIGH - LOW)/pipsize //VALORE in PIPS del mio TARGET INIZIALE
Prezzo = HIGH //VALORE al quale si entra in posizione se vengono soddisfatte TUTTE le CONDIZIONI
StopLoss = (HIGH - LOW)/pipsize //VALORE in PIPS dello STOP LOSS INIZIALE
MinimoPat = LOW
ENDIF
Moltiplicatore = (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 THEN
BUY Moltiplicatore lots AT (Prezzo+0.0000) STOP //Ordine automatico di ENTRATA LONG in posizione con eventuale aggiunta di pips
ENDIF
//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
//ENDIF
IF LongOnMarket THEN
IF Breakeven=0 AND ((High - Tradeprice) >= (TargetProfit * PercStop1)*pipsize) THEN
Breakeven = Tradeprice + PagoSpese
ENDIF
IF Breakeven>0 AND ((High - Tradeprice) >= (TargetProfit * PercStop2)*pipsize) AND High >= Breakeven + ((TargetProfit * (PercStop2 - PercStop1))*pipsize) THEN
Breakeven = Tradeprice + (TargetProfit/2)
ENDIF
ENDIF
IF OnMarket AND Breakeven>0 THEN
SELL AT Breakeven STOP
ENDIF
SET STOP pLOSS StopLoss
I did not test the below code, but you only need to add the TIMEFRAME instructions to embed the desired code in the desired timeframe!
//PARAMETRI
//inserire qui sotto tutti i parametri BASE del codice
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
MioRischio = 100 //importo massimo in euro che voglio rischiare per ogni singola operazione
PercStop1 = 0.50 //attiva il pareggio al 50% del profitto
PercStop2 = 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 TESTARE
timeframe(daily,updateonclose)
ONCE Flag = 0
IF OnMarket OR LOW < MinimoPat THEN
Flag=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 tradare
AO=Average[5](MedianPrice)-Average[34](MedianPrice)
Cond1 = AO[0]>0
Cond2 = AO[1]<0
CondTOT = Cond1 AND Cond2 //Condizione globale da tradare
IF CondTOT THEN
Flag = 1
ENDIF
//COMPORTAMENTI
//inserire qui sotto come si deve comportare la strategia quando è ONMARKET
IF CondTOT AND Not LongOnMarket THEN
TargetProfit = (HIGH - LOW)/pipsize //VALORE in PIPS del mio TARGET INIZIALE
Prezzo = HIGH //VALORE al quale si entra in posizione se vengono soddisfatte TUTTE le CONDIZIONI
StopLoss = (HIGH - LOW)/pipsize //VALORE in PIPS dello STOP LOSS INIZIALE
MinimoPat = LOW
ENDIF
Moltiplicatore = (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 THEN
BUY Moltiplicatore lots AT (Prezzo+0.0000) STOP //Ordine automatico di ENTRATA LONG in posizione con eventuale aggiunta di pips
ENDIF
//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
//ENDIF
timeframe(default)
IF Not OnMarket THEN
BreakEven = 0
ENDIF
IF LongOnMarket THEN
IF Breakeven=0 AND ((High - Tradeprice) >= (TargetProfit * PercStop1)*pipsize) THEN
Breakeven = Tradeprice + PagoSpese
ENDIF
IF Breakeven>0 AND ((High - Tradeprice) >= (TargetProfit * PercStop2)*pipsize) AND High >= Breakeven + ((TargetProfit * (PercStop2 - PercStop1))*pipsize) THEN
Breakeven = Tradeprice + (TargetProfit/2)
ENDIF
ENDIF
IF OnMarket AND Breakeven>0 THEN
SELL AT Breakeven STOP
ENDIF
SET STOP pLOSS StopLoss
Of course, you’ll have to launch it in the lowest timeframe.
At Line 5
Timeframe (Daily,updateonclose)
and at Line 49
Timeframe (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
Thank 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.
Did 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!? 🙂
Sounds great!
I look forward to ongoing developments and I like the idea of the 3 parts … makes it more manageable and feels not so overwhelming! 🙂
Using the code I attached above called Albert.itf
eurusd
1 min default T
spread = 2
100k bars…
1st Image is with this …
Timeframe (4 Hour, updateonclose)
2nd image is with this (for comparison)
Timeframe (Daily, updateonclose)
You 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.
With this line at the end of the code:
GRAPHONPRICE 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.
Attached shows breakeven as the thick black line … so it appears to be working.
We just need to get more trades now?
That last long trade appears to be following the equity curve?
//PARAMETRI
//inserire qui sotto tutti i parametri BASE del codice
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
MioRischio = 100 //importo massimo in euro che voglio rischiare per ogni singola operazione
PercStop1 = 0.50 //attiva il pareggio al 50% del profitto
PercStop2 = 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 TESTARE
IF Not OnMarket THEN
BreakEven = 0
ENDIF
ONCE Flag = 0
IF OnMarket OR LOW < MinimoPat THEN
Flag=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 tradare
AO=Average[5](MedianPrice)-Average[34](MedianPrice)
Cond1 = AO[0]>0
Cond2 = AO[1]<0
CondTOT = Cond1 AND Cond2 //Condizione globale da tradare
IF CondTOT THEN
Flag = 1
ENDIF
//COMPORTAMENTI
//inserire qui sotto come si deve comportare la strategia quando è ONMARKET
IF CondTOT AND Not LongOnMarket THEN
TargetProfit = (HIGH - LOW)/pipsize //VALORE in PIPS del mio TARGET INIZIALE
Prezzo = HIGH //VALORE al quale si entra in posizione se vengono soddisfatte TUTTE le CONDIZIONI
StopLoss = (HIGH - LOW)/pipsize //VALORE in PIPS dello STOP LOSS INIZIALE
MinimoPat = LOW
ENDIF
Moltiplicatore = (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 THEN
BUY Moltiplicatore lots AT (Prezzo+0.0000) STOP //Ordine automatico di ENTRATA LONG in posizione con eventuale aggiunta di pips
ENDIF
//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
//ENDIF
IF LongOnMarket THEN
IF Breakeven=0 AND ((High[0] - Tradeprice) >= (TargetProfit * PercStop1)*pipsize) THEN
Breakeven = Tradeprice + PagoSpese
ENDIF
IF Breakeven>0 AND ((High[0] - Tradeprice) >= (TargetProfit * PercStop2)*pipsize) AND High[0] >= Breakeven + ((TargetProfit * (PercStop2 - PercStop1))*pipsize) THEN
Breakeven = Tradeprice + ((TargetProfit/2)*pipsize)
ENDIF
ENDIF
IF OnMarket AND Breakeven>0 THEN
SELL AT Breakeven STOP
ENDIF
SET STOP pLOSS StopLoss
//SET TARGET pPROFIT TargetProfit
//SET STOP pTRAILING TargetProfit
graph Breakeven
Multi time frame and trailing stop management
This topic contains 62 replies,
has 5 voices, and was last updated by
robertogozzi
6 years, 5 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 05/21/2019 |
| Status: | Active |
| Attachments: | 21 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.