This is a very simple EA, I wrote it in the simplest way possible so that anyone can understand and work on it.
I’m not very happy with the result, the problem is that ichimoku is strongly related to the trend, and I’m thinking about how to do a prt analysis of the trend on different TSs.
Anyway, I hope you also want to work on it.
//Stategy: Ichimoku
//Author: Piero Petrosillo
//version: 1
//Timeframe: 15 and 30 minutes - eurusd only
//Backtested from 01/11/2015 to 27/09/2017
//I'm sorry for my bad english.. :-)
//work in progress..
Defparam CUMULATEORDERS = False
once segnale = 0
once barcount = 0
once barcountClose = 0
once blocForzato = 0
possize = 2
//indicators---------------------------------------------------------------------------------
T = 9 //Tenkan-Sen Period (9)
I = 26 //Chikou-Span Period (26)
K = 52 //Kijun-Sen Period (52)
TS = (highest[T](high)+lowest[T](low))/2 //Tenkan-Sen
KS = (highest[I](high)+lowest[I](low))/2 //Kijun-Sen
CS = close[I] //Chikou-Span
SA = (TS[I]+KS[I])/2 //Senkou-Span A
SB = (highest[K](high[I])+lowest[K](low[I]))/2 //Senkou-Span B
myADX = ADX[20]
//end of indicators--------------------------------------------------------------------------
//Signals------------------------------------------------------------------------------------
if blocForzato = 1 then //wait after the order close
if Barindex>barcountClose+2 then
blocForzato = 0
endif
endif
//Chikou-Span position respect to the price
prezzoCSLow = low[26]
prezzoCSHigh= high[26]
spreadCS = pointsize*4
prezzoCSLow = prezzoCSLow - spreadCS
prezzoCSHigh=prezzoCSHigh + spreadCS
// Tenkan-Sen/Kijun-Sen crossing
num1 = TS[0]
num2 = KS[0]
num1p = TS[1]
num2p = KS[1]
if segnale = 0 then
incrocio = 0
if num1>num2 and num2p>=num1p then
incrocio = 1 //long
segnale = Barindex+2
endif
if num2>num1 and num1p>=num2p then
incrocio = -1//short
segnale = Barindex+2
endif
endif
if Barindex > segnale then
segnale = 0
endif
//Kumo parameters
kumoUP =0
kumoDOWN =0
kumoUPold =0
kumoDOWNold =0
spesKumoMin =pointsize*1//-------------- minimum kumo size ---------------------
speKum =0
mode =0
if SA[0]>SB[0] then
kumoUP=SA[0]
kumoDOWN=SB[0]
mode=3
kumoUPold=SA[1]
kumoDOWNold=SB[1]
else
kumoUP=SB[0]
kumoDOWN=SA[0]
mode=4
kumoUPold=SB[1]
kumoDOWNold=SA[1]
endif
spesKumo = kumoUPold-kumoDOWNold
if spesKumo>spesKumoMin then
speKum = 1//kumo size signal
endif
//mini ts trend
primo = TS[3]
ultimo = TS[0]
spread = pointsize*2
miniTr= ultimo-primo
miniTr= miniTr/spread
//mini price trend - not used now
primo = typicalprice[1]
ultimo = typicalprice[0]
spread = pointsize*1
miniTrPr= ultimo-primo
miniTrPr= miniTrPr/spread
//ChikouSpan out of span A e B - not used now
//senkChiko = 0
if SA[26]>SB[26] then
if CS[26]>SB[26] and CS[26]<SA[26] then
//senkChiko = 1
endif
else
if CS[26]>SA[26] and CS[26]<SB[26] then
//senkChiko = 1
endif
endif
//kumo side
segnale1 =0
segnale2 =0
segnale3 =0
segnale4 =0
kumoLatLong = 0
kumoLatShort = 0
if mode = 3 then // A up, B down
last = SA[0]
candele = SA[1]
if candele > (last+spesKumoMin) then//long
segnale1 = segnale1 + 1
endif
last = SB[0]
candele = SB[1]
if (candele+spesKumoMin) < last then//short
segnale2 = segnale2 + 1
endif
endif
if mode = 4 then// B up, A down
last = SB[0]
candele = SB[1]
if candele > (last+spesKumoMin) then//long
segnale3 = segnale3 + 1
endif
last = SA[0]
candele = SA[1]
if (candele+spesKumoMin) < last then//short
segnale4 = segnale4 + 1
endif
endif
if (segnale1+segnale3) > 0 then
kumoLatLong = 1//signal
endif
if (segnale2+segnale4) > 0 then
kumoLatShort = 1//signal
endif
//end of signals------------------------------------------------------------------------------------
//Orders--------------------------------------------------------------------------------------------
//Chikou-Span redefinition
CS = close[0]
blocco = 0//not used now
speKum2 = 0
//long position
//and spesKumo>spesKumomin and senkChiko = 0 and miniTr>4 and miniTrPr>0 and incrocio = 1
if myADX>15 and blocForzato=0 then
if speKum=1 then//spessore kumo buono
if countofposition = 0 and entrataAquisto = 0 and entrataVendita = 0 and incrocio=1 and TS[0]>KS[0] and CS[0]>prezzoCSHigh and miniTr>4 then
//TS position compared to kumo
if kumoLatLong = 0 and TS[0]>kumoUP and KS[0]>kumoUP then
speKum2 = 1
else
if kumoLatLong = 1 and TS[0]>kumoDOWNold and TS[0]<kumoUPold then //to optimize it
speKum2 = 1
endif
endif
if blocco = 0 and speKum2 = 1 then
Buy possize contracts at market
barcount = Barindex
segnale = 0
entrataAquisto = 1
EndIf
endif
//Short Position
//and senkChiko = 0 and miniTr<-4 and miniTrPr<0 and incrocio = -1
if countofposition = 0 and entrataVendita = 0 and entrataAquisto = 0 and incrocio=-1 and TS[0]<KS[0] and CS[0]<prezzoCSLow and miniTr<-4 then
if kumoLatShort = 0 and TS[0]<kumoDOWN and KS[0]<kumoDOWN then
speKum2 = 1
else
if kumoLatShort = 1 and TS[0]<kumoDOWNold and TS[0]>kumoUPold then //to optimize it
speKum2 = 1
endif
endif
if blocco = 0 and speKum2 = 1 then
Sellshort possize contracts at market
barcount = Barindex
segnale = 0
entrataVendita = 1
EndIf
endif
else//slim kumo -----------------------------------------
//and miniTr>4 and miniTrPr>0and incrocio = 1
if countofposition = 0 and entrataAquisto = 0 and entrataVendita = 0 and incrocio=1 and TS[0]>KS[0] and CS[0]>prezzoCSHigh and miniTr>4 and blocco = 0 then
Buy possize contracts at market
barcount = Barindex
segnale = 0
entrataAquisto = 1
endif
//and senkChiko = 0and miniTr<-4 and miniTrPr<0and incrocio = -1
if countofposition = 0 and entrataVendita = 0 and entrataAquisto = 0 and incrocio=-1 and TS[0]<KS[0] and CS[0]<prezzoCSLow and miniTr<-4 and blocco = 0 then
Sellshort possize contracts at market
barcount = Barindex
segnale = 0
entrataVendita = 1
endif
endif
endif
//GRAPH CS[0] coloured(0,255,0) AS "CS0"
//GRAPH prezzoCSLow coloured(0,0,255) AS "prezzoCSLow"
//GRAPH incrocio coloured(255,0,0) AS "incrocio"
//GRAPH miniTr coloured(255,0,0) AS "miniTr"
//GRAPH miniTrPr coloured(255,0,0) AS "miniTrPr"
//GRAPH kumoLatShort coloured(255,0,0) AS "klat"
//GRAPH TS[0] coloured(255,0,0) AS "ts0"
//GRAPH FastSMA[0] coloured(255,0,0) AS "SMA"
//GRAPH KS[0] coloured(255,0,0) AS "ks0"
//GRAPH miniTrSma coloured(255,0,0) AS "miniTrSma"
//GRAPH speKum coloured(255,0,0) AS "speKum"
//End of orders-------------------------------------------------------------------------------------
//Exit Conditions-----------------------------------------------------------------------------------
bars = 3
if entrataAquisto = 1 and TS[0]<KS[0] then
Sell at market
segnale = 0
entrataAquisto = 0
blocForzato=1
barcountClose=Barindex
endif
if entrataAquisto = 1 and blocForzato = 1 then
Sell at market
segnale = 0
entrataAquisto = 0
blocForzato=1
barcountClose=Barindex
endif
if entrataAquisto = 1 and Barindex>barcount+bars and close[0]<close[bars] then
Sell at market
segnale = 0
entrataAquisto = 0
blocForzato=1
barcountClose=Barindex
endif
if entrataVendita = 1 and TS[0]>KS[0] then
exitshort at market
segnale = 0
entrataVendita = 0
blocForzato=1
barcountClose=Barindex
endif
if entrataVendita = 1 and blocForzato = 1 then
exitshort at market
segnale = 0
entrataVendita = 0
blocForzato=1
barcountClose=Barindex
endif
if entrataVendita = 1 and Barindex>barcount+bars and close[0]<close[bars] then
exitshort at market
segnale = 0
entrataVendita = 0
blocForzato=1
barcountClose=Barindex
endif
//Exit of exit conditions---------------------------------------------------------------------------
How can we help you? Do you need more assistance about:
how to do a prt analysis of the trend on different TSs
❓
Hi,
if I want compare the current graph TF ichimoku with the ichimoku values on a higher TF, for example at 1 hour respect the 15 minutes of the graph, it is possible with prt?
Thank’s
Piero
Not right out of the box (for now… still waiting for this crucial update 😀 ), but since Ichimoku is only built upon highest high and lowest low of different periods, we could try to get accurate values of higher timeframe, just by simulating them with periods multiplication. I think it should do the trick for Ichimoku.
Well done @pieroim, you are making excellent progress!
I can see that you are a seasoned coder looking at your programming style.
I will look a bit closer at your strategy and see if I can make any improvements.
I have a few tricks up my sleeve that I can try.
Ok.
To speed up writing the code, I used “pointize” as a constant in various functions. This works fine with eurusd at 15 and 30 minutes, otherwise it is worth to be calculated.
Remember, this is only the first version…
Nicolas, is there a way to close an order to a specific price? Example: to a 1.17113 in eurusd
Of course, you can use contrarian pending orders to close orders at specific price. If you want to close a BUY position above its current price:
SELL at myprice LIMIT
or to close the BUY position below its current price:
SELL at myprice STOP
Now I’m working on the code for the pseudo higher timeframe..
if Barindex>barcountClose+15 then //ogni 16 barre
barcountClose = Barindex
high4h=high[0]
low4h=low[0]
for x = 0 to 15 do
if high[x] > high1h then
high4h=high[x]
endif
if low[x] < low1h then
low4h=low[x]
endif
next
piuDM = MAX(high1h-high1h[1], 0)
menoDM = MAX(low1h[1]-low1h, 0)
IF piuDM > menoDM THEN
menoDM = 0
ENDIF
IF piuDM < menoDM THEN
piuDM = 0
ENDIF
IF piuDM = menoDM THEN
piuDM = 0
menoDM = 0
ENDIF
REM Calcolo degli indicatori direzionali
piuDI = WILDERAVERAGE[14](piuDM)
menoDI = WILDERAVERAGE[14](menoDM)
REM Calcolo del ADX
DX = ABS(piuDI - menoDI) / (piuDI + menoDI) * 100
myADX1h = WILDERAVERAGE[14](DX)
endif
with the above code i would like to calculate an 4h ADX in a 15m chart .. but it does not go .. the chart values, no matter if fragmented, are far from those of a 4 hour ADX ..
errata/corrige..
if Barindex>barcountClose+15 then //ogni 16 barre
barcountClose = Barindex
high4h=high[0]
low4h=low[0]
for x = 0 to 15 do
if high[x] > high4h then
high4h=high[x]
endif
if low[x] < low4h then
low4h=low[x]
endif
next
piuDM = MAX(high4h-high4h[16], 0)
menoDM = MAX(low4h[16]-low4h, 0)
IF piuDM > menoDM THEN
menoDM = 0
ENDIF
IF piuDM < menoDM THEN
piuDM = 0
ENDIF
IF piuDM = menoDM THEN
piuDM = 0
menoDM = 0
ENDIF
REM Calcolo degli indicatori direzionali
piuDI = WILDERAVERAGE[223](piuDM)
menoDI = WILDERAVERAGE[223](menoDM)
REM Calcolo del ADX
DX = ABS(piuDI - menoDI) / (piuDI + menoDI) * 100
myADX4h = WILDERAVERAGE[223](DX)
endif
now vorks a little better..