Prova di scrittura codice

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

    Roberto buongiorno,

    dopo aver bazzicato per 2 anni in PRT , ho provato a trasformare in codice una mia idea e cioè ; se ci sono due candele ascendenti si va long se il segnale è confermato da un indicatore, ho messo poi un filtro con volume e stop loss / profit /thrilling (in allegato).

    La mia domanda è se il su codice ha una sua logicità, lo sto provando su EUR/USD TF 1 Spread 0,2 ora e mi da dei discreti risultati.

    DEFPARAM CumulateOrders = False // Posizioni cumulate disattiva
    TradingTime=Time>=090000and Time<=210000

    td = opendayofweek >= 1 and opendayofweek <= 5
    //condizioni per entrata long
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c3 = (indicator1 >= indicator2)

    ONCE c1 = 0
    ONCE c2 = 0

    IF c1 = 0 AND Not OnMarket THEN
    c1 = ( close > open and close[1] > open[1] )
    ENDIF
    indicator3 = CALL “PRC_Adjustible CoRa_Wave”[20, 2, 1, 1](close)
    IF c2 = 0 AND Not OnMarket THEN
    c2 = (close >= indicator3)
    ENDIF
    IF c1 AND c2 AND td and c3 and TradingTime THEN
    BUY 1 CONTRACT AT MARKET
    c1 = 0
    c2 = 0
    ENDIF

     

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

    //SET STOP PLOSS l
    //SET TARGET PPROFIT p

    //************************************************************************
    //trailing stop
    trailingstop = tra

    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    MINPRICE = close
    priceexit = 0
    endif

    //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif

    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE – trailing stop price level
    endif
    endif

    Grazie

    #221863 quote
    robertogozzi
    Moderator
    Master

    All’inizio ho dovuto aggiungere le tre variabili mancanti, in quanto tule hai nell’ottimizzatore del backtest,mailCopia & Incolla non le copia.

    Ho aggiunto in fondo 3 righe che mancavano nel trailing stop, cioè l’USCITA, quindi NON usciva mai in trailing stop:

    IF PriceExit > 0 THEN
       SET STOP PRICE PriceExit
    ENDIF

    Ho spostato SET STOP LOSS e SET TARGET PROFIT all’interno del blocco IF…ENDIF dove c’è BUY, perché altrimenti ti vanificano il trailing stop.

    Ho spostato la condizione AND Not OnMarket sulla riga IF dell’entrata, èinutile metterla su ogni condizione, c1, c2 ecc…

    Ho inserito il Multi Time Frame, per cui le condizioni e l’entrate le verifica ed entra sul TF di 1 ora, mentre il trailing stop lo fa su 1 minuto (ma puoi anche provarlo sul 5 minuti):

    DEFPARAM CumulateOrders = False // Posizioni cumulate disattiva
    //
    timeframe(default)
    TradingTime=Time>=090000and Time<=210000
    
    l   = 0.8
    p   = 1.0
    tra = 13
    //
    Timeframe(1h,UpdateOnClose)
    td = opendayofweek >= 1 and opendayofweek <= 5
    //condizioni per entrata long
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c3 = (indicator1 >= indicator2)
    
    ONCE c1 = 0
    ONCE c2 = 0
    
    c1 = ( close > open and close[1] > open[1] )
    
    indicator3 = CALL "PRC_Adjustible CoRa_Wave"[20, 2, 1, 1](close)
    
    c2 = (close >= indicator3)
    
    IF c1 AND c2 AND td and c3 and TradingTime AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    c1 = 0
    c2 = 0
    SET STOP LOSS l*AverageTrueRange[10](close)
    SET TARGET PROFIT p*AverageTrueRange[12](close)
    ENDIF
    
    //SET STOP PLOSS l
    //SET TARGET PPROFIT p
    //
    timeframe(default)
    //************************************************************************
    //trailing stop
    trailingstop = tra
    
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE  = 0
    MINPRICE  = close
    priceexit = 0
    endif
    
    //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif
    
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    IF PriceExit > 0 THEN
    SET STOP PRICE PriceExit
    ENDIF

    l’ho provato con 200K barre ed è profittevole, ma devi testarlo per vari mesi prima di poterlo utilizzare, perché operare sulle medie spesso porta a risultati disastrosi a causa della sovraottimizzazione.

    #221865 quote
    Ciccarelli Franco
    Participant
    Junior

    Grazie veramente tanto gentile, il thrilling stop a 1 minuto mi sembra troppo stretto, come faccio a portarlo a 5 minuti.

    Grazie

    #221873 quote
    robertogozzi
    Moderator
    Master

    Basta che sostituisci la riga 37 con:

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

Prova di scrittura codice


ProOrder: Trading Automatico & Backtesting

New Reply
Summary

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

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