Wrong entries. Help to fix de code.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #52451 quote
    Juan Salas
    Participant
    Master

    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

    // Código principal : RSI w daily averaging 15' EUR 12NOV
    //-------------------------------------------------------------------------
    
    DEFPARAM CUMULATEORDERS = true
    
    // OPERATIONAL TIME
    DEFPARAM FLATBEFORE = 020000
    DEFPARAM FLATAFTER = 210000
    
    // STRATEGYPROFIT per day. It resets the variable each new day
    IF INTRADAYBARINDEX = 0 THEN
    stratprofit = STRATEGYPROFIT //saves the previous day Profit
    ENDIF
    
    // POSITION SIZE
    positionsize = 1
    
    // PROFITs
    profit1 = 10
    profit2 = 12
    profit3 = 14
    profit4 = 20
    
    // Condiciones
    // Alcistas
    rsialc1 = RSI[2](close)<2
    decreasinghighs = high<high[1] AND high[1]<high[2] AND high[2]<high[3]
    alcista = rsialc1 AND decreasinghighs
    enrojoalcista1= (tradeprice(1)-close)>5*pipsize AND (tradeprice(1)-close)<=10*pipsize
    enrojoalcista2= (tradeprice(1)-close)>10*pipsize AND (tradeprice(1)-close)<=20*pipsize
    enrojoalcista3= (tradeprice(1)-close)>20*pipsize AND (tradeprice(1)-close)<=30*pipsize
    tresvelasalcistas = open[1]<close[1] AND open[2]<close[2]
    rangoverde = (close[1]-open[3])>40*pipsize
    fastalza = tresvelasalcistas AND rangoverde
    
    // Bajistas
    rsibaj1 = RSI[2](close)>98
    increasinglows = low>low[1] AND low[1]>low[2] AND low[2]>low[3]
    bajista = rsibaj1 AND increasinglows
    enrojobajista1= (close-tradeprice(1))>5*pipsize AND (close-tradeprice(1))<=10*pipsize
    enrojobajista2= (close-tradeprice(1))>10*pipsize AND (close-tradeprice(1))<=20*pipsize
    enrojobajista3= (close-tradeprice(1))>20*pipsize AND (close-tradeprice(1))<=30*pipsize
    tresvelasbajistas = open[1]>close[1] AND open[2]>close[2]
    rangorojo = (open[3]-close[1])>40*pipsize
    fastbaja = tresvelasbajistas AND rangorojo
    
    
    // LONG Positions-Opening_________________________________________________________________________________________________
    // Alcistas
    IF alcista AND NOT fastbaja THEN
    BUY positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit1
    ENDIF
    
    // Averaging
    IF LONGONMARKET AND RSI[2](close)<5 AND COUNTOFLONGSHARES<=2 AND enrojoalcista1 THEN
    BUY positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit2
    ENDIF
    
    IF LONGONMARKET AND RSI[2](close)<5 AND COUNTOFLONGSHARES<=3 AND enrojoalcista2 THEN
    BUY positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit3
    ENDIF
    
    IF LONGONMARKET AND RSI[2](close)<5 AND COUNTOFLONGSHARES<=4 AND enrojoalcista3 THEN
    BUY positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit4
    ENDIF
    
    
    
    // SHORT Positions-Opening_________________________________________________________________________________________________
    // Bajistas
    IF bajista AND NOT fastalza THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit1
    ENDIF
    
    // Averaging
    IF SHORTONMARKET AND RSI[2](close)>95 AND COUNTOFSHORTSHARES<=2 AND enrojobajista1 THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit2
    ENDIF
    
    IF SHORTONMARKET AND RSI[2](close)>95 AND COUNTOFSHORTSHARES<=3 AND enrojobajista2 THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit3
    ENDIF
    
    IF SHORTONMARKET AND RSI[2](close)>95 AND COUNTOFSHORTSHARES<=4 AND enrojobajista3 THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    SET TARGET pPROFIT profit4
    ENDIF
    
    
    
    //Finishing DAILY operations when reaching target profit/loss
    IF (STRATEGYPROFIT-stratprofit)>=10 THEN //current day's profit
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    
    IF (STRATEGYPROFIT-stratprofit)<=-20 THEN //current day's loss
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    
    
     
    
    Screen-Shot-2017-11-12-at-17.02.24.png Screen-Shot-2017-11-12-at-17.02.24.png
    #52458 quote
    TempusFugit
    Participant
    Veteran

    Hola 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
    ENDIF

    IF (STRATEGYPROFIT-stratprofit)<=-20 THEN //current day’s loss
    NOTRADES = 1
    ENDIF

    Y 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 THEN

    NOTRADES = 0
    stratprofit = STRATEGYPROFIT //saves the previous day Profit
    ENDIF

    Y 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
    ENDIF

    Y al resto de ejecuciones.

    Tu sistema parece muy prometedor, espero poder verlo ya terminado. Buena suerte.

    #52459 quote
    Juan Salas
    Participant
    Master

    Hi 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…:)))

    #52462 quote
    TempusFugit
    Participant
    Veteran

    Juan,

    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 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Wrong entries. Help to fix de code.


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Juan Salas @juan-salas Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by TempusFugit
8 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/12/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...