loss e profit non funzionanti

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #223360 quote
    Ciccarelli Franco
    Participant
    Junior

    In una strategia trovato in libreria (allegato) in bak test i loss e profit funzionano , o almeno cosi sembra, in live non scattano . Inoltre in demo funzionano in live no. Sembra strano ma è quello che sto rilevando ultimamente.

    Chiedo a Roberto che ringrazio anticipatamente se mi può aiutare.

    //Universal XBody STrategy
    // instrument: EUR/USD
    // timeframe : Daily
    // Spread: 4
    // created and coded by davidelaferla
    //————————————————————————-

    //————————————————————————-
    defparam cumulateorders=false

    //***********************************************************************************************************
    N = 1
    //—————— SYSTEM VARIABLES—————————————
    //CAC40 Values: ——————————————– Ottimization info
    period=per// Optimize best value for each Symbol, range=1-1000, with step=1
    mode=md// Optimize the best trading mode , range=1-4, with step=1
    invertsignal=inv// 1=positive signal, -1=negative signal, range=-1-1, with step=2
    //***********************************************************************************************
    //—————— SYSTEM FILTER—————————————
    filter1=fl1// to set after the variable optimization, range=1-100, with step=1
    filter2=fl2// to set after the variable optimization, range=0-100, with step=1
    //—————— INDICATOR —————————————
    body=close-open
    var=(body-body[1])
    sumvar=summation[period](var)
    if sumvar>filter1*pipsize then
    green=(sumvar)
    endif
    if sumvar<-filter2*pipsize then
    red=(sumvar)
    endif

    if mode=1 then
    c1=red<red[1]
    c2=green>green[1]
    endif
    if mode=2 then
    c1=red>red[1]
    c2=green<green[1]
    endif
    if mode=3 then
    c1=red<red[1]
    c2=green<green[1]
    endif
    if mode=4 then
    c1=red>red[1]
    c2=green>green[1]
    endif
    if c1 then
    signal=1*invertsignal
    elsif c2 then
    signal=-1*invertsignal
    endif

    // Conditions for entering long positions and exit short positions
    IF signal>0 then
    BUY n contract AT market

    SET STOP PLOSS l
    SET TARGET PPROFIT p

    ENDIF

    // Conditions for entering short positions and exit long positions
    IF signal<0 THEN
    SELLSHORT n CONTRACTs AT market

    SET STOP PLOSS l1
    SET TARGET PPROFIT p1

    //SET STOP LOSS l*AverageTrueRange[10](close)
    //SET TARGET PROFIT p*AverageTrueRange[12](close)

    ENDIF

    VARIABILI

    l =20, p =90, l1=35 ,p1 = 20, per = 269, inv =1, md = 3, f1 =9 , f2 = 9

    #223372 quote
    robertogozzi
    Moderator
    Master

    Credo sia un problema di SL e TP, un pò troppo vicini al prezzo, trattandosi di candele giornaliere.

    Inoltre pè sempre opportuno usare anche la condizione OnMarket per entrare, in modo da non eseguire il codice anche nelle barre successive, se già a mercato.

    Questo pè il codice che hai postato, leggermente modificato come ti ho dertto e con l’aggiunta di GRAPHONPRICE per vedere sul grafico dove sono sutuati SL e TP:

    // Universal XBody STrategy
    // instrument: EUR/USD
    // timeframe : Daily
    // Spread    : 4
    // created and coded by davidelaferla
    //————————————————————————-
    defparam cumulateorders=false
    l   = 100//20
    p   = 300//90
    l1  = 100//35
    p1  = 300//20
    per = 269
    inv = 1
    md  = 3
    fl1 = 9
    fl2 = 9
    //***********************************************************************************************************
    N = 1
    //—————— SYSTEM VARIABLES—————————————
    //CAC40 Values: ——————————————- Ottimization info
    period=per// Optimize best value for each Symbol, range=1-1000, with step=1
    mode=md// Optimize the best trading mode , range=1-4, with step=1
    invertsignal=inv// 1=positive signal, -1=negative signal, range=-1-1, with step=2
    //***********************************************************************************************
    //—————— SYSTEM FILTER—————————————
    filter1=fl1// to set after the variable optimization, range=1-100, with step=1
    filter2=fl2// to set after the variable optimization, range=0-100, with step=1
    //—————— INDICATOR —————————————
    body=close-open
    var=(body-body[1])
    sumvar=summation[period](var)
    if sumvar>filter1*pipsize then
    green=(sumvar)
    endif
    if sumvar<-filter2*pipsize then
    red=(sumvar)
    endif
    
    if mode=1 then
    c1=red<red[1]
    c2=green>green[1]
    endif
    if mode=2 then
    c1=red>red[1]
    c2=green<green[1]
    endif
    if mode=3 then
    c1=red<red[1]
    c2=green<green[1]
    endif
    if mode=4 then
    c1=red>red[1]
    c2=green>green[1]
    endif
    if c1 then
    signal=1*invertsignal
    elsif c2 then
    signal=-1*invertsignal
    endif
    
    // Conditions for entering long positions and exit short positions
    IF signal>0 AND Not OnMarket then
    BUY n contract AT market
    SLprice = close - l*pipsize
    TPprice = close + p*pipsize
    SET STOP   PLOSS   l
    SET TARGET PPROFIT p
    ENDIF
    
    // Conditions for entering short positions and exit long positions
    IF signal<0 AND Not OnMarket THEN
    SELLSHORT n CONTRACTs AT market
    SLprice = close + l1*pipsize
    TPprice = close - p1*pipsize
    SET STOP   PLOSS   l1
    SET TARGET PPROFIT p1
    //SET STOP LOSS l*AverageTrueRange[10](close)
    //SET TARGET PROFIT p*AverageTrueRange[12](close)
    ENDIF
    graphonprice SLprice coloured("Red")
    graphonprice TPprice coloured("Blue")
    #223486 quote
    Ciccarelli Franco
    Participant
    Junior
    SLprice = close l*pipsize
    TPprice = close + p*pipsize
    SET STOP   PLOSS   l
    SET TARGET PPROFIT p
    Ma in questa maniera gli stop e profit sono forse doppiati?
    Grazie
    #223508 quote
    robertogozzi
    Moderator
    Master

    No, le prime due righe definiscono delle variabili (usate per visualizzare TP e SL sul grafico), non sono istruzioni da eseguire.
    Gli ordini di SL e TP sono le altre due righe che iniziano con SET, quindi non c’è nessuna duplicazione.

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

loss e profit non funzionanti


ProOrder: Trading Automatico & Backtesting

New Reply
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 11/08/2023
Status: Active
Attachments: No files
Logo Logo
Loading...