Mantenere valida una condizione

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #108485 quote
    R05R05
    Participant
    Veteran

    Gent.mi, vi chiedo come poter mantenere valido un massimo/minimo a N periodi per un numero limitato di candele successive, al termine delle quali non si tiene più in considerazione di quel massimo/minimo, finchè non si verifica uno nuovo. Mi spiego meglio: ad esempio alle 10 ho un massimo di giornata o a N periodi, io prenderò in considerazione la possibilità di aprire una posizione short solo se entro le prossime 10 candele si verificano altre condizioni; al termine delle 10 candele si resetta tutto; poi alle 12 ho un nuovo massimo e allora prenderò in considerazione questo massimo solo per le successive 10 candele e cosi via.

    Vi allego il sistema che stavo mettendo su, con un codice che dovrebbe fare quello che vorrei, ma purtroppo sbaglio qualcosa. Infatti il problema del sistema seguente è che mi entra ogni qual volta si verifica la condizione z1 a prescindere che siano trascorse o meno 10 candele. Vi premetto che le condizioni di entrata alla voce z1 sono ancora in fase di studio.

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    // Il sistema cancellerà tutti gli ordini in attesa e chiuderà tutte le posizioni a 0:00. Dopo l'orario "Flat Before" non saranno piazzati nuovi ordini o posizioni.
    DEFPARAM FLATBEFORE = 090000
    // Cancellare tutti gli ordini in attesa e chiudere tutte le posizioni all'orario "Flat After"
    DEFPARAM FLATAFTER = 173000
    
    once miopatternshort = 0
    
    If OnMarket or STRATEGYPROFIT <> STRATEGYPROFIT[1] Then
    miopatternshort = 0                    //resettare la variabile al valore iniziale, se a mercato
    ENDIF
    IF miopatternshort THEN
    IF (BarIndex - miopatternshort) > 10 THEN
    miopatternshort = 0                 //resettare la variabile al valore iniziale dopo n candele
    ENDIF
    ENDIF
    
    ONCE TradeOn            = 0             //inizializzazione variabile
    IF OnMarket THEN
    TradeOn  = 0                          //una volta a mercato azzerare la variabile
    ENDIF
    
    Tophigh = highest[100](high)
    z= high<tophigh
    z1 = high > low[1] and high>low[2] and high>low[3] and high>low[4] and high>low[5]
    
    if z and z1 then
    miopatternshort=barindex
    endif
    
    IF miopatternshort THEN          // se...
    TradeOn = 1                          //...settare la variabile per tradare e...
    Tophigh = highest[100](high)        //...salvare il massimo delle ultime 100 candele.
    ENDIF
    
    
    IF summation[6](miopatternshort) = 6 THEN   //se la condizione è da oltre 5 candele...
    TradeOn = 0                          //...annullare e ripartire da zero.
    ENDIF
    IF TradeOn THEN     //Se condizioni soddisfatte aprire il trade
    SELLSHORT 1 CONTRACT AT low stop
    ENDIF
    
    // Stop e target
    SET STOP pLOSS 15
    SET TARGET pPROFIT 15
    
    #108488 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Nel tup esempio qual’è la variabile che vuoi mantenere valida per un massimo di 10 ore?

    #108491 quote
    R05R05
    Participant
    Veteran

    Vorrei mantenere l’highest[100](high).

    #108582 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Intendevo 10 candele, non ore.

    Innanzitutto scrivi alla riga 7, o alla 9:

    ONCE NumeroBarra = 0

    poi sostituisci sia la riga 24  che la riga 34, con queste righe:

    Tophigh = highest[100](high)
    IF Tophigh = Tophigh[1] THEN
       IF NumeroBarra <> 0 then
          NumeroBarra = NumeroBarra + 1
       endif
       IF NumeroBarra >= 10 THEN
          NumeroBarra = 0
       ENDIF
    ELSE
       NumeroBarra = 1
    ENDIF

    Sostituisci la riga 41 (che avrà cambiato numero dopo le suddette modifiche) con:

    IF TradeOn AND NumeroBarra > 0 THEN     //Se condizioni soddisfatte aprire il trade
    #108590 quote
    R05R05
    Participant
    Veteran

    Grazie Roberto, gentilissimo, quel problema è risolto. Ho notato però che alcune volte la strategia non tiene conto del massimo delle ultime 100 candele, ma entra in posizione lo stesso e poi alle 9:00 appena il sistema parte mi fa fare un’operazione. Ti allego un esempio. Strumento utilizzato dax su time frame 30 secondi.

    Cattura-4.jpg Cattura-4.jpg
    #108593 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Utilizza GRAPH per monitorare le variabili che ti interessano per verificare il caso, tipo:

    GRAPH tophigh
    GRAPH z
    GRAPH z1
    GRAPH ....

    puoi metterne quante ne vuoi, in tal cao vedrai che valore hanno, candela per candele e ti renderai conto quado c’è un valore errato.

    R05 thanked this post
    #109136 quote
    R05R05
    Participant
    Veteran

    Una domanda sul trading sistema su esposto che vale in generale: c’è il modo di riportare l’highest cha va, ad esempio, dalla centesima candela alla quinta precedente alla candela presente; quindi non l’highest delle ultime 100 candele ma l’highest dalla 100 alle ultime 5 senza tenere conto delle ultime 5 candele?

    #109137 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Quindi in pratica 95, dalla 6 alla 100:

    Tophigh = highest[95](high[5]) //il Massimo più alto tra le candele 5-99 precedenti

    si può scrivere anche:

    Tophigh = highest[100](high)[5] //il Massimo più alto tra le ultime 100 candele, ma prendendo il valore aggiornato alla 5 candela precedente

    anzi, dalla 5 alla 99, perché si parte da quella corrente che è la candela 0.

    #109138 quote
    R05R05
    Participant
    Veteran

    Si 95 candele escludendo le ultime 5. Grazie Roberto.

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

Mantenere valida una condizione


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
R05 @r05 Participant
Summary

This topic contains 8 replies,
has 2 voices, and was last updated by R05R05
6 years, 12 months ago.

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