Snippet x attesa N barre dopo chiusura di un trade

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

    Ciao Roberto, volevo chiederti se è possibile includere in questo snippetCode (funzionante) che permette di attendere N barre dopo la chiusura di un trade, anche i trades che aprono e chiudono nella stessa barra,

    Per maggior chiarezza: se un TS apre un trade nella barra 1 e lo chiude nella barra 2 (o superiore) lo snippet permette di attendere N barre prima di aprire il trade successivo.

    Se invece un TS (vd immagine) apre e chiude un trade nella barra 1, lo snippet non funziona (non attende il numero di barre).

    Esempio (Nasdaq  cfd- 15m – 10k): il giorno venerdi 6 maggio 2022 il TS  apre e chiude un trade nella stessa barra ed infatti poi, erroneamente, prende il segnale seguente prima di attendere 20 barre, come fa lo stesso TS (quello sotto nel grafico) senza snippet.

     

    once barCount = 0                                        
    waitingBars = 20    //barsToWaitAfterTrade
    once tradeCount  = 1
    if (longOnMarket and not onMarket[1]) or (longOnMarket and shortOnMarket[1]) or (longOnMarket[1] and shortOnMarket) then
    tradeCount  = 0
    barCount = 0
    endif
    if not longOnMarket then
    barCount = barCount + 1
    endif
    if barCount > waitingBars then
    tradeCount = 1
    endif
    //--------------------------------------------------------------
    if close crosses over average[50,0](close) and not onMarket and barCount > waitingBars then
    buy 1 contract at market
    endif
    set target pProfit 100
    set stop   pLoss   100
    #193087 quote
    robertogozzi
    Moderator
    Master

    Sostituisci la riga 4 con questa:

    If (OnMarket and Not OnMarket[1]) or ((Not OnMarket and Not OnMarket[1] and (StrategyProfit <> StrategyProfit[1])) or (LongOnMarket and ShortOnMarket[1]) or (LongOnMarket[1] and ShortOnMarket) Then
    MauroPro thanked this post
    #193097 quote
    MauroPro
    Participant
    Veteran

    Grazie Roberto, funziona (manca una parentesi nella formula che hai scritto dopo il secondo “not onMarket[1]”

    In pratica è come la formula che usa il tuo nuovo snippet per effettuare il massimo numero di operazioni al giorno:

    newTrades =  (onMarket and not onMarket[1]) or (longOnMarket and shortOnMarket[1]) or (longOnMarket[1] and shortOnMarket) or ((not OnMarket and not onMarket[1]) and (strategyProfit <> strategyProfit[1]))
    Penso che questa sia la formulazione migliore per determinare se c’è stata un operazione includendo operazioni che si aprono e chiudono sulla stessa barra.
    Andrebbe rimpiazzato questa riga di codice anche in snippet più vecchi e non molto precisi che si trovano nel forum (come quello che ho riportato all’inizio) che hanno bisogno (per diversi motivi) di verificare se c’è stata un operazione.
    #193110 quote
    robertogozzi
    Moderator
    Master

    Scusa per la parentesi, hai ragione.

    Si, è proprio  quello snippet li, solo che (me ne sono accorto proprio la settimana scorsa) nel caso di operazioni aperte e chiuse sulla stessa barra, verifica e conteggia solo quelle negative o positive, quelle che hanno avuto un pareggio perfetto (credo rarissime) no, perché STRATEGYPROFIT risulta identica alla barra precedente.

    Ho pensato a questa modifica, che include anche questi rari casi:

    IF (OnMarket AND Not OnMarket[1]) OR ((Not OnMarket AND Not OnMarket[1]) AND (StrategyProfit <> StrategyProfit[1])) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR ((TradeIndex(1) = TradeIndex(2)) AND (BarIndex = TradeIndex(1)) AND (BarIndex > 0) AND (StrategyProfit = StrategyProfit[1])) THEN

    In pratica verifica che STRATEGYPRIFIT sia identica, che non fosse a mercato prima, né dopo (quindi una sola barra) e che l’operazione si sia davvero chiusa la barra precedente e che si sia anche aperta nella stessa barra, tramite TRADEINDEX.

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

Snippet x attesa N barre dopo chiusura di un trade


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
MauroPro @mauropro Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 05/11/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...