Questi codici possono servire come implementazioni ai sistemi relativi ai canali di Donchian, cioè quelli esposti nella pagina precedente.
Per gli esempi seguenti utilizzo come base il sistema del canale di donchian + il supertrend come stop loss in versione breakout, ma possono essere utilizzati anche gli altri due sistemi: quello a 1 canale di Donchian e quello a 2 canali di Donchian.
Inoltre utilizzo ancora il comando BUY 1 SHARES per semplicità, con 10.000 $ per lotto con un conto totale di 10.000 $.
Inserisco comunque anche l'opzione con la % di rischio per il dimensionamento della posizione in base al capitale.
Per quanto riguarda i titoli azionari e le commodities togliete la voce spread.
Se vogliamo aggiungere più posizioni successive di acquisto e di vendita durante la continuazione del trend dobbiamo prima di tutto introdurre il comando:
defparam cumulateorders=true all'inizio del sistema.
Dobbiamo poi, implementare alcune condizioni in modo che gli ulteriori contratti o azioni vengano acquistati o venduti quando il prezzo è prima del breakout, in situazione di trading range, cioè in momentanea pausa dal trend.
In questo modo compreremo quando il prezzo esce da un Box (vedi strategia di Darvas).
Queste congestioni possono essere individuate quando la resistenza o il supporto maggiore, cioè le linee del canale di Donchian sono per un certo "periodo" orizzontali.
Inoltre, quando i massimi giornalieri (per l'uptrend) sono più bassi o i minimi (per il downtrend) sono più alti, rispetto a tali linee.
Per la prima condizione quindi potremmo scrivere:
// definizione trading range
C1=Highest[a](high)[1]=Highest[a](high)[6]
C2=Lowest[a](low)[1]=Lowest[a](low)[6]
Cioè, che la linea del canale di donchian è la stessa da oggi a 5 giorni fa [6].
Il periodo può essere ovviamente cambiato.
Per la seconda condizione, potremmo scrivere:
// definizione prezzo all'interno del box
C3=Highest[5](High)<Highest[a](High)[1]
C4=Lowest[5](low)>Lowest[a](low)[1]
Vale a dire, che il massimo più alto dei 5 periodi o giorni precedenti al breakout deve essere inferiore alla resistenza del canale di donchian o che il più basso minimo dei 5 giorni precedenti al breakdown deve essere superiore al supporto del canale di donchian.
In pratica deve formarsi 1 settimana di trading range o di ritracciamento precedente al breakout.
Anche in questo caso il periodo [5] può essere cambiato a piacimento.
In questo esempio le entrate successive non sono vincolate dal fatto che i trades precedenti siano a breakeven, cioè che il trailing profit sia a livello di entry.
Le condizioni per ogni trade sono quelle di perforazione della resistenza o del supporto (resistenza e supporto) per la prima entrata e per le successive defininiamo anche il trading range (C3, C4 e C5, C6).
VARIABILI PER TUTTI GLI ESEMPI ESPOSTI:
Canale di Donchian: 40-200 passo 5
X=1-4 passo 0.5
Y=8-30 passo 2
_________________________________________________________________________________
VERSIONE A BREAKOUT DI PREZZO
DEFPARAM CUMULATEORDERS=TRUE
// definizione indicatori
resistenza = Highest[a](High)
supporto = Lowest[a](Low)
stoploss= supertrend[x,y]
// definizione condizioni
C1=close>stoploss
C2=close<stoploss
C3=resistenza[1]=Highest[a](high)[6]
C4=supporto[1]=Lowest[a](low)[6]
C5=Highest[5](High)<resistenza[1]
C6=Lowest[5](low)>supporto[1]
// prima apertura long
IF not longonmarket and resistenza and C1 then
buy 1 SHARES AT resistenza STOP
endif
// aperture successive long
IF longonmarket and resistenza and C1 and C3 and C5 then
buy 1 SHARES AT resistenza STOP
endif
// chiusura long
If C2 or stoploss and LONGONMARKET THEN
SELL AT STOPLOSS STOP
ENDIF
// prima apertura short
if not shortonmarket and supporto and C2 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// aperture successive short
if shortonmarket and supporto and C2 and C4 and C6 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// chiusura short
If C1 or stoploss and SHORTONMARKET THEN
EXITSHORT AT STOPLOSS STOP
ENDIF
Risultato : 168,31%
canale di donchian= 75
X=3.5
Y=8
_________________________________________________________________________________
CODICI PER % DI RISCHIO, VERSIONE CLASSICA (NEXTBAR OPEN)
// prima apertura long
IF not longonmarket and resistenza and C1 then
BUY 200/(Close-stoploss) SHARES AT MARKET
endif
// aperture successive long
IF longonmarket and resistenza and C1 and C3 and C5 then
BUY 200/(Close-stoploss) SHARES AT MARKET
endif
// prima apertura short
if not shortonmarket and supporto and C2 THEN
SELLSHORT 200/(stoploss-close) SHARES AT MARKET
ENDIF
// aperture successive short
if shortonmarket and supporto and C2 and C4 and C6 THEN
SELLSHORT 200/(stoploss-close) SHARES AT MARKET
ENDIF
_________________________________________________________________________________
CODICI PER % DI RISCHIO, VERSIONE A BREAKOUT DI PREZZO
// prima apertura long
IF not longonmarket and resistenza and C1 then
BUY 200/(resistenza-stoploss) SHARES AT resistenza STOP
endif
// aperture successive long
IF longonmarket and resistenza and C1 and C3 and C5 then
BUY 200/(resistenza-stoploss) SHARES AT resistenza STOP
endif
// prima apertura short
if not shortonmarket and supporto and C2 THEN
SELLSHORT 200/(stoploss-supporto) SHARES AT supporto STOP
ENDIF
// aperture successive short
if shortonmarket and supporto and C2 and C4 and C6 THEN
SELLSHORT 200/(stoploss-supporto) SHARES AT supporto STOP
ENDIF
Ulteriormente, potreste volere che la nuova posizione in aggiunta alla precedente venga aperta solo quando lo stop loss relativo ha raggiunto il livello di entry, cioè che sia a breakeven.
In questo caso, basta aggiungere le seguenti condizioni di acquisto e di vendita come abbiamo visto nella prima pagina dedicata ai comandi base:
// prima posizione long
if not longonmarket and TueCondizioni then
buy 1 shares at market
endif
// long posizioni successive
if longonmarket and stoploss>=tradeprice(1) and TueCondizioni then
buy 1 shares at market
endif
// prima posizione short
if not shortonmarket and TueCondizioni then
sellshort 1 shares at market
endif
// short posizioni successive
if shortonmarket and stoploss<=tradeprice(1) and TueCondizioni then
selsshort 1 shares at market
endif
Potete scegliere di scrivere prima le condizioni e poi richiamarle nelle istruzioni di acquisto e vendita appena viste:
C1=stoploss>=tradeprice(1) (per un trade long)
C2=stoploss<=tradeprice(1) (per un trade short)
_________________________________________________________________________________________
MULTIPOSIZIONE CON LA CONDIZIONE DI BREAK EVEN DEI TRADES PRECEDENTI.
DEFPARAM CUMULATEORDERS=TRUE
// definizione indicatori
resistenza = Highest[a](High)
supporto = Lowest[a](Low)
stoploss= supertrend[x,y]
// definizione condizioni
C1=close>stoploss
C2=close<stoploss
C3=resistenza[1]=resistenza)[6]
C4=supporto[1]=supporto[6]
C5=Highest[5](High)<resistenza[1]
C6=Lowest[5](low)>supporto[1]
C7=stoploss>=tradeprice(1)
C8=stoploss<=tradeprice(1)
// apertura long prima posizione
IF not longonmarket and resistenza and C1 then
BUY 1 SHARES AT resistenza STOP
ENDIF
// long posizioni successive
IF longonmarket and resistenza and C1 and C3 and C5 and C7 then
buy 1 SHARES AT resistenza STOP
endif
// chiusura long
If C2 or stoploss and LONGONMARKET THEN
SELL AT STOPLOSS STOP
ENDIF
// apertura short prima posizione
if not shortonmarket and supporto and C2 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// short posizioni successive
if shortonmarket and supporto and C2 and C4 and C6 and C8 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// chiusura short
If C1 or stoploss and SHORTONMARKET THEN
EXITSHORT AT STOPLOSS STOP
ENDIF
Risultato : 87,38 %
canale di donchian= 80
X=3.5
Y=8
_________________________________________________________________________________
CODICI PER % DI RISCHIO, VERSIONE CLASSICA E VERSIONE BREAKOUT:
VEDI PARAGRAFO PRECEDENTE PIU' LE CONDIZIONI C7 E C8.
Queste istruzioni vanno aggiunte alle istruzioni IF LONGONMARKET per determinare L'AMMONTARE TOTALE di acquisti e vendite.
Per esempio, se determinate l'ammontare del lotto FOREX a 1000, significa che 1 contratto o share equivale a 1.000 $ della valuta base.
Quando vogliamo limitare l'acquisto a 4 contratti o 4.000 $, dovremo specificare nel codice di acquisto:
IF COUNTOFLONGSHARES < 5 AND TueCondizioni THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
Nel codice di entrata in posizione short:
IF COUNTOFSHORTSHARES < 5 AND TueCondizioni THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
In questo modo sostituiamo quindi il codice IF NOT LONGONMARKET con i codici delle posizioni massime long e short.
_________________________________________________________________________________
ATTENZIONE:
Quando non definite il lotto dei contratti nella sezione di destra, ma utilizzate la formula della % di rischio:
BUY 200/(ENTRY - STOP LOSS) SHARES AT MARKET per i trades long e
BUY 200/(STOP LOSS-ENTRY) SHARES AT MARKET per i trades short
dovete capire che la definizione del lotto negoziabile non è fissa ma è variabile.
Quindi, non abbiamo per esempio nelle azioni un LOTTO specifico ma azioni il cui numero varia in base ai livelli di prezzo di ENTRY e di STOP LOSS.
Quindi, in base al prezzo del titolo dovremmo fare una stima della posizione totale che vogliamo assumere in quel particolare mercato e dobbiamo porre un limite di
posizione totale $.
Ad esempio un controvalore di 10.000 azioni acquistabili totalmente od un controvalore di 100.000 $ di lotti forex.
_________________________________________________________________________________
Per ovviare a questo odioso calcolo estimativo, basta definire a priori l'order size, cioè la taglia del nostro lotto:
ORDERSIZELONG=200/(entry-stoploss)
ORDERSIZESHORT=200/(stoploss-entry)
Una volta decisa la % in soldi del nostro rischio per acquistare le azioni (in questo esempio 200$ - 2% di 10.000$ di capitale), definiamo il numero massimo di trades che il sistema dovrebbe fare.
Esempio:
IF COUNTOFLONGSHARES < (ORDERSIZELONG*4) AND TueCondizioni THEN
BUY ORDERSIZELONG CONTRACTS AT MARKET
ENDIF
IF COUNTOFSHORTSHARES < (ORDERSIZESHORT*4) AND TueCondizioni THEN
BUY ORDERSIZESHORT CONTRACTS AT MARKET
ENDIF
Il sistema riconoscerà l'ammontare di rischio totale equivalente a 4 trades come limite massimo di posizione.
_________________________________________________________________________________
MULTIPOSIZIONE CON LIMITAZIONE A 4 TRADES SENZA LA CONDIZIONE DI BREAK EVEN DEI TRADES PRECEDENTI.
In questo esempio le entrate successive non sono vincolate dal fatto che i trades precedenti siano a break even.
Settiamo il numero di massime posizioni a 4, la prima più altre 3 in aggiunta: (COUNTOFLONGSHARES < 4).
Le condizioni per ogni trade sono quelle di perforazione della resistenza o del supporto (C3 E C4) dopo un minimo di trading range (C3, C4, C5, C6).
DEFPARAM CUMULATEORDERS=TRUE
// definizione indicatori
resistenza = Highest[a](High)
supporto = Lowest[a](Low)
stoploss= supertrend[x,y]
// definizione condizioni
C1=close>stoploss
C2=close<stoploss
C3=resistenza[1]=resistenza[6]
C4=supporto[1]=supporto[6]
C5=Highest[5](High)<resistenza[1]
C6=Lowest[5](low)>supporto[1]
// apertura long
IF not longonmarket and resistenza and C1 then
buy 1 SHARES AT resistenza STOP
endif
// aperture successive long
IF longonmarket and COUNTOFLONGSHARES < 4 and resistenza and C1 and C3 and C5 then
buy 1 SHARES AT resistenza STOP
endif
// chiusura long
If C2 or stoploss and LONGONMARKET THEN
SELL AT STOPLOSS STOP
ENDIF
// apertura short
if not shortonmarket and supporto and C2 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// aperture successive short
if shortonmarket and COUNTOFSHORTSHARES < 4 and supporto and C2 and C4 and C6 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// chiusura short
If C1 or stoploss and SHORTONMARKET THEN
EXITSHORT AT STOPLOSS STOP
ENDIF
Risultato : 143,32 %
canale di donchian= 75
X=3
Y=30
_________________________________________________________________________________
CODICI PER % DI RISCHIO, VERSIONE CLASSICA (NEXTBAR OPEN)
// dimensionamento della posizione
ordersizelong=200/(resistenza-stoploss)
ordersizeshort=200/(stoploss-supporto)
// prima apertura long
IF not longonmarket and resistenza and C1 then
BUY ordersizelong SHARES AT MARKET
endif
// aperture successive long
IF longonmarket and countoflongshares<ordersizelong*4 and resistenza and C1 and C3 and C5 then
BUY ordersizelong SHARES AT MARKET
endif
// prima apertura short
if not shortonmarket and supporto and C2 then
SELLSHORT ordersizeshort SHARES AT MARKET
ENDIF
// aperture successive short
if shortonmarket and countofshortshares<ordersizeshort*4 and supporto and C2 and C4 and C6 then
SELLSHORT ordersizeshort SHARES AT MARKET
ENDIF
_________________________________________________________________________________
CODICI PER % DI RISCHIO, VERSIONE A BREAKOUT DI PREZZO
// dimensionamento della posizione
ordersizelong=200/(resistenza-stoploss)
ordersizeshort=200/(stoploss-supporto)
// prima apertura long
IF not longonmarket and resistenza and C1 then
BUY ordersizelong SHARES AT resistenza STOP
endif
// aperture successive long
IF longonmarket and countoflongshares<ordersizelong*4 and resistenza and C1 and C3 and C5 then
BUY ordersizelong SHARES AT resistenza STOP
endif
// prima apertura short
if not shortonmarket and supporto and C2 THEN
SELLSHORT ordersizeshort SHARES AT supporto STOP
ENDIF
// aperture successive short
if shortonmarket and countofshortshares<ordersizeshort*4 and supporto and C2 and C4 and C6 THEN
SELLSHORT ordersizeshort SHARES AT supporto STOP
ENDIF
Se volete combinare le due condizioni precedenti e cioè, aprire più posizioni una volta che il precedente trade è giunto a BREAKEVEN dovete prima impostare il trade di apertura (con l'istruzione IF NOTLONGONMARKET) e poi impostare i successivi trade a breakeven (con l'istruzione IF LONGONMARKET) con questi comandi:
// apertura long prima posizione
IF not longonmarket and tue condizioni then
BUY 1 SHARES AT MARKET
ENDIF
// long posizioni successive
IF longonmarket and COUNTOFLONGSHARES < 5 and tue condizioni and stoploss>=tradeprice(1) then
buy 1 SHARES AT MARKET
endif
// chiusura long
If LONGONMARKET and tue condizioni THEN
SELL ATMARKET
ENDIF
// apertura short prima posizione
if not shortonmarket and tue condizioni THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
// short posizioni successive
if shortonmarket and COUNTOFSHORTSHARES < 5 and tue condizioni and stoploss<=tradeprice(1)THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
// chiusura short
If SHORTONMARKET and tue condizioni THEN
EXITSHORT AT MARKET
ENDIF
_________________________________________________________________________________________
MULTIPOSIZIONE CON LIMITAZIONI 4 TRADES CON LA CONDIZIONE DI BREAK EVEN DEI TRADES PRECEDENTI
In questo esempio, oltre alle condizioni viste prima, aggiungiamo quelle riguardanti al break even delle posizioni precedenti: C7 e C8 solo nelle istruzioni relative all'apertura di posizioni successive alla prima.
DEFPARAM CUMULATEORDERS=true
// definizione indicatori
resistenza = Highest[a](High)
supporto = Lowest[a](Low)
stoploss= supertrend[x,y]
// definizione condizioni
C1=close>stoploss
C2=close<stoploss
C3=resistenza[1]=resistenza[6]
C4=supporto[1]=supporto[6]
C5=Highest[5](High)<resistenza[1]
C6=Lowest[5](low)>supporto[1]
C7=stoploss>=tradeprice(1)
C8=stoploss<=tradeprice(1)
// apertura long prima posizione
IF not longonmarket and resistenza and C1 then
BUY 1 SHARES AT resistenza STOP
ENDIF
// long posizioni successive
IF longonmarket and COUNTOFLONGSHARES < 4 and resistenza and C1 and C3 and C5 and C7 then
buy 1 SHARES AT resistenza STOP
endif
// chiusura long
If C2 or stoploss and LONGONMARKET THEN
SELL AT STOPLOSS STOP
ENDIF
// apertura short prima posizione
if not shortonmarket and supporto and C2 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// short posizioni successive
if shortonmarket and COUNTOFSHORTSHARES < 4 and supporto and C2 and C4 and C6 and C8 THEN
SELLSHORT 1 SHARES AT supporto STOP
ENDIF
// chiusura short
If C1 or stoploss and SHORTONMARKET THEN
EXITSHORT AT STOPLOSS STOP
ENDIF
Risultato : 87,37 %
canale di donchian= 80
X=3,5
Y=8
_________________________________________________________________________________
CODICI PER % DI RISCHIO, VERSIONE CLASSICA E VERSIONE BREAKOUT:
VEDI PARAGRAFO PRECEDENTE.
Il passo naturale seguente è quello di aprire più posizioni successive ma mediante la ben nota tecnica di money management chiamata “piramidazione” che consiste nell’aggiungere più posizioni ma in quantità sempre minore rispetto a quella del trade precedente, cioè "piramidare" una posizione di base.
Se aggiungiamo più posizioni uguali, è come se aprissimo diversi trade successivi sullo stesso strumento.
La logica sottostante della piramidazione è invece quella di rischiare sempre meno man mano che il trend avanza verso il suo apice e le probabilità di esaurimento del trend aumentano.
Come s’intuisce dal nome, la grandezza delle posizioni viene definita da uno schema piramidale.
1) Per prima cosa dobbiamo definire una % di rischio totale sul nostro capitale.
Consiglio di non andare oltre il 5%.
Possiamo definire tale % in contratti a lotto fisso come per il forex (1 shares=10.000 $ per esempio) o come % di rischio sul capitale rischio/(entry-stop loss) come abbiamo visto più volte.
2) Il secondo step è quello di decidere il numero massimo di posizioni successive che vogliamo aprire, cioè definiamo i livelli della nostra piramide:
Possiamo decidere se piramidare a 2, 3 , 4 o 5 livelli.
In base ai livelli della piramide, possiamo definire le nostre unità di rischio o UNIT (i pallini blu):
- 2 livelli: 3 unit
- 3 livelli: 6 unit
- 4 livelli: 10 unit
- 5 livelli: 15 unit
3) Dividiamo la % totale di rischio per il numero di unit della piramide.
Prendiamo per esempio quella a 4 livelli:
5 % /10 unit = 0,5% di rischio per unit.
Se il nostro capitale è 10.000 $, il rischio per unit è 50 $.
Se invece del 5% sul capitale, abbiamo definito che per il nostro backtest i lotti forex massimi acquistabili sono 5 minilotti (50.000 $ di controvalore), avremo che ogni UNIT sarà pari a:
50.000$/10=5.000 $ e cioè 5 microlotti per unit
Questo è quello che dovremo impostare come lotto base di acquisto, in altre parole
1 shares: 5.000 $.
4) Ora calcoliamo gli unit per ogni posizione:
1° posizione: 4 unit ossia 2% sul capitale oppure 4 shares (2.000 $)
2° posizione: 3 unit ossia 1,5% sul capitale oppure 3 shares (1.500 $)
3° posizione: 2 unit ossia 1% sul capitale oppure 2 shares (1.000 $)
4° posizione: 1 unit ossia 0,5% sul capitale oppure 1 shares (500 $)
Ecco definite le nostre quantità di entrata.
Per i backtest daremo le istruzioni per ogni singola entrata con le dimension sizing appena definite:
//prima posizione long 4 SHARES
if not longonmarket and tuecondizioni then
buy 4 shares at market
endif
//seconda posizione long 7 SHARES (4+3)
if countoflongshares = 4 and tuecondizioni then
buy 3 shares at market
endif
//terza posizione long 9 SHARES (4+3+2)
if countoflongshares = 7 and tuecondizioni then
buy 2 shares at market
endif
//quarta posizione long 10 SHARES (4+3+2+1)
if countoflongshares = 9 and tuecondizioni then
buy 1 shares at market
endif
// chiusure posizioni long 10 SHARES
if longonmarket and tuecondizioni then
sell at market
lo stesso facciamo per le posizioni short:
//prima posizione short 4 SHARES
if not shortonmarket and tuecondizioni then
sellshort 4 shares at market
endif
//seconda posizione short 7 SHARES (4+3)
if countofshortshares = 4 and tuecondizioni then
sellshort 3 shares at market
endif
//terza posizione short 9 SHARES (4+3+2)
if countofshortshares = 7 and tuecondizioni then
sellshort 2 shares at market
endif
//quarta posizione short 10 SHARES (4+3+2+1)
if countofshortshares = 9 and tuecondizioni then
sellshort 1 shares at market
endif
// chiusure posizioni short 10 SHARES
if longonmarket and tuecondizioni then
exitshort at market
Se partiamo da una base di 10000$ pari ad 1 shares, come abbiamo fatto per i precedenti sistemi, dobbiamo determinare quanto è l'unit.
Facciamo 10000/4 e troviamo il lotto unit minimo: 10000/5=2500 $.
Questo è quello che impostiamo come lotto base nella finestra di programmazione, in modo che la prima posizione sia 4 lotti, cioè 10.000 $, la seconda posizione siano 3 lotti, cioè 7.500 $, la terza 5.000 $ e l'ultima 2.500$.
DEFPARAM CUMULATEORDERS=true
// definizione indicatori
resistenza = Highest[a](High)
supporto = Lowest[a](Low)
stoploss= supertrend[x,y]
// definizione condizioni
C1=close>stoploss
C2=close<stoploss
C3=resistenza[1]=resistenza[6]
C4=supporto[1]=supporto[6]
C5=Highest[5](High)<resistenza[1]
C6=Lowest[5](low)>supporto[1]
// apertura long prima posizione
IF not longonmarket and resistenza and C1 then
BUY 4 SHARES AT resistenza STOP
ENDIF
//seconda posizione long
IF longonmarket and COUNTOFLONGSHARES = 4 and resistenza and C1 and C3 and C5 then
buy 3 SHARES AT resistenza STOP
endif
//terza posizione long
IF longonmarket and COUNTOFLONGSHARES = 7 and resistenza and C1 and C3 and C5 then
buy 2 SHARES AT resistenza STOP
endif
//ultima posizione long
IF longonmarket and COUNTOFLONGSHARES = 9 and resistenza and C1 and C3 and C5 then
buy 1 SHARES AT resistenza STOP
endif
// chiusura posizioni long
If C2 or stoploss and LONGONMARKET THEN
SELL AT STOPLOSS STOP
ENDIF
// apertura short prima posizione
if not shortonmarket and supporto and C2 THEN
SELLSHORT 4 SHARES AT supporto STOP
ENDIF
//seconda posizione short
if shortonmarket and countofshortshares = 4 and supporto and C2 and C4 and C6 then
SELLSHORT 3 SHARES AT supporto STOP
endif
//terza posizione short
if shortonmarket and countofshortshares = 7 and supporto and C2 and C4 and C6 then
SELLSHORT 2 SHARES AT supporto STOP
endif
//ultima posizione short
if shortonmarket and countofshortshares = 9 and supporto and C2 and C4 and C6 then
SELLSHORT 1 SHARES AT supporto STOP
endif
// chiusura posizioni short
If C1 or stoploss and SHORTONMARKET THEN
EXITSHORT AT STOPLOSS STOP
ENDIF
Risultato : 102,53 %
canale di donchian= 75
X=3
Y=30
DEFPARAM CUMULATEORDERS=true
// definizione indicatori
resistenza = Highest[a](High)
supporto = Lowest[a](Low)
stoploss= supertrend[x,y]
// definizione condizioni
C1=close>stoploss
C2=close<stoploss
C3=resistenza[1]=resistenza[6]
C4=supporto[1]=supporto[6]
C5=Highest[5](High)<resistenza[1]
C6=Lowest[5](low)>supporto[1]
C7=stoploss>=tradeprice(1)
C8=stoploss<=tradeprice(1)
// apertura long prima posizione
IF not longonmarket and resistenza and C1 then
BUY 4 SHARES AT resistenza STOP
ENDIF
//seconda posizione long
IF longonmarket and COUNTOFLONGSHARES = 4 and resistenza and C1 and C3 and C5 and C7 then
buy 3 SHARES AT resistenza STOP
endif
//terza posizione long
IF longonmarket and COUNTOFLONGSHARES = 7 and resistenza and C1 and C3 and C5 and C7 then
buy 2 SHARES AT resistenza STOP
endif
//ultima posizione long
IF longonmarket and COUNTOFLONGSHARES = 9 and resistenza and C1 and C3 and C5 and C7 then
buy 1 SHARES AT resistenza STOP
endif
// chiusura posizioni long
If C2 or stoploss and LONGONMARKET THEN
SELL AT STOPLOSS STOP
ENDIF
// apertura short prima posizione
if not shortonmarket and supporto and C2 THEN
SELLSHORT 4 SHARES AT supporto STOP
ENDIF
//seconda posizione short
if shortonmarket and countofshortshares = 4 and supporto and C2 and C4 and C6 and C8 then
SELLSHORT 3 SHARES AT supporto STOP
endif
//terza posizione short
if shortonmarket and countofshortshares = 7 and supporto and C2 and C4 and C6 and C8 then
SELLSHORT 2 SHARES AT supporto STOP
endif
//ultima posizione short
if shortonmarket and countofshortshares = 9 and supporto and C2 and C4 and C6 and C8 then
SELLSHORT 1 SHARES AT supporto STOP
endif
// chiusura posizioni short
If C1 or stoploss and SHORTONMARKET THEN
EXITSHORT AT STOPLOSS STOP
ENDIF
Risultato : 78,54 %
canale di donchian= 80
X=3,5
Y=8
Al momento non sono riuscito ad impostare il sistema della piramidazione con la formula della % di rischio sul capitale.
La difficoltà deriva dal fatto di non essere in grado di definire specifici n° di lotti precedenti e totali, come nel caso appena visto di numero di shares.
Scrivi commento