Ordini limit per 10 o più barre ?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #77978 quote
    GIBU2GIBU2
    Participant
    Average

    Salve a tuuti,

    vorrei tenere aperto l’ordine Limit per 10 o più barre

    per poter entrare ad un prezzo migliore ma non riesco a trovare

    le combinazioni corrette di variabili qualcuno mi può aiutare ?

    Sotto ho messo il codice che vorrei provare a modificare.

    Grazie.

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    
    // Condizioni per entrare su posizioni long
    indicator1 = Stochastic[100,10](close)
    indicator2 = Average[10](indicator1)
    c1 = (indicator1 CROSSES UNDER indicator2)
    indicator3 = Stochastic[100,10](close)
    c2 = (indicator3 <= 20)
    
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT close – 10 * pipsize LIMIT
    ENDIF
    
    // Condizioni per entrare su posizioni short
    indicator4 = Stochastic[100,10](close)
    indicator5 = Average[10](indicator4)
    c3 = (indicator4 CROSSES OVER indicator5)
    indicator6 = Stochastic[100,10](close)
    c4 = (indicator6 >= 80)
    
    IF c3 AND c4 THEN
    SELLSHORT 1 CONTRACT AT close + 10 * pipsize LIMIT
    ENDIF
    // Stop e target
    SET STOP pLOSS 100
    SET TARGET pPROFIT 100
    #78017 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Ci sono alcune variazioni importanti da fare al tuo codice, ti scriverò qualcosa lunedì, adesso sono fuori e non ho il mio PC.

    #78055 quote
    GIBU2GIBU2
    Participant
    Average

    Grazie Roberto.

    #78078 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Per scrivere il codice , utilizza il pulsante <> “insert PRT code“, in modo da rendere il codice più chiaro e comprensibile. Grazie.

    Per prima cosa devi salvare il prezzo di entrata che desideri al verificarsi delle condizioni da te desiderate, nel tuo caso CLOSE; devi anche salvare il numero della relativa candela o barra, quindi dovresti aggiungere, tra le righe 11 e 12 e tra 22 e 23 le seguenti righe:

    PrezzoEntrata = CLOSE
    NumeroBarra   = BARINDEX

    devi anche salvare l’indicazione se entrare a rialzo oppure al ribasso perché le condizioni C1-C2-C3-C4 potrebbero anche variare temporaneamente nel corso di 10 candele, per cui aggiungi, tra le righe 12 e 13:

    Rialzo  = 1
    Ribasso = 0

    e tra tra le righe 23 e 24:

    Rialzo  = 0
    Ribasso = 1

    però questo prezzo potrebbe variare tra una candela e l’altra, a causa delle mutate condizioni, per cui dovresti aggiungere, alla righe 11 e 22 la condizione:

    AND Not OnMarket

    che ti consiglio di usare SEMPRE, a meno che tu non desideri entrare più volte accumulando posizioni.

    A questo punto non resta altro che verificare che, se non sei già a mercato, tu sia ancora entro le 10 barre per continuare ad inserire l’ordine pendente:

    IF Not OnMarket AND ((BarIndex - NumeroBarra) <= 10) THEN
       IF Rialzo THEN
          BUY 1 CONTRACT AT PrezzoEntrata  – 10 * pipsize LIMIT       //oppure STOP
       ELSIF Ribasso THEN
          SELLSHORT 1 CONTRACT AT PrezzoEntrata  + 10 * pipsize LIMIT //oppure STOP
    ENDIF

    devi anche, all’inizio della strategia, azzerare tutte le variabili quando sei a mercato:

    IF OnMarket THEN
       PrezzoEntrata = 0
       NumeroBarra   = 0
       Rialzo        = 0
       Ribasso       = 0
    ENDIF

    Questo è il codice completo:

    // Definizione dei parametri del codice
    DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
    
    IF OnMarket THEN
       PrezzoEntrata = 0
       NumeroBarra   = 0
       Rialzo        = 0
       Ribasso       = 0
    ENDIF
    
    IF Not OnMarket AND ((BarIndex - NumeroBarra) <= 10) THEN
       IF Rialzo THEN
          BUY 1 CONTRACT AT PrezzoEntrata – 10 * pipsize LIMIT       //oppure STOP
       ELSIF Ribasso THEN
          SELLSHORT 1 CONTRACT AT PrezzoEntrata + 10 * pipsize LIMIT //oppure STOP
       ENDIF
    ENDIF
    
    // Condizioni per entrare su posizioni long
    indicator1 = Stochastic[100,10](close)
    indicator2 = Average[10](indicator1)
    c1 = (indicator1 CROSSES UNDER indicator2)
    indicator3 = Stochastic[100,10](close)
    c2 = (indicator3 <= 20)
    
    IF c1 AND c2 AND Not OnMarket THEN
       PrezzoEntrata = CLOSE
       NumeroBarra   = BARINDEX
       BUY 1 CONTRACT AT PrezzoEntrata – 10 * pipsize LIMIT
       Rialzo  = 1
       Ribasso = 0
    ENDIF
    
    // Condizioni per entrare su posizioni short
    indicator4 = Stochastic[100,10](close)
    indicator5 = Average[10](indicator4)
    c3 = (indicator4 CROSSES OVER indicator5)
    indicator6 = Stochastic[100,10](close)
    c4 = (indicator6 >= 80)
    
    IF c3 AND c4 AND Not OnMarket THEN
       PrezzoEntrata = CLOSE
       NumeroBarra   = BARINDEX
       SELLSHORT 1 CONTRACT AT PrezzoEntrata + 10 * pipsize LIMIT
       Rialzo  = 0
       Ribasso = 1
    ENDIF
    // Stop e target
    SET STOP pLOSS 100
    SET TARGET pPROFIT 100
    Nicolas thanked this post
    #78127 quote
    GIBU2GIBU2
    Participant
    Average

    Direi che di cose da aggiungere e modificare c’e ne erano parecchie. Grazie Roberto.

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

Ordini limit per 10 o più barre ?


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
GIBU2 @gibu2 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by GIBU2GIBU2
8 years, 1 month ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 08/10/2018
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...