Numero massimo di trade per giorno

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #116865 quote
    GianlucaGianluca
    Participant
    Master

    Salve in diversi codici uso una funzione per stabilire il numero massimo di trade da fare, ho notato che pero’ se il trade si apre e chiude nella stessa candela non viene conteggiato, come posso fare per aggiustare questo errore? Ci ho provato ma non so quale possa essere la funzione.

    Io attualmente uso:

    ////////////////////
    maxorderslong = 1 //max orders per day
    maxordersshort= 0
    
    //BUY ORDERS
    if setuplong=1 then
    if not onmarket and not NOTRADEDAYlong and timelong and condlong and countlong<maxorderslong THEN
    IF maxsetup = 0 THEN
    maxsetup = res
    graphonprice maxsetup
    endif
    BUY numberContracts CONTRACT AT maxsetup+1 stop
    set target profit 25
    set stop loss 50
    endif
    endif
    
    
    //counting orders
    if LONGONMARKET and lastindex<>tradeindex then
    countlong=countlong+1
    lastindex=tradeindex
    endif
    
    if shortonmarket and lastindex<>tradeindex then
    countshort=countshort+1
    lastindex=tradeindex
    endif
    

    Ho provato anche mettendo il count subito dopo l’ordine, ma se l’ordine non entra a mercato poi il sistema non opera

    #116867 quote
    GianlucaGianluca
    Participant
    Master

    ho fatto questa modifica e sembra a ritroso andare bene potreste confermarmi la cosa?

    if not onmarket and lastindex<tradeindex then
    countlong=countlong+1
    lastindex=tradeindex
    endif

     

    anche se in caso di due candele consecutive che aprono e chiudono in stessa barra non riesce a contare la prima

    #116879 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Per verificare se c’è stata un’operazione aperta e chiusa nella stessa barra occorre scrivere:

    If STRATEGYPROFIT <> STRATEGYPROFIT[1] then
       .
    Endif

    perché è evidente che se il risultato della strategia è diverso da quello della barra precedente è dovuto ad un’operazione appena effettuata.

    #116880 quote
    robertogozzirobertogozzi
    Moderator
    Legend
    #117231 quote
    GianlucaGianluca
    Participant
    Master
    //------------------
    //check profit 
    if strategyprofit<>strategyprofit[1] then 
     if positionperf(1)>0 then 
      if close<tradeprice(2) then  
       gain=-1 //was sell
      elsif close>tradeprice(2) then 
       gain=1 //was buy
      endif
     else
      gain=0
     endif
    endif

    Questo è quanto riporta nicolas, ma io non sono interessato al fatto che sia stato un gain o un loss, devo far si che ci sia un contatore separato per i trade che siano short o long. il problema è che il contatore non legge i trade aperti e chiusi nella stessa barra.

    #117232 quote
    GianlucaGianluca
    Participant
    Master
    If STRATEGYPROFIT <> STRATEGYPROFIT[1] then
       .
    Endif

    come si fa a scrivere questo codice e ad identificare se è stato un sell o un long?

    #117235 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Il codice di Nicolas è quello che va messo tra la tua riga 1 e la riga 3, solo che oltre a differenziare i trade in profitto vanno anche differenziati quelli in perdita, dove lui ha messo GAIN=0.

    Adesso non sono al PC, domani lo adatto.

    #117240 quote
    GianlucaGianluca
    Participant
    Master

    grazie

    #117333 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Inserisci questo codice all’inizio della tua strategia, o comunque prima di nuove entrate a mercato e prima che ti serva sapere se il trade precedente era LONG o SHORT:

    EraLong  = 0
    EraShort = 0
    if strategyprofit <> strategyprofit[1] then
       if positionperf(1) > 0 then
          if tradeprice(1) < tradeprice(2) then
             EraShort = 1
          elsif tradeprice(1) > tradeprice(2) then
             EraLong  = 1
          endif
       elsif positionperf(1) < 0 then
          if tradeprice(1) < tradeprice(2) then
             EraLong  = 1
          elsif tradeprice(1) > tradeprice(2) then
             EraShort = 1
          endif
       endif
    endif
    //---------------------------------------------------------------

    se EraLong  avrà valore 1 significa che il trade precedente era LONG,   altrimenti avrà valore 0.

    se EraShort avrà valore 1 significa che il trade precedente era SHORT, altrimenti avrà valore 0.

    #117708 quote
    GianlucaGianluca
    Participant
    Master

    Grazie e se voglio dire fai massimo 3 trade long e 2 short?

    #117712 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Metti un contatore per i Long ed ino per gli Short e tra le condizioni metti che quando ciascuno è arrivato al massimo t’impedisca di aprire nuove posizioni.

    Questi contatori dovrai riazzerarli ogni volta che vuoi, ogni giorno, oppure ogni due giorni o una settimana.

    #118317 quote
    GianlucaGianluca
    Participant
    Master

    ok quindi se ho capito io faccio cosi

     

    if MieCondizioni and erashort<1 then
    sellshort 1 contract at market
    endif
    
    EraLong  = 0
    EraShort = 0
    if strategyprofit <> strategyprofit[1] then
       if positionperf(1) > 0 then
          if tradeprice(1) < tradeprice(2) then
             EraShort = 1
          elsif tradeprice(1) > tradeprice(2) then
             EraLong  = 1
          endif
       elsif positionperf(1) < 0 then
          if tradeprice(1) < tradeprice(2) then
             EraLong  = 1
          elsif tradeprice(1) > tradeprice(2) then
             EraShort = 1
          endif
       endif
    endif
    
    

    GIUSTO?

    #118318 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Esatto, proprio così.

    #118327 quote
    GianlucaGianluca
    Participant
    Master

    ma per aumentare il contatore di short se ci sono più ordini invece?

    #118329 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Cosa intendi, fammi un esempio?

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

Numero massimo di trade per giorno


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Gianluca @altares Participant
Summary

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

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 01/15/2020
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...