TS HEIKEN ASHI

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #171488 quote
    Wolf TradesWolf Trades
    Participant
    Average

    Buon pomeriggio a tutti, tramite il forum non riesco a capire come definire le heiken ashi.
    Vorrei provare a codificare un TS che si basa su questo tipo di candele, potete aiutarmi a definire: chiusura, apertura, massimo e minimo?
    Il resto ovviamente lo faccio da solo.

    Grazie

    #171489 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Ecco, sono alcune semplici righe che puoi usare sempre, su qualunque time frame, per definire le Heikin-Ashi. Solitamente si mettono verso l’inizio del codice (dopo eventuali DEFPARAM), in ogni caso basta metterle PRIMA dell’uso.

    Esistono 3-4 modi (ognuno leggermente diverso dagli altri), ma questo è il più semplice, si può usare con screener, indicatori e strategie:

    once xOpen = open                            //Apertura iniziale
    xClose     = (open + close + high + low) / 4 //Chiusura
    if barindex > 0 then
        xOpen  = (xOpen[1] + xClose[1]) / 2      //Apertura (dopo la prima)
    endif
    xLow       = min(low,min(xClose,xOpen))      //Minimo
    xHigh      = max(high,max(xClose,xOpen))     //Massimo
    xTypic     = (xHigh + xLow + xClose) / 3     //Typical price
    xMed       = (xHigh + xLow) / 2              //Medium price
    xRange     = xHigh - xLow                    //Range

    per riferirti ad Open Heikin-Ashi dovrai usare xOpen, al Minimo userai xLow, ecc…

    Se vuoi usarle su più TF all’interno dello stesso codice, dovrai usare nomi diversi, ad esempio:

    Timeframe(1 hour)
    once xOpen1 = open                        //Apertura iniziale
    xClose1 = (open + close + high + low) / 4 //Chiusura
    if barindex > 0 then
       xOpen1 = (xOpen1[1] + xClose1[1]) / 2  //Apertura (dopo la prima)
    endif
    //
    Timeframe(5 minuti)
    once xOpen5 = open                        //Apertura iniziale
    xClose5 = (open + close + high + low) / 4 //Chiusura
    if barindex > 0 then
       xOpen5 = (xOpen5[1] + xClose5[1]) / 2  //Apertura (dopo la prima)
    endif

    nell’esempio ho definito solo xOpen e xClose, può anche bastare se non ti servoni gli altri dati, non è obbligatorio definirli tutti.

    #171511 quote
    Wolf TradesWolf Trades
    Participant
    Average

    Ti ringrazio Roberto, ho inserito il tutto in trade system. Puoi aiutarmi a controllarlo?
    Le logiche sono:
    BUY
    -CANDELA HE RIALZISTA TUTTA CORPO (Body > 50% Range)
    -MASSIMO CHE ROMPE BB SUPERIORE

    -STOP LOSS TECNICO MINIMO TRA 2 MINIMI FA E MEDIANA BB (sono riuscito a fare solo la prima condizione, almeno penso di averla fatta)

    TAKE PROFIT X VOLTE LO STOP LOSS (1,618)

    NUMERO MASSIMO DI CANDELE (8 o 13) dopo si chiude il trade

    SELL

    -CANDELA HE RIBASSISTA TUTTA CORPO (Body > 50% Range)
    -MINIMO CHE ROMPE BB INFERIORE

    -STOP LOSS TECNICO MASSIMO TRA 2 MASSIMI FA E MEDIANA BB (sono riuscito a fare solo la prima condizione, almeno penso di averla fatta)

    TAKE PROFIT X VOLTE LO STOP LOSS (1,618)

    NUMERO MASSIMO DI CANDELE (8 o 13) dopo si chiude il trade

    Ti Allego il codice:

    DEFPARAM PreLoadBars = 100
    DEFPARAM CumulateOrders = False
    DEFPARAM FLATBEFORE = 070100 // Il TS non apre trade prima di questo orario
    DEFPARAM FLATAFTER = 180000  // Il TS non apre trade dopo questo orario e chiude le posizioni ancora aperte
    
    
    // HA - definizione Heikin-Ashi
    once xOpen = open
    xClose = (open+close+high+low)/4
    if barindex > 0 then
    xOpen = (xOpen[1]+xClose[1])/2
    endif
    xLow = min(low,min(xClose,xOpen))
    xHigh = max(high,max(xClose,xOpen))
    xRange = abs(xHigh - xLow)
    xBody = abs(XClose - xOpen)
    
    //Indicatore BB
    BBUP = BollingerUp[20](xclose)
    BBDW = BollingerDown[20](xclose)
    MEDIA20 = Average[20](xClose)
    
    // Condizioni corpo candela
    Ratio = 0.5 // il 50%
    c1 = abs(xBody > XRange*Ratio)
    
    // Chiusura Posizioni dopo n Candele
    TempoScaduto = ((BarIndex - TradeIndex) >= 8) // il trade si chiude dopo "n" candele
    
    // Aggiungo "n" Point/Pips al mio stopLoss
    Npips = 2 * pipsize
    
    //Condizione BUY - BUYBOUT
    c2 = xHigh >= BBUP  // il massimo della candela è maggiore o uguale alle UPBB
    c3 = xClose > xOpen // Candela Rialzista
    MyStop1 = abs((xClose - Lowest[2](xLow))- Npips) // il minimo tra 2 minimi fa - Npips
    MyProfit1 = TradePrice + (abs (MyStop1*1.618))
    
    //Condizione SELL - SELLBOUT
    c4 = xLow <= BBDW  // il minimo della candela è minore o uguale alle DOWNBB
    c5 = xClose < xOpen // Candela Ribassista
    MyStop2 = abs((xClose + Highest[2](xHigh))+ Npips)  // il massimo tra due massimi fa + Npips
    MyProfit2 = TradePrice - (abs (MyStop2*1.618))
    
    
    // Condizioni per entrare su posizioni long
    IF NOT LongOnMarket AND c1 and c2 and c3 THEN
    BUY 1 CONTRACTS AT MARKET
    SET STOP LOSS MyStop1      //se inserisco MySTop1 devo togliere la "p" prima di LOSS
    SET TARGET PROFIT MyProfit1   //se inserisco MyProfit1 devo togliare la "p" prima di PROFIT
    ENDIF
    
    // Condizioni per uscire da posizioni long
    If LongOnMarket AND TempoScaduto THEN
    SELL AT MARKET
    ENDIF
    
    // Condizioni per entrare su posizioni short
    IF NOT ShortOnMarket AND c1 and c4 and c5 THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    SET STOP LOSS  MyStop2 //se inserisco MySTop2 devo togliere la "p" prima di LOSS
    SET TARGET PROFIT MyProfit2  //se inserisco MyProfit2 devo togliare la "p" prima di PROFIT
    ENDIF
    
    // Condizioni per uscire da posizioni short
    IF ShortOnMarket AND TempoScaduto THEN
    EXITSHORT AT MARKET
    ENDIF
    
    STARED-9-Giugno-2021-BOUT.itf
    #171544 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Mi sembra vada bene. Dal punto di vista logico è corretto.

Viewing 4 posts - 1 through 4 (of 4 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

TS HEIKEN ASHI


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Wolf Trades @lupo32 Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 06/09/2021
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...