SISTEMA DELLE TRE CANDELE CONSECUTIVE

Viewing 15 posts - 1 through 15 (of 42 total)
  • Author
    Posts
  • #99582 quote
    Gaspare
    Participant
    Veteran

    buongiorno a tutti

    se possibile avere un sistema automatico che apra e chiuda posizioni dopo 3 candele consecutive dello stesso colore, cioè:

    long dopo 3 candele rosse consecutive con minimi crescenti e  stop loss, da definire, sotto il minimo dell’ultima candela

    short dopo 3 candele verdi consecutive con massimi crescenti e stop loss, da definire, sopra il massimo dell’ultima candela.

    il TF lo si sceglie come si vuole.

    Grazie per la vostra gentile collaborazione

    #99585 quote
    robertogozzi
    Moderator
    Master

    Quelle rosse con MINIMI CRESCENTI  o decrescenti?

    #99586 quote
    robertogozzi
    Moderator
    Master

    Per la chiusura attende che si verifichino le condizioni opposte, se entra dopo 3 candele ROSSE esce quando ve ne saranno 3 VERDI e viceversa?

    #99587 quote
    Gaspare
    Participant
    Veteran

    chiedo scusa

    con 3 minimi decrescenti

    #99588 quote
    Gaspare
    Participant
    Veteran

    no, per la chiusura del trade pensavo a un trailing stop che ho trovato in bibblioteca

    da ottimizzare assieme allo stop loss

    Grazie

    set stop ploss X
    //trailing stop
    trailingstop = Y
    //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
    
    #99607 quote
    robertogozzi
    Moderator
    Master

    Eccola:

    ONCE CandleNum = 3
    Bullish        = summation[CandleNum](close > open) = CandleNum
    Bearish        = summation[CandleNum](close < open) = CandleNum
    HigherHIGHs    = (summation[CandleNum - 1](high > high[1]) = (CandleNum - 1))
    LowerLOWs      = (summation[CandleNum - 1](low < low[1])   = (CandleNum - 1))
    IF Bearish AND LowerLOWs AND Not OnMarket THEN
       BUY 1 CONTRACT AT MARKET
       Sl = max(10,(close - low) / pipsize)
       Tp = Sl * 3
    ENDIF
    IF Bullish AND HigherHIGHs AND Not OnMarket THEN
       SELLSHORT 1 CONTRACT AT MARKET
       Sl = max(10,(high - close) / pipsize)
       Tp = Sl * 1.5
    ENDIF
    SET STOP   pLOSS   Sl
    SET TARGET pPROFIT Tp

    Alle righe 8 e 13 ho messo la funzione MAX con un numero di pips minimi (tu metti la cifra che vuoi), perché può capitare che CLOSE possa essere uguale a LOW o HIGH, nel qual caso lo SL sarebbe = 0, come pure il TP, quindi entrerebbe a mercato SENZA più uscire, oppure uscendo in MARGIN CALL.

    In fondo bast che aggiungi il codice del trailing stop ed è fatta. Il TP puoi anche toglierlo, se vuoi.

    #99734 quote
    Gaspare
    Participant
    Veteran

    salve Roberto

    cortesemente puoi provarlo anche tu perchè mi sembra che qualcovsa non vada.

    Ho testato il sistema non a TF temporali, ma a quantita’ di TICKS, con candele da 50, 100, 200, ecc.

    e la posizione resta aperta per diverse candele successive sino a quando non scatta lo stop loss.

    Grazie

    ONCE CandleNum = 3
    Bullish        = summation[CandleNum](close > open) = CandleNum
    Bearish        = summation[CandleNum](close < open) = CandleNum
    HigherHIGHs    = (summation[CandleNum - 1](high > high[1]) = (CandleNum - 1))
    LowerLOWs      = (summation[CandleNum - 1](low < low[1])   = (CandleNum - 1))
    IF Bearish AND LowerLOWs AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    Sl = max(X,(close - low) / pipsize)
    
    ENDIF
    IF Bullish AND HigherHIGHs AND Not OnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Sl = max(X,(high - close) / pipsize)
    
    ENDIF
    SET STOP   pLOSS   Sl
    
    //trailing stop
    trailingstop = Y
    //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
    
    #99735 quote
    robertogozzi
    Moderator
    Master

    Certo, non hai messo nessun Target Profit!

    #102649 quote
    Gaspare
    Participant
    Veteran
    ONCE CandleNum = C
    Bullish        = summation[CandleNum](close > open) = CandleNum
    Bearish        = summation[CandleNum](close < open) = CandleNum
    HigherHIGHs    = (summation[CandleNum - 1](high > high[1]) = (CandleNum - 1))
    LowerLOWs      = (summation[CandleNum - 1](low < low[1])   = (CandleNum - 1))
    IF Bearish AND LowerLOWs AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    Sl = max(S,(close - low) / pipsize)
    Tp = Sl * M
    ENDIF
    IF Bullish AND HigherHIGHs AND Not OnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Sl = max(S,(high - close) / pipsize)
    Tp = Sl * M
    ENDIF
    SET STOP   pLOSS   Sl
    SET TARGET pPROFIT Tp
    //trailing stop
    trailingstop = T
    //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
    

    ciao Roberto

    il TS finale, secondo me

    da ottimizzare le variabili

    C  da 1  a 5  passo 1

    S  da 5 a 200  passo 5

    M  da 1  a  5  passo 1

    T  da 1 a 10 passo 1,  oppure da 5 a 50 passo 5, oppure da 10 a 100 passo 10, ecc.

    Mi dai un tuo parere?

    Grazie

    #102657 quote
    robertogozzi
    Moderator
    Master

    Devi dirmi indicarmi te i valori per te ottimali, purtroppo non ho il tempo per fare prove di ottimizzazione.

    #103095 quote
    Gaspare
    Participant
    Veteran

    buongiorno, ciao Roberto

    una domanda da neofita:

    dopo l’ottimizzazione si attiva subito il TS?
    oppure si deve aspettare la chiusura della posizione ancora aperta nella simulazione?
    mi spiego meglio:
    ottimizzate le variabili del TS inserisco i valori e se non ci sono posizioni aperte attivo il TS, ma se c’è una posizione aperta devo attendere che si chiuda?
    Secondo me, se attivo con posizione aperta, viene compromesso il risultato finale, perchè non conforme con lo storico parziale esaminato, da inizio a fine periodo preso in esame.

    Forse bisogna inserire una riga o piu’ di codice, affinche’ il TS si attivi in automatico dopo la chiusura del trade precedente?
    Grazie

    #103098 quote
    robertogozzi
    Moderator
    Master

    Se per attivare intendi esguire la strategia non in backtest, ma realmente (su conto demo o reale) puoi eseguirla quando vuoi, basta che la esegui con ProOrder in autotrading. Le due cose possono coesistere, anzi, puoi tenere anche più strategie aperte contemporaneamente in backtest.

    Ad ogni modo interrompare il backtest non falsa niente, quando vuoi lo fai ripartire ed ottieni gli stessi risultati (salvo nel frattempo siano scomparse entrate vecchie ed apparse quelle nuove). Ogni backtest può sempre essere falsato, perché tra dieci giorni, come ho detto, alcune delle prime operazioni possono essere scomparse ed altre nuove apparse.

    Lo scopo del backtest è darti l’idea della bontà, o meno, della strategia, non sostituire esattamente quello che accade nella realtà.

    #105022 quote
    Alessandro
    Participant
    Junior
    ONCE CandleNum = 4
    Bullish        = summation[CandleNum](close > open) = CandleNum
    Bearish        = summation[CandleNum](close < open) = CandleNum
    HigherHIGHs    = (summation[CandleNum - 1](high > high[1]) = (CandleNum - 1))
    LowerLOWs      = (summation[CandleNum - 1](low < low[1])   = (CandleNum - 1))
    IF Bearish AND LowerLOWs AND Not OnMarket THEN
    BUY 1 CONTRACT AT MARKET
    Sl = max(20,(close - low) / pipsize)
    Tp = Sl * 3
    ENDIF
    IF Bullish AND HigherHIGHs AND Not OnMarket THEN
    SELLSHORT 1 CONTRACT AT MARKET
    Sl = max(20,(high - close) / pipsize)
    Tp = Sl * 3
    ENDIF
    SET STOP   pLOSS   Sl
    SET TARGET pPROFIT Tp
    //trailing stop
    trailingstop = 10
    //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

     

    Innanziutto grazie peril codice.Ho provato a inserire le variabili usando un timeframe a 1 minuto ma analizzando il grafico ho notato e non ho capito alcune cose

    Nello screen 1 c’è una mancata entrata short con discesa di 45 pips e una mancata entrata long di circa 80 pips e addirittura una entrata short durante la fase rialzista.

    Nello screen 2 un’entrata short in ritardo e un’entrata short nella fase rialzista.

    Nello screen 3 una mancata entrata long mancata entrata short e un’entrata long nella fase ribassista.

    Qualcuno mi può gentilmente aiutare a correggere questo codice ? mi interessa molto

    Grazie

    #105037 quote
    robertogozzi
    Moderator
    Master

    Per verificare le operazioni serve la data e l’ora della candela d’entrata.

    #105040 quote
    Alessandro
    Participant
    Junior

    Questo è il rimo screenshoot con gli orari

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

SISTEMA DELLE TRE CANDELE CONSECUTIVE


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Gaspare @gaspare Participant
Summary

This topic contains 41 replies,
has 3 voices, and was last updated by Gaspare
5 years, 11 months ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 05/28/2019
Status: Active
Attachments: 7 files
Logo Logo
Loading...