Grazie mille gentilissimo, mi scuso per il titolo vago grazie per la correzione. Mentre ero in effetti indeciso sulla sezione perchè in realtà nasce come indicatore che può essere utilizzato anche in una strategia automatizzata.
L’indicatore richiede 5 parametri, (di base è configurato per il Russell TF 5Min)
MyIndicator2C[2,0.3,20,0,15] [Volatilita, Spread medio asset,Fattore per moltiplicazione Spread,Tipo di grafico (0,1),TP]
Il [Tipo di grafico] serve per utilizzarlo nel grafico, o come indicatore
Quindi può essere caricato ed utilizzato in 2 modi
- Sul grafico in modo che possa disegnare le frecce per indicare entrate ed uscite [Tipo di grafico=0]
- Come indicatore in modo che indichi gli stati (-2,-1,2,1) per utilizzarlo in una strategia o associarlo ad allarmi [Tipo di grafico=1]
Per rispondere alle tue richieste:
- lo stesso codice che hai usato tu [Lo pubbico sotto]
- lo strumento su cui l’hai eseguito [US Russell 2000 Cash ($10)
- il time frame usate [5 Minuti]
- il numero di unità di barre usate [15000]
- il periodo (da… a…) [Tutto]
- lo spread + eventuali commissioni [0.3]
- data ed ore delle candele dove si è verificata un’entrata/uscita errata oppore una mancara entrata/uscita [Entrate non segnalate dall’indicatore 30/03/2020 03:10, 30/03/2020 10:25, 30/03/2020 18:20]
Inserisco il codice qui di seguito, come dicevo non è molto “elegante” è ancora in fase beta:
Indicatore:
//Candele HA
IF BarIndex = 0 THEN
XClose = TotalPrice
XOpen = (Open + Close) / 2
XHigh = MAX(XOpen,XClose)
XHigh = Max(XHigh,high)
XLow = MIN(XOpen,XClose)
XLow = MIN(XLow,Low)
ELSE
XClose = TotalPrice
XOpen = (XOpen[1] + Xclose[1]) / 2
XHighTemp = MAX(XOpen,XClose)
XHigh = Max(XHighTemp,high)
XLowTemp = MIN(XOpen,XClose)
XLow = MIN(XLowTemp,Low)
ENDIF
CandeleTFBig=120 // 120 periodi a 5 min = 1h
CandelaBig1=0
CandelaBig2=0
OpenTFBig1=XOpen[CandeleTFBig]
CloseTFBig1=XClose[1]
if OpenTFBig1>CloseTFBig1 then
CandelaBig1=-1
else
CandelaBig1=1
endif
OpenTFBig2=XOpen[CandeleTFBig*2]
CloseTFBig2=OpenTFBig1[1]
if OpenTFBig2>CloseTFBig2 then
CandelaBig2=-1
else
CandelaBig2=1
endif
Trend=0
if CandelaBig1=1 and CandelaBig2=1 then
Trend=1
endif
if CandelaBig1=-1 and CandelaBig2=-1 then
Trend=-1
endif
//Volatilita ultime
VolLast=0
For iVol=1 to 6 do
VolTot= ABS(XOpen[iVol] - XClose[iVol] )
VolLast=VolLast+VolTot
next
VolLast=VolLast/6
IF XClose >= XOpen THEN
Candela = 1
//ConteggioDown=0
//ConteggioUp=ConteggioUp+1
if LastCandela=0 then
//LastConteggioCandele=ConteggioCandela
ConteggioCandela=0
//PrezzoChiusura=XClose[1]
//VolTrend=abs(PrezzoApertura-PrezzoChiusura)
endif
//PrezzoApertura=XOpen
ConteggioCandela=ConteggioCandela+1
LastCandela=1
else
Candela = -1
//ConteggioUp=0
//ConteggioDown=ConteggioDown+1
if LastCandela=1 then
//LastConteggioCandele=ConteggioCandela
ConteggioCandela=0
//PrezzoChiusura=XClose[1]
//VolTrend=abs(PrezzoApertura-PrezzoChiusura)
endif
//PrezzoApertura=XOpen
ConteggioCandela=ConteggioCandela+1
LastCandela=0
endif
VolBigTrand=3
BigTrendLong=0
if Candela[1]=-1 and Volatilita[1]>VolBigTrand and Candela[2]=-1 and Volatilita[2]>VolBigTrand and Candela[3]=-1 and Volatilita[3]>VolBigTrand and Candela[4]=-1 and Volatilita[4]>VolBigTrand and Candela[5]=-1 and Volatilita[5]>VolBigTrand then
if Candela=1 and Candela[1]=1 then
BigTrendLong=1
endif
endif
BigTrendShort=0
if Candela[1]=1 and Volatilita[1]>VolBigTrand and Candela[2]=1 and Volatilita[2]>VolBigTrand and Candela[3]=1 and Volatilita[3]>VolBigTrand and Candela[4]=1 and Volatilita[4]>VolBigTrand and Candela[5]=1 and Volatilita[5]>VolBigTrand then
if Candela=-1 and Candela[1]=-1 then
BigTrendShort=1
endif
endif
OraInizio=070000
OraFine=230000
//OraLimite=235900
//TradeOn=0
if Time >= OraInizio and Time <= OraFine then
//TradeOn=1
endif
Volatilita= ABS(XOpen - XClose )
if (ABS(XOpen - XClose ) <= ((XHigh - XLow ) * 0.1)) then
Doji=1
else
Doji=0
endif
if Doji=1 then
ConteggioDoji=ConteggioDoji+1
else
if Volatilita>1 then
ConteggioDoji=0
endif
endif
//MM=Average(7)
//MME=ExponentialAverage[12](close)
//MMW=WeightedAverage[20](close)
MMEP=EndPointAverage[120](close)
//WILLR=Williams[21](close)
//SUPERT=Supertrend[6,12]
StatoPosizione=0
ValPipVolatilita=pipsize*ValVolatilita
//ValProfit=40
//ValSpread=0.3
//ValSpreadX=10
if 1=1 then
if Candela=1 and PositionLongOpen=0 and PositionShortOpen=0 and Trend=1 and xOpen>=MMEP and ConteggioCandela<=4 and Candela[ConteggioCandela+2]=1 and Volatilita>ValPipVolatilita and Volatilita<ValPipVolatilita*6 or PositionLongOpen=0 and PositionShortOpen=0 and BigTrendLong=1 then
if Grafico=1 then
DRAWARROWUP(barindex,xLow) Coloured(0,255,255)
endif
PositionLongOpen=1
StatoPosizione=2
ValPrezzoPosizioneLong=Close
ValPrezzoBreakEvenLong=ValPrezzoPosizioneLong+(ValSpread*(ValSpreadX/2))
ValTargetBreakEvenLong=ValPrezzoPosizioneLong+(ValSpread*ValSpreadX)
ValPrezzoStopLong = MIN(Low[1] , MIN(Low[2] , MIN(Low[3] , MIN(Low[4] , MIN(Low[5] , MIN(Low[6] , MIN(Low[7] , Low[8]) ) ) ) ) ))
ValPrezzoProfitLong=ValPrezzoPosizioneLong+(pipsize*ValProfit)
endif
if PositionLongOpen=1 and Close>ValTargetBreakEvenLong then
ValStatoBreakEvenLong=1
endif
if Volatilita[1]<1 and Volatilita[2]<1 and Volatilita[3]<1 and Volatilita[4]<1 and Volatilita[5]<1 then
//ForceCloseLong=1
endif
if PositionLongOpen=1 and XClose<MMEP and XOpen<MMEP and Candela=-1 and 1=0 or PositionLongOpen=1 and ValStatoBreakEvenLong=1 and Close<= ValPrezzoBreakEvenLong or PositionLongOpen=1 and Close<= ValPrezzoStopLong or PositionLongOpen=1 and Close> ValPrezzoProfitLong then
if ValStatoBreakEvenLong=1 then
if Grafico=0 then
DRAWARROWUP(barindex,StatoPosizione)Coloured(255,165,0)
endif
endif
if Close<= ValPrezzoStopLong then
if Grafico=0 then
DRAWARROWUP(barindex,StatoPosizione)Coloured(255,0,255)
endif
endif
if Grafico=0 then
if Close>ValPrezzoPosizioneLong then
DRAWARROWUP(barindex,StatoPosizione-0.3)Coloured(0,255,0)
else
DRAWARROWUP(barindex,StatoPosizione-0.3)Coloured(255,0,0)
endif
endif
ValStatoBreakEvenLong=0
ValPrezzoPosizioneLong=0
ValPrezzoBreakEvenLong=0
ValTargetBreakEvenLong=0
PositionLongOpen=0
StatoPosizione=1
if Grafico=1 then
DRAWARROWUP(barindex,XLow)Coloured(0,0,128)
endif
endif
endif
if 1=1 then
if Candela=-1 and PositionShortOpen=0 and PositionLongOpen=0 and Trend=-1 and ConteggioCandela<=4 and xOpen<=MMEP and Candela[ConteggioCandela+2]=-1 and Volatilita>ValPipVolatilita and Volatilita<ValPipVolatilita*6 or PositionLongOpen=0 and PositionShortOpen=0 and BigTrendShort=1 then
if Grafico=1 then
DRAWARROWDOWN(barindex,XHigh) Coloured(255,255,0)
endif
PositionShortOpen=1
StatoPosizione=-2
ValPrezzoPosizioneShort=Close
ValPrezzoBreakEvenShort=ValPrezzoPosizioneShort-(ValSpread*(ValSpreadX/2))
ValTargetBreakEvenShort=ValPrezzoPosizioneShort-(ValSpread*ValSpreadX)
ValPrezzoStopShort = MAX(High[1] , MAX(High[2] , MAX(High[3] , MAX(High[4] , MAX(High[5] , MAX(High[6] , MAX(High[7] , High[8]) ) ) ) ) ))
ValPrezzoProfitShort=ValPrezzoPosizioneShort-(pipsize*ValProfit)
endif
if PositionShortOpen=1 and Close<ValTargetBreakEvenShort then
ValStatoBreakEvenShort=1
endif
if PositionShortOpen=1 and XClose>MMEP and XOpen>MMEP and Candela=1 and 1=0 or PositionShortOpen=1 and ValStatoBreakEvenShort=1 and Close>= ValPrezzoBreakEvenShort or PositionShortOpen=1 and Close>= ValPrezzoStopShort or PositionShortOpen=1 and Close< ValPrezzoProfitShort then
if ValStatoBreakEvenShort=1 then
if Grafico=0 then
DRAWARROWDOWN(barindex,StatoPosizione)Coloured(255,165,0)
endif
endif
if Close>= ValPrezzoStopShort then
if Grafico=0 then
DRAWARROWDOWN(barindex,StatoPosizione)Coloured(255,0,255)
endif
endif
if Grafico=0 then
if Close<ValPrezzoPosizioneShort then
DRAWARROWDOWN(barindex,StatoPosizione+0.3)Coloured(0,255,0)
else
DRAWARROWDOWN(barindex,StatoPosizione+0.3)Coloured(255,0,0)
endif
endif
ValStatoBreakEvenShort=0
ValPrezzoPosizioneShort=0
ValPrezzoBreakEvenShort=0
ValTargetBreakEvenShort=0
PositionShortOpen=0
StatoPosizione=-1
if Grafico=1 then
DRAWARROWDOWN(barindex,XHigh)Coloured(0,128,0)
endif
endif
endif
if StatoPosizione=1 and Trend=1 then
endif
if Grafico=1 then
StatoPosizione= Undefined
endif
Return StatoPosizione as "StatoPosizione"
Strategia:
StatoPosizione= CALL MyIndicator2C[2,0.3,20,0,15]
// Condizioni per entrare su posizioni long
IF NOT LongOnMarket and NOT ShortOnMarket AND StatoPosizione=2 and 1=1 THEN
BUY 2.5 CONTRACTS AT MARKET
ENDIF
// Condizioni per uscire da posizioni long
If LongOnMarket AND StatoPosizione=1 THEN
SELL AT MARKET
ENDIF
// Condizioni per entrare su posizioni short
IF NOT ShortOnMarket and NOT LongOnMarket AND StatoPosizione=-2 and 1=1 THEN
SELLSHORT 2.5 CONTRACTS AT MARKET
ENDIF
// Condizioni per uscire da posizioni short
IF ShortOnMarket AND StatoPosizione=-1 THEN
EXITSHORT AT MARKET
ENDIF