Chiudere definitivamente una strateggia

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #222973 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Che istruzioni dovrei usare per chiudere definitivamente una strategia al raggiungimento di un livello di prezzo?

     

    Grazie

    #222974 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    QUIT, questa è l’istruzione per chiudere una strategia ed interromperne l’autotrading.

    Se poi volessi riattivarla basta la la esegui nuovamente in autotrading.

    #222975 quote
    GraHalGraHal
    Participant
    Master
    #222977 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Grazie per le risposte, mi andrebbe bene l’esempio 1, ma invece dell’ora vorrei mettere il prezzo. Come devo fare?

    #222982 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Metti il prezzo che desideri al posto dell’ora:

    IF ShortOnMarket AND PrezzoUscita = XXXXX THEN
    #222987 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Vale anche per la versione short del codice?

    Grazie

    #222988 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Non mi funziona, allego versione long e short, ditemi per cortesia se le istruzioni da me messe sono giuste.

    Grazie

     

    DEFPARAM CumulateOrders = FALSE
    TradingTime=Time>=080000and Time<=180000

    // LONG
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c1 = (indicator1 >= indicator2)

    IF ( close > open and close[1] > open[1] ) and c1 and TradingTime Then
    BUY 1 CONTRACTS AT MARKET
    endif
    PrezzoUscita= 1.3900
    IF ShortOnMarket AND PrezzoUscita then
    QUIT

     

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

    //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

    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif

     

    DEFPARAM CumulateOrders = False

    TradingTime=Time>=090000and Time<=210000

    // SHORT
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c1 = (indicator1 >= indicator2)

    IF ( ( close < open and close[1] < open[1] )) and c1 and TradingTime THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    endif
    PrezzoUscita= 1.3500
    IF shortOnMarket AND PrezzoUscita then
    QUIT

     

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

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

    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif

    #222992 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Manca il confronto, con cosa vuoi confrontare il prezzo di uscita? Immagino con CLOSE:

    IF shortOnMarket AND close = PrezzoUscita then
       QUIT
    ENDIF

    vale anche per le operazioni LONG.

    #222996 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Grazie sempre gentile.

    #223016 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Scusami Roberto, contrariamente a quando credevo non funziona , praticamente nei backtest  che eseguo, ultimamente sull’argento TF 1 ora , le entrate e le uscite sono determinate dalle date  ma non dal valore che inserisco.

    Ti allego i due codici che uso per vedere dove sbaglio.

    Versione long

    DEFPARAM CumulateOrders = FALSE
    TradingTime=Time>=080000and Time<=180000

    // LONG
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c1 = (indicator1 >= indicator2)

    IF ( close > open and close[1] > open[1] ) and c1 and TradingTime Then
    BUY 1 CONTRACTS AT MARKET
    endif
    PrezzoUscita =2400
    IF shortOnMarket AND close = PrezzoUscita then
    QUIT
    endif

     

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

     

    //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

    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif

     

    Versione short

     

     

    DEFPARAM CumulateOrders = False

    TradingTime=Time>=090000and Time<=210000

    // SHORT
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c1 = (indicator1 >= indicator2)

    IF ( ( close < open and close[1] < open[1] )) and c1 and TradingTime THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    endif
    PrezzoUscita= 2150
    IF shortOnMarket AND close = PrezzoUscita then
    QUIT

     

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

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

    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif

    #223138 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Roberto, forse non lo ritieni interessante?

    #223180 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Nella versione LONG devi usare LongOnMarket.

    Questa LONG sul DAX funziona, con il livello che ho indicato:

    //Versione long
    DEFPARAM CumulateOrders = FALSE
    TradingTime=Time>=080000 and Time<=180000
    // LONG
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c1 = (indicator1 >= indicator2)
    IF ( close > open and close[1] > open[1] ) and c1 and TradingTime Then
    BUY 1 CONTRACTS AT MARKET
    endif
    PrezzoUscita = 15400
    IF LongOnMarket AND close = PrezzoUscita then
    QUIT
    endif
    SET STOP LOSS 10*AverageTrueRange[10](close)
    SET TARGET PROFIT 10*AverageTrueRange[12](close)

    anche questa versione SHORT funziona:

    //Versione short
    DEFPARAM CumulateOrders = False
    TradingTime=Time>=090000and Time<=210000
    // SHORT
    indicator1 = Volume
    indicator2 = ExponentialAverage[14](Volume)
    c1 = (indicator1 >= indicator2)
    IF ( ( close < open and close[1] < open[1] )) and c1 and TradingTime THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    endif
    PrezzoUscita = 15400
    IF shortOnMarket AND close = PrezzoUscita then
    QUIT
    ENDIF
     SET STOP LOSS 10*AverageTrueRange[10](close)
    SET TARGET PROFIT 10*AverageTrueRange[12](close)

    Se vuoi puoi aggiungere il trailing stop, ma con un valore alto, altrimenti entra in funzione quello e difficilmente esce con QUIT. Io ho provato con TRA=100.

    #223197 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Si funziona , ma esce esattamente a quel prezzo, io invece vorrei che uscisse da quel prezzo in su o in giù per la variante short.

    Grazie

    #223198 quote
    Ciccarelli FrancoCiccarelli Franco
    Participant
    Senior

    Risolto grazie.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Chiudere definitivamente una strateggia


ProOrder: Trading Automatico & Backtesting

New Reply
Summary

This topic contains 13 replies,
has 3 voices, and was last updated by Ciccarelli FrancoCiccarelli Franco
2 years, 10 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 10/27/2023
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...