Costruzione TS con Heikin-Hashii

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #162151 quote
    tundercut
    Participant
    Senior

    Ciao Roberto, vorrei costruire una strategia basata sulle Heikin-Hashii con entrata long o short sulla apertura della quarta candela dello stesso colore, e sull’avvenuto incrocio delle due medie mobili, con uscita posizione all’incrocio successivo.

    Poi eventualmente inserirò io ulteriori stop loss e take profit. Per chiarezza ti allego un immagine.

    Grazie.

    Schermata-2021-02-21-alle-08.19.35.png Schermata-2021-02-21-alle-08.19.35.png
    #162166 quote
    robertogozzi
    Moderator
    Master

    Le strategie vengono eseguite alla chiusura di ogni candela, per cui alla chiusura della terza o della quarta, ovviamente non si può sapere di quale colore sarà la successiva.

    Eccolo:

    DEFPARAM CumulateOrders = FALSE
    //
    // definizione delle candele Heikin-Ashi
    once xOpen = open
    xClose        = (open + close + high + low) / 4
    if barindex > 0 then
       xOpen     = (xOpen + xClose[1]) / 2
    endif
    //xLow       = min(low,min(xClose,xOpen))
    //xHigh      = max(high,max(xClose,xOpen))
    //xTypic     = (xHigh + xLow + xClose) / 3
    //xMed       = (xHigh + xLow) / 2
    //xRange     = xHigh - xLow
    xBullish     = xClose > xOpen
    xBearish     = xClose < xOpen
    //
    NumeroHA     = 3
    SerieUP      = (summation[NumeroHA](xBullish) = NumeroHA)
    SerieDN      = (summation[NumeroHA](xBearish) = NumeroHA)
    //
    ONCE CrossUP = 0
    ONCE CrossDN = 0
    IF IsLastBarUpdate THEN
       Sma20     = Average[20,0](close)
       Sma50     = Average[50,0](close)
       IF CrossUP = 0 THEN
          CrossUP = Sma20 CROSSES OVER  Sma50
          IF CrossUP THEN
             CrossDN = 0
          ENDIF
       ENDIF
       IF CrossDN = 0 THEN
          CrossDN = Sma20 CROSSES UNDER Sma50
          IF CrossDN THEN
             CrossUP = 0
          ENDIF
       ENDIF
       CambioDirezione = (CrossUP AND CrossDN[1]) OR (CrossUP[1] AND CrossDN)
    ENDIF
    // LONG
    IF SerieUP AND CrossUP AND Not OnMarket THEN
       BUY 1 Contract AT Market
    ENDIF
    IF LongOnMarket AND CambioDirezione THEN
       SELL AT Market
    ENDIF
    // SHORT
    IF SerieDN AND CrossDN AND Not OnMarket THEN
       SELLSHORT 1 Contract AT Market
    ENDIF
    IF ShortOnMarket AND CambioDirezione THEN
       EXITSHORT AT Market
    ENDIF
    //
    SET TARGET pPROFIT 500
    SET STOP   pLOSS   100
    //
    graph SerieUP
    graph SerieDN
    graph CrossUP
    graph CrossDN
    graph CambioDirezione
    #162252 quote
    tundercut
    Participant
    Senior

    Grazie Roberto, sempre molto gentile, pensavo fosse piu semplice, non ci sarei mai riuscito.

    robertogozzi thanked this post
    #162264 quote
    tundercut
    Participant
    Senior

    Scusa Roberto, ma come posso evitare che apra una nuova posizione dopo aver raggiunto il profit? Ti allego un immagine con le freccette dove vorrei che non entrasse a mercato.

    Schermata-2021-02-21-alle-18.36.54.png Schermata-2021-02-21-alle-18.36.54.png
    #162267 quote
    robertogozzi
    Moderator
    Master

    Subito dopo la riga 42 (tra BUY ed ENDIF) inserisci queste:

    SerieUP = 0
    CrossUP = 0

    subito dopo la riga 49 (tra SELLSHORT ed ENDIF) inserisci queste:

    SerieDN = 0
    CrossDN = 0

    non l’ho provato, ma dovrebbe funzionare.

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

Costruzione TS con Heikin-Hashii


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
tundercut @tundercut Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 02/21/2021
Status: Active
Attachments: 2 files
Logo Logo
Loading...