ProRealCode - Trading & Coding with ProRealTime™
Salve a tutti,
Ho fatto realizzare un TS ,ma vanno fatte Delle modifiche,posso fornire il codice completo con tutte le spiegazioni necessarie,pronto a condividere tutto
Grazie
Edoardo
Se vuoi che qualcuno ti aiuti devi certamente postare il codice per condividerlo.
Poi chi si sentirà in grado di aiutarti lo farà con piacere, nei tempi e modi in cui potrà dedicarcisi.
Buon trading.
Roberto
Certamente,
sono alla prima richiesta,quindi non sapevo di dover pubblicare subito il codice :
defparam cumulateorders = false
// --- parameters
ActivatePattern1 = 1//activate or not the 1st pattern (0=false) -> PINBAR PATTERN
ActivatePattern2 = 0//activate or not the 2nd pattern (0=false) -> SECOND PATTERN
ActivatePattern3 = 1 //activate or not the 3rd pattern (0=false) -> THIRD PATTERN
MAtype = 1 //0=SMA ; 1=EMA
MAperiod = 100 //Moving average period
MAprice = close //MA price (close,high,low,open)
MAdifference = 0 //points difference from moving average and the pinbar (0=disable)
CandleCount = 5//candles count above/below Moving Average
MinimoMassimoDecrescente = 0 //minimum candles to increase or decrease before pattern 1,2 or 3
MaxStop = 30//maximum stoploss value in points15
MinStop = 5//minimum stoploss value in points
TimeStart = 080000 //time to start the strategy
TimeEnd = 170000 //time to end the strategy
MaxTradesPerDay = 5 //max quantity of trades each day
BarsExpiration = 1 //how much bars to wait to expire pending orders
PointsToKeep = 1 //how much points to keep above or below the openprice when breakeven (50% profit reached)
// ---
once buylevel=0
once selllevel=0
if longonmarket or barindex-tradeindex(1)<BarsExpiration then
// set buy level @ 0 to avoid new pending order
buylevel = 0
endif
if shortonmarket or barindex-tradeindex(1)<BarsExpiration then
// set sell level @ 0 to avoid new pending order
selllevel = 0
endif
if intradaybarindex = 0 then
tradecount = 0
endif
tcondition = time>=TimeStart and time<TimeEnd
if MAtype=1 then
ma = exponentialaverage[MAperiod](MAprice)
else
ma = average[MAperiod](MAprice)
endif
//Trade count
if onmarket and tradeprice<>savedprice then
tradecount = tradecount+1
savedprice = tradeprice
endif
//Candles count
if close>ma then
above = above+1
below = 0
endif
if close<ma then
above = 0
below = below+1
endif
//Increase/Decrease count
if MinimoMassimoDecrescente>0 then
lowincrease = summation[MinimoMassimoDecrescente+1](low>low[1])
highdecrease = summation[MinimoMassimoDecrescente+1](high<high[1])
else
lowincrease = 1
highdecrease = 1
endif
//Pin Bar
body = abs(open-close)>=1*pointsize
if close>open then
bullishtail = (open-low>=0.33*range)
bullishnose = (high-close<0.18*range)
bearishtail = (high-close>=0.33*range)
bearishnose = (open-low<0.18*range)
else
bullishtail = (close-low>=0.33*range)
bullishnose = (high-open<0.18*range)
bearishtail = (high-open>=0.33*range)
bearishnose = (close-low<0.18*range)
endif
if ActivatePattern1 then
buypattern1 = body and bullishtail and bullishnose and highdecrease>=MinimoMassimoDecrescente and low<low[1] and close>open//and low>ma and low[1]>(high+low)/2 //+50%
sellpattern1 = body and bearishtail and bearishnose and lowincrease>=MinimoMassimoDecrescente and high>high[1] and close<open//and high<ma and high[1]<(high+low)/2 //+50%
else
buypattern1 = 0
sellpattern1 = 0
endif
//Max Above / Below patterns
if ActivatePattern2 then
buypattern2 = close>open and summation[2](close[1]<open[1])=2 and high>high[1] and low<low[1] and highdecrease>=MinimoMassimoDecrescente
sellpattern2 = close<open and summation[2](close[1]>open[1])=2 and high>high[1] and low<low[1] and lowincrease>=MinimoMassimoDecrescente
else
buypattern2 = 0
sellpattern2 = 0
endif
//Pattern 3
if ActivatePattern3 then
buypattern3 = close>open and summation[2](close[1]<open[1])=2 and high>high[1] and low<low[1] and highdecrease>=MinimoMassimoDecrescente
sellpattern3 = close<open and summation[2](close[1]>open[1])>=1 and high>high[1] and low>low[1] and lowincrease>=MinimoMassimoDecrescente
else
buypattern3 = 0
sellpattern3 = 0
endif
//MA difference activate or not
if MAdifference=0 then
buydiff = 1
selldiff = 1
else
buydiff = low-ma>=MAdifference*pointsize
selldiff = ma-high>=MAdifference*pointsize
endif
//long conditions tested
if not longonmarket and (buypattern1 or buypattern2 or buypattern3) and tcondition and tradecount<MaxTradesPerDay and above>=candlecount and buydiff then
savedbarindex = barindex
buylevel = high
stoplossvalue = range
//buySL = low
endif
while not longonmarket and buylevel>0 and barindex<=savedbarindex+BarsExpiration and stoplossvalue<MaxStop*pointsize and stoplossvalue>MinStop*pointsize and not onmarket[1] and barindex>tradeindex(1)+BarsExpiration and tcondition do
buy 1 share at buylevel stop
wend
//short conditions tested
if not shortonmarket and (sellpattern1 or sellpattern2 or sellpattern3) and tcondition and tradecount<MaxTradesPerDay and below>=candlecount and selldiff then
savedbarindex = barindex
selllevel = low
stoplossvalue = range
//sellSL = high
endif
while not shortonmarket and selllevel>0 and barindex<=savedbarindex+BarsExpiration and stoplossvalue<MaxStop*pointsize and stoplossvalue>MinStop*pointsize and not onmarket[1] and barindex>tradeindex(1)+BarsExpiration and tcondition do
sellshort 1 share at selllevel stop
wend
set target profit stoplossvalue
set stop loss stoplossvalue
//BREAKEVEN
if PointsToKeep>0 then
//set the breakeven level
startBreakeven = (stoplossvalue/2)/pipsize
//reset the breakevenLevel when no trade are on market
IF NOT ONMARKET THEN
breakevenLevel=0
ENDIF
// --- BUY SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
if longonmarket then
IF close-tradeprice(1)>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
//place the stop for the first time
//if breakevenlevel=0 then
//sell at buySL stop
//endif
endif
// --- end of BUY SIDE ---
// --- SELL SIDE ---
//test if the price have moved favourably of "startBreakeven" points already
if shortonmarket then
IF tradeprice(1)-close>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
SELLSHORT AT breakevenLevel STOP
ENDIF
//place the stop for the first time
//if breakevenlevel=0 then
//sellshort at sellSL limit
//endif
endif
// --- end of BUY SIDE ---
endif // end of breakeven
//graph above coloured(0,200,0) as "above"
//graph below coloured(200,0,0) as "below"
//graph bullishpinbar coloured(0,200,0) as "bull pinbar"
//graph bearishpinbar coloured(200,0,0) as "bear pinbar"
//graph buylevel coloured(0,200,0) as "buy level"
//graph selllevel coloured(200,0,0) as "sell level"
//graph buySL coloured(0,10,0) as "buy SL"
//graph sellSL coloured(10,0,0) as "sell SL"
//graph stoplossvalue
//graph startbreakeven
//graph breakevenLevel
//graph buypattern2 coloured(0,200,0)
//graph sellpattern2 coloured(200,0,0)
//grafico buypattern3 colorato (0,200,0)
//grafico sellpattern3 colorato (200,0,0)
Il ts deve eseguire i trade sopra(buy)/sotto(short) la media in base alle condizioni inserite,le condizioni dei pattern pero’ non vanno bene :
esempio:
nel caso apertura trade buy del pattern n° 3 ,il pattern deve essere rialzista (candela verde ) ed avere sempre il minimo inferiore alla candela precedente che deve essere sempre ribassista (rossa)
Per scrivere il codice , utilizza il pulsante <> “insert PRT code” che si trova nella barra grigia proprio sopra allo spazio dove scrivi il testo quando posti qualcosa. L’ho fatto io, come vedi il codice è più leggibile e facilita chi ha intenzione d’aiutarti.
Nei prossimi giorni cerco di darci un’occhiata per capire cosa fa e poi ti faccio sapere qualcosa.
Grazie!!!
Edoardo
Per qualsiasi altra informazione che possa aiutare sono sempre disponibile
Questa è la scomposizione della riga 103
buypattern3 = close>open and //Ok, Candela RIALZISTA
summation[2](close[1]<open[1])=2 and // ??? forse dovevi scrivere: close[1] < open[1] per verificare che la candela precedente fosse RIBASSISTA
high>high[1] and // ??? perché il massimo, non bastava che il minimo fosse inferiore al precedente?
low<low[1] and //Ok, Minimo inferiore al precedente
highdecrease>=MinimoMassimoDecrescente //Questo non so cosa sia
come vedi la seconda e la terza condizione mi sembrano sbagliate, la seconda puoi modificarla come ho indicato io nel commento, la terza credo dovresti toglierla se non ti interessa il massimo.
Poi riassemblala e ripeti il tutto anche per il pattern SELL.
Ripeti la verifica, riga per riga (scomponendole in modo da avere un corretto allineamento che ti facilita la comprensione) anche per gli altri pattern.
Con pazienza e dedizione arriverai alla corretta identificazione dei pattern.
Ciao,
Grazie di tutto!
Io non sono un programmatore,il ts lo fatto realizzare fornendo la strategia scritta con allegati disegni,provero’ ad applicare tutte le tue informazioni sperando di riuscirci,ti faro’ sapere se sono stato capace…
Grazie
edoardo
buypattern3 = close>open and summation[2](close[1]<open[1]=2 and close[1]<open[1]
Scusa ma provo a capire!!!
grazie!!
Ciao, per la mia ignoranza ho cambiato il modo di uscita dai trade cercando la fine dei cicli con il CCI. Ti incollo il file, è ottimizzato per il dax cash 30m.
Per scrivere il codice , utilizza il pulsante <> “insert PRT code. Grazie.
Questa è la riga scomposta come sopra descritta:
buypattern3 = close>open and //Ok, Candela RIALZISTA
summation[2](close[1]<open[1])=2 and // ??? forse dovevi scrivere: close[1] < open[1] per verificare che la candela precedente fosse RIBASSISTA
high>high[1] and // ??? perché il massimo, non bastava che il minimo fosse inferiore al precedente?
low<low[1] and //Ok, Minimo inferiore al precedente
highdecrease>=MinimoMassimoDecrescente //Questo non so cosa sia
questa dovrebbe essere, secondo me la riga corretta:
buypattern3 = close>open and close[1]<open[1] and low<low[1] and highdecrease>=MinimoMassimoDecrescente
perché la verifica dei massimi (HIGH) non è necessaria e SUMMATION mi pare che non c’entri proprio niente con quello che vuoi, perché verifica che le DUE candele precedenti siano ribassiste, mentre tu hai detto solo UNA.
Imparare a programmare non è difficile, specialmente con il linguaggio PRT che è molto semplice e privo di strutture sofisticate. Se conosci un pò l’inglese non ti sarà difficile comprendere il significato di IF…ENDIF o FOR…NEXT, per il resto sono tutti riferimenti ai prezzi (Open, Close, High, Low, Customclose) ed indicatori/oscillatori (Medie, Macd, Rsi, ecc…).
La parte più difficile è riuscire a ragionare nella logica informatica. La classica difficoltà è riconoscere una Pin Bar, perché visivamente noi la notiamo subito, mentre un PC ha bisogno di sapere come definirla, quanto deve essere grande il corpo, quanto l’ombra superiore e quanto quella inferiore, ecc…
Ciao, per la mia ignoranza ho cambiato il modo di uscita dai trade cercando la fine dei cicli con il CCI. Ti incollo il file, è ottimizzato per il dax cash 30m.
Ho visto che gira; non conosco la tua strategia e non voglio saperla.
Tu provala in demo, dopo avere verificato che i pattern siano identificati come tu desideri.
Se hai problemi con i pattern o con qualche istruzione sarò ben lieto di aiutarti,
Circa la strategia, invece, non voglio entrare nel merito delle tue scelte.
Ciao ,
grazie lo provo sicuramente,la stretegia e’ concepita su una media mobile,numero candele sopra/sotto la media,pattern ingresso,su queste basi ho inserito la possibilita’ delle variabili in base allo strumento :
tipo media ,valore media
dimensione candela da un min/amx
numero candele sopra/sotto
orario di trading
spostamento breakeven
Il problema e’ stato nelle condizioni dei pattern ingresso,quello che cerco di risolvere
Grazie veramente a tutti quelli che condividono
edoardo
Scusami Roberto ma la tua risposta mi sembra un pò infastidita come mai? Io ho semplicemente risposto ad Edo che chiedeva collaborazione ed ho apportato delle modifiche che secondo me fanno lavorare al meglio il Trading System.
Semplicemente ho identificato l’utilizzo del Commodity Channel Index come un punto di uscita migliore (dal mio punto di vista e per i trading system) dai trade rispetto alla strategia originale di Edo, ho fatto qualcosa di sbagliato?
Non preoccuparti Altares, non ero e non sono affatto infastidito. A dire la verità mi sono accorto che il post era tuo solo dopo averlo confermato.
Non hai fatto niente di sbagliato, magari non so se edocasa inserirà le tue modifiche, visto che è alle prime armi. Anzi, credo sia meglio per lui affrontare un problema per volta per poi passare ad eventuali successivi. Il suo per ora sono il corretto riconoscimento dei pattern.
Ciò non toglie che tu, come chiunque altro, possa fare le modifiche che ritiene più opportune.
Altares,
ti ringrazio infinitamente,ho testato subito il tuo ts modificato,facendo delle modifiche al setting da febbraio 2017 ad oggi funziona discretamente,ringrazio anche Roberto,ho capito il suo spirito cerca di farmi fare modifiche dietro i suoi consigli,io lo stesso ts non trovando un modo per fare modificare i pattern sbagliati lo fatto realizzare su mt4,questo per farvi capire la mia volonta’ di arrivare ad ottenere un ts funzionale.
Se Altares vorrai dedicare un po’ di tempo alla modifica dei pattern,sarei lieto di specificare il piu’ possibile la strategia
Grazie ancora a tuttti!!!
Altares,
ActivatePattern1 = 1//activate or not the 1st pattern (0=false) -> PINBAR PATTERN
ActivatePattern2 = 0//activate or not the 2nd pattern (0=false) -> SECOND PATTERN
ActivatePattern3 = 1 //activate or not the 3rd pattern (0=false) -> THIRD PATTERN
MAtype = 1 //0=SMA ; 1=EMA
MAperiod = 21 //Moving average period
MAprice = close //MA price (close,high,low,open)
MAdifference = 0 //points difference from moving average and the pinbar (0=disable)
CandleCount = 3//5//candles count above/below Moving Average
MinimoMassimoDecrescente = 0 //minimum candles to increase or decrease before pattern 1,2 or 3
MaxStop = var3//30//maximum stoploss value in points15
MinStop = 8//minimum stoploss value in points
TimeStart = 080000 //time to start the strategy
TimeEnd = 150000 //time to end the strategy
MaxTradesPerDay = 5 //max quantity of trades each day
BarsExpiration = 2 //how much bars to wait to expire pending orders
cc = CCI[20]
targetplong = (cc < var1)
targetpshort = (cc>var2)
Prova questo setting,fammi sapere cosa ne pensi
Modifica TS da condividere
This topic contains 43 replies,
has 3 voices, and was last updated by
robertogozzi
7 years, 7 months ago.
| Forum: | ProOrder: Trading Automatico & Backtesting |
| Language: | Italian |
| Started: | 12/27/2017 |
| Status: | Active |
| Attachments: | 5 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.