Aprire una sola posizione al Massimo o al minimo candela oraria

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #168792 quote
    Stanko
    Participant
    Senior

    Buonasera Roberto.

    Avevo già chiesto, precedentemente, aiuto perchè c’erano dei problemi nell’aprire una sola posizione (al massimo o al minimo) in una candela oraria.

    In questi giorni sto provando in demo il programma che non soddisfaceva il mio scopo, però separandolo in pratica in 2 sistemi: uno solo long e l’altro solo short (allegati di seguito).

    Stranamente questi due programmi sembrano operare in simbiosi perchè si apre solo una operazione al giorno (o long o short) ed anche i backtest confermano i risultati.

    Per cortesia potresti verificare se c’ è qualche comando errato?

    Grazie

    DEFPARAM CumulateOrders = False
    //DEFPARAM FLATAFTER = 220000
    //Condizioni per entrare LONG//
    Timeframe (1 Hour, Updateonclose)
    //IF NOTONMARKET THEN
    //i = 0
    IF Time = 090000 AND not OnMarket THEN
    COMPRA = High[0] + (5*pipsize)
    BUY 1 CONTRACT AT COMPRA STOP
    ENDIF
    
    
    Timeframe (5 minute, Updateonclose)
    ATRSU = AverageTrueRange[5] < AverageTrueRange[1]
    ATRGIU = AverageTrueRange[5] > AverageTrueRange[1]
    
    IF ATRSU THEN
    SET TARGET pPROFIT (70*1.2)*pipsize
    SET STOP pLOSS (70*1.2)*pipsize
    ELSE
    IF ATRGIU THEN
    SET TARGET pPROFIT 70*pipsize
    SET STOP pLOSS 70*pipsize
    ENDIF
    ENDIF
    
    SCA = 50*pipsize
    
    IF LONGONMARKET AND (close - tradeprice(1)) >= (SCA* pipsize) THEN
    breakevenLevel = tradeprice(1) + (SCA* pipsize) //calculate the breakevenLevel
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel > 0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    ENDIF
    // --- SHORT side
    IF SHORTONMARKET AND (tradeprice(1) - close) >= (SCA* pipsize) THEN
    breakevenLevel = tradeprice(1) + (SCA* pipsize) //calculate the breakevenLevel
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel > 0 THEN
    EXITSHORT AT breakevenLevel STOP
    ENDIF
    ENDIF
    
    DEFPARAM CumulateOrders = False
    //DEFPARAM FLATAFTER = 220000
    //Condizioni per entrare LONG//
    Timeframe (1 Hour, Updateonclose)
    
    IF Time = 090000 AND not OnMarket THEN
    VENDI = Low[0] - (5*pipsize)
    SELLSHORT 1 CONTRACT AT VENDI STOP
    ENDIF
    
    Timeframe (5 minute, Updateonclose)
    ATRSU = AverageTrueRange[5] < AverageTrueRange[1]
    ATRGIU = AverageTrueRange[5] > AverageTrueRange[1]
    
    IF ATRSU THEN
    SET TARGET pPROFIT (70*1.2)*pipsize
    SET STOP pLOSS (70*1.2)*pipsize
    ELSE
    IF ATRGIU THEN
    SET TARGET pPROFIT 70*pipsize
    SET STOP pLOSS 70*pipsize
    ENDIF
    ENDIF
    
    SCA = 50*pipsize
    
    IF LONGONMARKET AND (close - tradeprice(1)) >= (SCA* pipsize) THEN
    breakevenLevel = tradeprice(1) + (SCA* pipsize) //calculate the breakevenLevel
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel > 0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    ENDIF
    // --- SHORT side
    IF SHORTONMARKET AND (tradeprice(1) - close) >= (SCA* pipsize) THEN
    breakevenLevel = tradeprice(1) + (SCA* pipsize) //calculate the breakevenLevel
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel > 0 THEN
    EXITSHORT AT breakevenLevel STOP
    ENDIF
    ENDIF
    
    #168809 quote
    robertogozzi
    Moderator
    Master

    Nel primo codice (ma va bene anche per il secondo, cambieranno probabilmente le righe), subito dopo  la riga 4 aggiungi questa:

    BarCount = BarIndex

    e subito dopo la riga 13 queste:

    ONCE TradeON = 1
    IF IntraDayBarIndex = 0 THEN
       TradeON = 1
    ENDIF
    TradeBar = BarCount
    IF Not OnMarket AND TradeBar <> TradeBar[1] THEN
       TradeON = 1
    ENDIF
    IF OnMarket OR (StrategyProfit <> StrategyProfit[1]) THEN
       TradeON = 0
    ENDIF

    infine modifica la riga 7 aggiungendoci la condizione TradeON:

    IF Time = 090000 AND not OnMarket AND TradeON THEN
    #168814 quote
    Stanko
    Participant
    Senior

    Grazie Roberto per la disponibilità.

    Purtroppo il sistema mi restituisce gli stessi risultati.

    In pratica il sistema entra in posizione LONG solo se il primo movimento successivo alla candela in esame rompe al rialzo.

    Il sistema sembra che riesca a valutare un eventuale ingresso SHORT anche se non ci sono comandi che lo richiedano.

    Grazie ancora e buona giornata.

    #168824 quote
    robertogozzi
    Moderator
    Master

    Scusami, avevo capito una cosa completamente diversa.

    Ti fa un’operazione soltanto perché hai messo l’entrata alle 9 esatte, siccome gli ordini pendenti vengono automaticamente cancellati ad ogni barra del TF principale, quello che è sul grafico (nel tuo caso ogni 5 minuti) se non entra allora non entra più.

    In pratica vuoi che ti faccia più operazioni durante il giorno?

    #168826 quote
    Stanko
    Participant
    Senior

    Un caso emblematico è stato ieri sul DAX: in apertura ha tentato di allungare trovando un nuovo massimo dopo le ore 9 per poi invertire subito e scendere con decisione: il sistema solo SHORT che avevo in DEMO non si è azionato quindi l’operazione LONG ha chiuso in LOSS mentre una possibile operazione SHORT non si è aperta.

    Comunque, come mi hai fatto notare, con un Timeframe a 5 minuti sarebbe più opportuno trovare il massimo delle ore 9 con una funzione tipo HIGHEST[12] fino a quando non viene (eventualmente) aperta l’operazione.

    #168887 quote
    robertogozzi
    Moderator
    Master

    L’ho modificato un pò, in particolare ho messo l’entrata nel TF a 5 minuti (mentre il calcolo del prezzo l’ho lasciato su H1), poi ho spostato qualche linea del BreakEven, perché come l’avevi messo tu se dopo averlo messo a BreakEven tornava sotto i 50 pips non piazzava l’ordine pendente STOP e non usciva:

    DEFPARAM CumulateOrders = False
    //DEFPARAM FLATAFTER = 220000
    //Condizioni per entrare LONG//
    Timeframe (1 Hour, Updateonclose)
    Distanza = 7 * pipsize
    IF Time = 090000 THEN
    COMPRA = High[0] + (5*pipsize)
    ENDIF
    Timeframe (5 minute, Updateonclose)
    IF Time >= 090000 AND Not OnMarket THEN
    IF (close + Distanza) < COMPRA THEN
    BUY 1 CONTRACT AT COMPRA STOP
    ElSIF (close - Distanza) > COMPRA THEN
    BUY 1 CONTRACT AT COMPRA LIMIT
    ELSE
    BUY 1 CONTRACT AT MARKET
    ENDIF
    ENDIF
    ATRSU  = AverageTrueRange[5] < AverageTrueRange[1]
    ATRGIU = AverageTrueRange[5] > AverageTrueRange[1]
    IF Not OnMarket THEN
    breakevenlevel = 0
    IF ATRSU THEN
    SET TARGET pPROFIT (70*1.2)*pipsize
    SET STOP pLOSS (70*1.2)*pipsize
    ELSIF ATRGIU THEN
    SET TARGET pPROFIT 70*pipsize
    SET STOP pLOSS 70*pipsize
    ENDIF
    ENDIF 
    SCA = 50*pipsize
    // --- LONG  side
    IF LONGONMARKET AND (close - tradeprice(1)) >= (SCA* pipsize) THEN
    breakevenLevel = tradeprice(1) + (SCA* pipsize) //calculate the breakevenLevel
    ENDIF
    // --- SHORT side
    IF SHORTONMARKET AND (tradeprice(1) - close) >= (SCA* pipsize) THEN
    breakevenLevel = tradeprice(1) + (SCA* pipsize) //calculate the breakevenLevel
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel > 0 THEN
    SELL      AT breakevenLevel STOP
    EXITSHORT AT breakevenLevel STOP
    ENDIF
    #168910 quote
    Stanko
    Participant
    Senior

    Buongiorno Roberto.

    Ancora grazie per la disponibilità.

    Ho provato in demo il tuo sistema e riduce nettamente le operazioni in loss.

    Buona giornata.

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

Aprire una sola posizione al Massimo o al minimo candela oraria


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Stanko @stanko Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Stanko
4 years, 9 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 05/04/2021
Status: Active
Attachments: No files
Logo Logo
Loading...