Wrong entries. Help to fix de code.
Forums › ProRealTime English forum › ProOrder support › Wrong entries. Help to fix de code.
- This topic has 3 replies, 2 voices, and was last updated 6 years ago by TempusFugit.
-
-
11/12/2017 at 5:11 PM #52451
Hi everyone,
I am trying to put together a code, based on the RSI, and applying some daily averaging down in both directions. I am trying to averaging down within the same day to avoid uncontrolled losses and limit the number of contracts.
I am still in the middle of the process, but after trying a couple of versions, I am getting wrong entries of just 1€. I have no idea why this is happening. I am attaching the results of one of the tries, so you can see the entries, and also the code as it is right now.
I would appreciate any help or feedback about these false entries.
Thanks,
Juan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107// Código principal : RSI w daily averaging 15' EUR 12NOV//-------------------------------------------------------------------------DEFPARAM CUMULATEORDERS = true// OPERATIONAL TIMEDEFPARAM FLATBEFORE = 020000DEFPARAM FLATAFTER = 210000// STRATEGYPROFIT per day. It resets the variable each new dayIF INTRADAYBARINDEX = 0 THENstratprofit = STRATEGYPROFIT //saves the previous day ProfitENDIF// POSITION SIZEpositionsize = 1// PROFITsprofit1 = 10profit2 = 12profit3 = 14profit4 = 20// Condiciones// Alcistasrsialc1 = RSI[2](close)<2decreasinghighs = high<high[1] AND high[1]<high[2] AND high[2]<high[3]alcista = rsialc1 AND decreasinghighsenrojoalcista1= (tradeprice(1)-close)>5*pipsize AND (tradeprice(1)-close)<=10*pipsizeenrojoalcista2= (tradeprice(1)-close)>10*pipsize AND (tradeprice(1)-close)<=20*pipsizeenrojoalcista3= (tradeprice(1)-close)>20*pipsize AND (tradeprice(1)-close)<=30*pipsizetresvelasalcistas = open[1]<close[1] AND open[2]<close[2]rangoverde = (close[1]-open[3])>40*pipsizefastalza = tresvelasalcistas AND rangoverde// Bajistasrsibaj1 = RSI[2](close)>98increasinglows = low>low[1] AND low[1]>low[2] AND low[2]>low[3]bajista = rsibaj1 AND increasinglowsenrojobajista1= (close-tradeprice(1))>5*pipsize AND (close-tradeprice(1))<=10*pipsizeenrojobajista2= (close-tradeprice(1))>10*pipsize AND (close-tradeprice(1))<=20*pipsizeenrojobajista3= (close-tradeprice(1))>20*pipsize AND (close-tradeprice(1))<=30*pipsizetresvelasbajistas = open[1]>close[1] AND open[2]>close[2]rangorojo = (open[3]-close[1])>40*pipsizefastbaja = tresvelasbajistas AND rangorojo// LONG Positions-Opening_________________________________________________________________________________________________// AlcistasIF alcista AND NOT fastbaja THENBUY positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit1ENDIF// AveragingIF LONGONMARKET AND RSI[2](close)<5 AND COUNTOFLONGSHARES<=2 AND enrojoalcista1 THENBUY positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit2ENDIFIF LONGONMARKET AND RSI[2](close)<5 AND COUNTOFLONGSHARES<=3 AND enrojoalcista2 THENBUY positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit3ENDIFIF LONGONMARKET AND RSI[2](close)<5 AND COUNTOFLONGSHARES<=4 AND enrojoalcista3 THENBUY positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit4ENDIF// SHORT Positions-Opening_________________________________________________________________________________________________// BajistasIF bajista AND NOT fastalza THENSELLSHORT positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit1ENDIF// AveragingIF SHORTONMARKET AND RSI[2](close)>95 AND COUNTOFSHORTSHARES<=2 AND enrojobajista1 THENSELLSHORT positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit2ENDIFIF SHORTONMARKET AND RSI[2](close)>95 AND COUNTOFSHORTSHARES<=3 AND enrojobajista2 THENSELLSHORT positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit3ENDIFIF SHORTONMARKET AND RSI[2](close)>95 AND COUNTOFSHORTSHARES<=4 AND enrojobajista3 THENSELLSHORT positionsize CONTRACT AT MARKETSET TARGET pPROFIT profit4ENDIF//Finishing DAILY operations when reaching target profit/lossIF (STRATEGYPROFIT-stratprofit)>=10 THEN //current day's profitSELL AT MARKETEXITSHORT AT MARKETENDIFIF (STRATEGYPROFIT-stratprofit)<=-20 THEN //current day's lossSELL AT MARKETEXITSHORT AT MARKETENDIF11/12/2017 at 6:47 PM #52458Hola Juan,
Creo que tu problema está en las últimas líneas. Quieres que el sistema no haga más operaciones cuando se alcance un determinado beneficio/pérdida en el día, pero tal y como está programado aunque se haya alcanzado ese límite diario se sigue ejecutando la operación sólo que inmediatamente la cierra, con el consiguiente beneficio/pérdida de 1 € (quizás el spread). Para que no se ejecuten más operaciones al llegar a esos límites, que es lo que quieres, se me ocurre por ejemplo añadir una nueva variable en esas líneas finales, tal que así:
//Finishing DAILY operations when reaching target profit/loss
IF (STRATEGYPROFIT-stratprofit)>=10 THEN //current day’s profit
NOTRADES = 1
ENDIFIF (STRATEGYPROFIT-stratprofit)<=-20 THEN //current day’s loss
NOTRADES = 1
ENDIFY hacer que vuelva a “0” esa variable al principio de cada día, añadiendo a las líneas iniciales:
// STRATEGYPROFIT per day. It resets the variable each new day
IF INTRADAYBARINDEX = 0 THENNOTRADES = 0
stratprofit = STRATEGYPROFIT //saves the previous day Profit
ENDIFY añadiendo esa condición a las líneas de ejecución, claro:
// LONG Positions-Opening_________________________________________________________________________________________________
// Alcistas
IF alcista AND NOT fastbaja AND NOTRADE=0 THEN
BUY positionsize CONTRACT AT MARKET
SET TARGET pPROFIT profit1
ENDIFY al resto de ejecuciones.
Tu sistema parece muy prometedor, espero poder verlo ya terminado. Buena suerte.
11/12/2017 at 7:01 PM #52459Hi Tempus,
Thanks so much for your answer. I had a line with nomoretrade = 1 before, but I had it remove because I thought it didnt make a difference. I will try it now.
I am also confused with the strategy profit. Roberto helped me to create a daily strategy profit and limit the losses and stoping the operations once you reached a target, just to avoid an overexposure to the market. Honestly, I don’t know if is working.
The final idea is to stop trading for the day once you reach the profit, and if the operation is not going well averaging down (in both directions) and close the accumulation once the profit is >0. So, trying to generate a daily profit or a breakeven.
Let you know of the results,
Muchas gracias compañero.
Juan
P.S.- Perdona por el inglés, pero al haber abierto el hilo en el grupo de inglés, las reglas nos obligan a mantenerlo en inglés. Ya me han dado varios tokes…:)))
11/12/2017 at 7:34 PM #52462Juan,
I have no much experince so don´t take my words too seriously but if I were you I will design and backtest the system first without the two parameters you are using: daily profit/loss limit and avering down (kind of martingala?). And when you think you have a good system you can try those ideas, but if you use them from the begining maybe your system is not good and only saved in the backtest because of those parameters. And I would not expect to get good results in the future with that system. In other words I think you would have more chances to datamining or overoptimization. Just my thought 🙂
-
AuthorPosts
Find exclusive trading pro-tools on