Singola operazione MultiTimeFrame

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #168794 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, ho provato un tuo snippet code sul multitimeframe (MTF), attraverso il quale si dovrebbe aprire un unica operazione nel timeframe superiore, ma nel mio semplice esempio non funziona

    (riferimento libreria snippetcode di GraHal , n.3 – https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit#gid=0).

    Nel mio esempio di prova si utilizza un MTF ad 1 ora ed uno operativo (default) ad 1 minuto.

    DEFPARAM CumulateOrders=False
    DEFPARAM Flatbefore=080000
    DEFPARAM Flatafter=220000
    //-------------------------------------------------------------------------------
    timeframe(1hour,updateOnClose)
    
    C1= close
    H1 = High
    L1= Low
    //------------------------------------------
    timeframe(1 minute)
    
    if low[1]<L1 and close>L1  then
    buy 1 contract at market
    endif
    
    if high>H1 then
    sell 1 contract at market
    endif
    //----------------------------------------------------
    pointToReach=50*pointSize
    pointToKeep=20*pointSize
    If not onmarket then
    newSL=0
    endif
    If longonmarket then
    If newSL=0 and close-tradeprice[1]>pointToReach then
    newSL=tradeprice(1)+pointToKeep
    endif
    If newSL>0 and close-newSL>pointToReach then
    newSL = newSL+pointToKeep
    endif
    endif
    If shortonmarket then
    If newSl=0 and tradeprice(1)-close>pointToReach then
    newSL = tradeprice(1)-pointToKeep
    endif
    If newSl>0 and newSL-close>pointToReach then
    newSL = newSl-pointToKeep
    endif
    endif
    if newSL>0 then
    sell at newSL STOP
    exitshort at newSL STOP
    endif
    //----------------------------------------------------
    set stop %loss 0.3

     

    Quando aggiungo lo snippetcode, secondo esempio, non funziona più bene. Puoi controllare? Grazie (provato su Nasdaq 1 minuto – 30K, CFD)

    DEFPARAM CumulateOrders=False
    DEFPARAM Flatbefore=080000
    DEFPARAM Flatafter=220000
    //-------------------------------------------------------------------------------
    timeframe(1hour,updateOnClose)
    
    IF Not OnMarket THEN
    BarCount = 0
    ELSE
    BarCount = BarCount + 1
    ENDIF
    
    C1= close
    H1 = High
    L1= Low
    //------------------------------------------
    timeframe(1 minute) //default
    
    ONCE TradeON = 1
    IF IntraDayBarIndex = 0 THEN
    TradeON = 1
    ENDIF
    TradeBar = BarCount
    IF Not OnMarket AND TradeBar <> TradeBar[1] THEN
    TradeON = 1
    ENDIF
    
    if low[1]<L1 and close>L1 and not onMarket and tradeON then
    buy 1 contract at market
    tradeOn= 0
    endif
    
    if high>H1 then
    sell 1 contract at market
    endif
    //----------------------------------------------------
    pointToReach=50*pointSize
    pointToKeep=20*pointSize
    If not onmarket then
    newSL=0
    endif
    If longonmarket then
    If newSL=0 and close-tradeprice[1]>pointToReach then
    newSL=tradeprice(1)+pointToKeep
    endif
    If newSL>0 and close-newSL>pointToReach then
    newSL = newSL+pointToKeep
    endif
    endif
    If shortonmarket then
    If newSl=0 and tradeprice(1)-close>pointToReach then
    newSL = tradeprice(1)-pointToKeep
    endif
    If newSl>0 and newSL-close>pointToReach then
    newSL = newSl-pointToKeep
    endif
    endif
    if newSL>0 then
    sell at newSL STOP
    exitshort at newSL STOP
    endif
    //----------------------------------------------------
    set stop %loss 0.3
    #168807 quote
    robertogozzi
    Moderator
    Master

    E’ errato, devi sostituire (nel secondo codice), le righe 7-11 con questa sola riga:

    BarCount = BarIndex

    ho anche modificato il post originale.

    Grazie per averlo segnalato 🙂

    #170326 quote
    MauroPro
    Participant
    Veteran

    Ciao Roberto, puoi controllare perchè  con il codice sotto riportato (snippetcode) il  TS  in allegato (semplficato) apre più operazioni al giorno (ne dovrebbe aprire una soltanto come il primo codice). Ho evidenziato le differenze dei due codici per agevolare il confronto. Grazie

    // Primo codice (corretto)
    
    DEFPARAM CumulateOrders=False
    DEFPARAM Flatbefore=000000
    DEFPARAM Flatafter=220000
    //——————————————-
    timeframe(daily,updateOnClose)
    dayHigh = Dhigh(0)
    dayLow = Dlow(0)
    //——————————————–
    timeframe(1 hour)
    if low[1]<dayLow and close>dayLow and (barIndex-tradeIndex(1)>intradayBarIndex) then
    buy 1 contract at market
    endif
    if high[1]>dayHigh and close<dayHigh and (barIndex-tradeIndex(1)>intradayBarIndex) then
    sellshort 1 contract at market
    endif
    
    //——————————————————————————–
    set stop %loss 0.5
    set target %profit 1.5
    
    //————-————-————-————-————-————-
    
    // Secondo codice MTF
    
    DEFPARAM CumulateOrders=False
    DEFPARAM Flatbefore=000000
    DEFPARAM Flatafter=220000
    //——————————————-
    timeframe(daily,updateOnClose)
    BarCount = barIndex
    
    dayHigh = Dhigh(0)
    dayLow = Dlow(0)
    //——————————————–
    timeframe(1 hour)
    ONCE TradeON = 1
    IF IntraDayBarIndex = 0 THEN
    TradeON = 1
    ENDIF
    TradeBar = BarCount
    IF Not OnMarket AND TradeBar <> TradeBar[1] THEN
    TradeON = 1
    ENDIF
    
    if low[1]<dayLow and close>dayLow and tradeOn then
    buy 1 contract at market
    endif
    if high[1]>dayHigh and close<dayHigh and tradeOn then
    sellshort 1 contract at market
    endif
    
    //——————————————————————————–
    set stop %loss 0.5
    set target %profit 1.5
    #170355 quote
    robertogozzi
    Moderator
    Master

    Lo scopo del mio codice è d’impedire che entri più volte nel TF inferiore, ma quando c’è un TF di default ancora più piccolo, tipo 5 minuti.
    Così non fa assolutamente niente.
    Per fare una sola operazione al giorno usa questo nel TF più piccolo:

    OTD = (Barindex - TradeIndex(1) > IntradayBarIndex)  // IntradayBarIndex < (Barindex - TradeIndex(1)) limits the (opening) trades till  1 per day (OTD One Trade per Day)

    e aggiungi OTD alle condizioni di entrata.

    #170360 quote
    MauroPro
    Participant
    Veteran

    Il codice OTD è lo stesso utilizzato nel mio primo esempio sopra riportato e funzionante.

    Volevo sostituirlo con lo snippetcode come prova. Mi “sembrava” che il codice riportato nello snippet serviva ad effettuare 1 operazione NON nel TF inferiore, ma in uno a scelta in cui si inseriva la prima parte del codice,  corretta in: BarCount = BarIndex:

    “should be added to only one TF, i.e. if you are using Daily+h4+h1+10-minute+default(1-second), then if you add that code on the 10-minute TF your next trade would not open till the next 10-minute bar.

    If you add it, instead, to your 1-hour TF, only one trade per hour will be allowed, and so on…”

    In sintesi, basta inserire: (barIndextradeIndex(1)>intradayBarIndex) nel TF in cui si vuole fare una sola operazione senza usare più lo snippet?

    #170364 quote
    MauroPro
    Participant
    Veteran

    Un esempio per capire meglio:

    lo snippet ha due parti da inserire ognuna in un TF differente:

    A)  BarCount = barIndex                                               // che “dovrebbe” essere inserita nel TF dove si vuole fare una sola operazione

    B) ONCE TradeON = 1                                                  //che “dovrebbe” essere inserito nel TF più piccolo (default)

    IF IntraDayBarIndex = 0 THEN
    TradeON = 1
    ENDIF
    TradeBar = BarCount
    Supponiamo di avere 3 TF:
    1) timeframe (daily, updateOnClose)
    2)  timeframe (1 hour)
    3) timeframe (5 minutes) – default
    Per effettuare fare una sola operazione ogni ora, mi “sembrava” che dovevo inserire la parte A in 2 e la parte B in 3. 
    #170373 quote
    robertogozzi
    Moderator
    Master

    Esatto.

    Solo che usi il TF daily, quindi più di una al giorno non può fartela.

    Però devi azzerare TradeON quando entri a mercato, quindi dopo le linee 48 e 51 devi aggiungere:

    TradeON = 0
    #170384 quote
    MauroPro
    Participant
    Veteran

    Perfetto, mi ero scordato nel secondo codice con MTF di azzerare i flag (ecco perchè era diverso = faceva più operazioni).

    Ti chiedo due cose veloci, la prima è solo una conferma:

    A) Se si utilizzano il TF daily ed un TF di default a 5 minuti, e scrivo:

    timeframe (daily, updateOnClose)

    dayHigh = Dhigh(0)

    con dayHigh mi stò riferendo al massimo della candela daily di ieri, dato che la candela di oggi non è ancora terminata, mentre se scrivo:

    timeframe (daily)

    dayHigh = Dhigh(0)

    con dayHigh mi stò riferendo al massimo della candela di oggi in corso, lo stesso giorno del TF a 5 minuti. Corretto? (se si, updateOnClose determina quindi anche il giorno di riferimento della candela daily)

    B) Se volessi utilizzare la candela daily con updateOnClose per avere, ad esempio, il minimo della giornata di ieri per entrare, ma contemporaneamente mi servirebbe utilizzare il “divenire” della candela per uscire (quindi senza updateOnClose) c’è un modo migliore che utilizzare 2 TF: ad 1 ora con updateOnclose ed a 59 minuti senza?

    Grazie

    #170385 quote
    MauroPro
    Participant
    Veteran

    scusa, nel caso B mi riferisco sempre alla candela oraria con e senza updateOnClose:

    B) Se volessi utilizzare la candela oraria con updateOnClose per avere, ad esempio, il minimo orario per entrare, ma contemporaneamente mi servirebbe utilizzare il “divenire” della candela oraria per uscire (quindi senza updateOnClose) c’è un modo migliore che utilizzare 2 TF: ad 1 ora con updateOnclose ed a 59 minuti senza?

    #170386 quote
    robertogozzi
    Moderator
    Master

    Esatto.

    Puoi utilizzare entrambi (sono due TF diversi, quindi non possono avere le variabili con lo stesso nome):

    timeframe (daily, updateOnClose)
     .
     .
    timeframe (daily, default)       (DEFAULT non è obbligatorio, puoi ometterlo)
     .
     .

    però sono considerati come un unico TF per i limiti di ProOrder (5 TF + quello di default sono il masimo utilizzabile), quindi è come se tu ne usassi solo due (Daily + default).

    Con DAILY non c’è bisogno di usare DHIGH, DOPEN, ecc… basta HIGH, OPEN, ecc… in quanto so i valori giornalieri.

    Semmai 1 minuto, 59 non è accettato perché 1 ora e Daily non sono multipli di 59.

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

Singola operazione MultiTimeFrame


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
MauroPro @mauropro Participant
Summary

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

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