I have created this comprehensive strategy based on ichimoku. I optimized this on Germany cash 1 euro a CFD market TF 3H. The parameters to be optimized are both SL and TP but also the same ichimoku parameters based on the TF and the market. The goal is to improve it again and to make it perform well on other tools like forex. Thnaks.
//-------------------------------------------------------------------------
// Codice principale : ichi
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Codice principale : Ichimonu_trading
//-------------------------------------------------------------------------
//DEFPARAM FlatBefore = 080000
//DEFPARAM FlatAfter = 220000
DEFPARAM CumulateOrders = false
//parametri calcolo ichimoku...fibonacci (8, 21, 55) e gli altri sono noti.
I= 6//7//9//8//8
P = 26//28//26//21//21
U = 146//119//52//55//89
//signal=0
DojiSize = 0.08//0.13
data=(abs(open - close) <= (high - low) * DojiSize)
kk= data
MM = ExponentialAverage[8](close)
MM2 = ExponentialAverage[89](close)
//TTlong = close [1] crosses over MM OR close > MM AND MM[3]<MM[2] AND MM[2]<MM[1] AND MM[1] < MM
//TTShort= close[1] crosses under MM OR close < MM AND MM[3]>MM[2] AND MM[2]>MM[1] AND MM[1] > MM
TTlong= MM - MM[2] >= 1.4 AND CLOSE >MM AND CLOSE > MM2
TTshort= MM[2] - MM >= 1.35 AND CLOSE < MM AND CLOSE < MM2
//controllo direzione chikou per long
KK1= chikou > chikou[1]
//diffe= ((chikou -chikou[1])/chikou)*100
//kk1= diffe >=a
//controllo direzione chikou per short
kk2= chikou < chikou[1]
//diffe1= ((chikou[1] -chikou)/chikou[1])*100
//kk2= diffe1 >= b
//Kijunsen piatta
KK3= Kijunsen = Kijunsen[1] and Kijunsen[1] = Kijunsen[2]
//Ichimoku
Tenkansen = (highest[I](high)+lowest[I](low))/2
Kijunsen = (highest[P](high)+lowest[P](low))/2
SpanA = (tenkansen[P]+kijunsen[P])/2
SpanB = (highest[U](high[P])+lowest[U](low[P]))/2
//FutureSpanA = (tenkansen+kijunsen)/2
//FutureSpanB = (highest[52](high)+lowest[52](low))/2
Chikou = close
// le condizioni sono volutamente ripetute per una maggiore visisibilità in fase di ottimizzazione. Una volta ottimizzata occorrerà creare delle condizioni uniche e non ridondanti.
// SpanA > SpanB e brekout kumo LONG
C1= SpanA > SpanB
c2= close[1] crosses over SpanA
C3= close > SpanA
C4= close > Tenkansen
c5= close > Kijunsen
c6= chikou > Tenkansen[P]
c7= chikou > Kijunsen [P]
C8= chikou > Close[P]
c9= chikou > SpanA[P]
c10= chikou > SpanB[P]
//BKUMOLONG= c1 and c2 and c3 and c4 and c5 and c6 and c7 and c8 and c9 and c10
BKUMOLONG= c1 and c2 and c3 and c4 and c5 and c8 and c9 and c10 and c6 and c7 and not kk and kk1 and not kk3 and TTlong
// SpanA < SpanB e brekout kumo LONG
c11=SpanA < SpanB
c12= close[1] crosses over SpanB
C13= close > SpanB
C14= close > Tenkansen
c15= close > Kijunsen
c16= chikou > Tenkansen[P]
c17= chikou > Kijunsen [P]
C18= chikou > Close[P]
c19= chikou > SpanB[P]
c191= chikou > SpanB[P]
//BKUMOLONG1= c11 and c12 and c13 and c14 and c15 and c16 and c17 and c18 and c19 and c191
BKUMOLONG1= c11 and c12 and c13 and c14 and c15 and c18 and c19 and c191 and c16 and c17 and not kk and kk1 and not kk3 and TTlong
//SpanA > SpanB e croce d'oro sopra kumo LONG
C20= SpanA > SpanB
C21= Tenkansen crosses over Kijunsen
C22= chikou > Close[P]
C23= close > Tenkansen
c24= close > kijunsen
c25= chikou > Tenkansen[P]
c26= chikou > Kijunsen [P]
C27= close > SpanA
//OROLONG = c20 and c21 and c22 and c23 and c24 and c25 and c26 and c27
OROLONG = c20 and c21 and c22 and c23 and c24 and c27 and c25 and c26 and not kk and kk1 and not kk3 and TTlong
//SpanA < SpanB e croce d'oro sotto kumo LONG
c28=SpanA < SpanB
C29= Tenkansen crosses over Kijunsen
C30= chikou > Close[P]
C31= close > Tenkansen
c34= close > kijunsen
c35= chikou > Tenkansen[P]
c36= chikou > Kijunsen [P]
//c37= close < SpanA
//OROLONG1= c28 and c29 and c30 and c31 and c34 and c35 and c36 and c37
OROLONG1= c28 and c29 and c30 and c31 and c34 and c35 and c36 and not kk and kk1 and not kk3 and TTlong
// SpanA > SpanB Segnale tre linee sopra kumo LONG
C38= SpanA > SpanB
c39= Tenkansen > kijunsen
c40= kijunsen > SpanA
c41= Tenkansen > SpanA
C42= close > SpanA
C43= close > Tenkansen
c44= close > kijunsen
C420= close[1] > SpanA
C430= close[1] > Tenkansen
c440= close[1] > kijunsen
c45= chikou > close[P]
c46= chikou > SpanA[P]
c47= chikou > SpanB[P]
TRELINEELONG= c38 and c39 and c40 and c41 and c42 and c43 and c44 and c45 and c46 and c47 and c420 and c430 and c440 and not KK and kk1 and not kk3 and TTlong
// SpanA < SpanB e brekout kumo SHORT
C48= SpanA < SpanB
c49= close[1] crosses under SpanA
C50= close < SpanA
C51= close < Tenkansen
c52= close < Kijunsen
c53= chikou < Tenkansen[P]
c54= chikou < Kijunsen [P]
C55= chikou < Close[P]
c56= chikou < SpanA[P]
c57= chikou < SpanB[P]
BKUMOSHORT= c48 and c49 and c50 and c51 and c52 and c53 and c54 and c55 and c56 and c57 and not kk and kk2 and not kk3 and TTshort
// SpanA > SpanB e brekout kumo SHORT
C58= SpanA > SpanB
c59= close[1] crosses under SpanB
C60= close < SpanB
C61= close < Tenkansen
c62= close < Kijunsen
c63= chikou < Tenkansen[P]
c64= chikou < Kijunsen [P]
C65= chikou < Close[P]
c66= chikou < SpanA[P]
c67= chikou < SpanB[P]
//BKUMOSHORT1= c58 and c59 and c60 and c61 and c62 and c63 and c64 and c65 and c66 and c67
BKUMOSHORT1= c58 and c59 and c60 and c61 and c62 and c65 and c66 and c67 and c63 and c64 and not kk and kk2 and not kk3 and TTshort
//SpanA > SpanB e croce morte sopra kumo SHORT
C68= SpanA > SpanB
C69= Tenkansen crosses under Kijunsen
C70= chikou < Close[P]
C71= close < Tenkansen
c72= close < kijunsen
c73= chikou < Tenkansen[P]
c74= chikou < Kijunsen [P]
//C75= close > SpanA
//MORTESHORT= c68 and c69 and c70 and c71 and c72 and c73 and c74 and c75
MORTESHORT= c68 and c69 and c70 and c71 and c72 and c73 and c74 and not kk and kk2 and not kk3 and TTshort
//SpanA < SpanB e croce MORTE sotto kumo SHORT
C76= SpanA < SpanB
c77= Tenkansen crosses under Kijunsen
c78= chikou< close[P]
C79= close < Tenkansen
c80= close < kijunsen
c81= chikou < Tenkansen[P]
c82= chikou < Kijunsen [P]
c83=close < SpanA
//MORTESHORT1= c76 and c77 and c78 and c79 and c80 and c81 and c82 and c83
MORTESHORT1= c76 and c77 and c78 and c79 and c80 and c83 and c81 and c82 and not kk and kk2 and not kk3 and TTshort
// SpanA < SpanB Segnale tre linee sottokumo SHORT
c84=SpanA < SpanB
c85= Tenkansen < kijunsen
c86= kijunsen < SpanA
c87= Tenkansen < SpanA
C88= close < SpanA
c880= close[1]<SpanA
c89= close < SpanB
C90= chikou < Close[P]
C91= close < Tenkansen
c92= close< kijunsen
C910= close[1] < Tenkansen
c920= close[1]< kijunsen
c93= chikou < SpanA[P]
c94= chikou < SpanB[P]
TREELINEESHORT= c84 and c85 and c86 and c87 and c88 and c89 and c90 and c91 and c92 and c93 and c94 and c880 and c910 and c920 and not KK and kk2 and not kk3 and TTshort
IF not onmarket and BKUMOLONG then
buy 1 shares at market
//signal=1
endif
IF not onmarket and BKUMOLONG1 then
buy 1 shares at market
//signal=2
endif
IF not onmarket and OROLONG then
buy 1 shares at market
//signal=3
endif
IF not onmarket and OROLONG1 then
buy 1 shares at market
//signal=4
endif
IF not onmarket and TRELINEELONG then
buy 1 shares at market
//signal=5
endif
IF not onmarket and BKUMOSHORT then
sellshort 1 shares at market
//signal=-1
endif
IF not onmarket and BKUMOSHORT1 then
sellshort 1 shares at market
//signal=-2
endif
IF not onmarket and MORTESHORT then
sellshort 1 shares at market
//signal=-3
endif
IF not onmarket and MORTESHORT1 then
sellshort 1 shares at market
//signal=-4
endif
IF not onmarket and TREELINEESHORT then
sellshort 1 shares at market
//signal=-5
endif
if longonmarket and close crosses under Kijunsen or close crosses under SpanA or close crosses under spanB or close crosses over Kijunsen or close crosses over SpanA or close crosses over spanB then
sell at market
//signal=0
endif
if shortonmarket and close crosses under Kijunsen or close crosses under SpanA or close crosses under spanB or close crosses over Kijunsen or close crosses over SpanA or close crosses over spanB then
exitshort at market
//signal=0
endif
//trailing stop
trailingstop = 14
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//SET STOP ploss b//20
//SET TARGET pPROFIT c//54
//GRAPH signal coloured(255,0,0) as "segnale per capire"
SET STOP ploss 105
SET TARGET pPROFIT 135
//SET STOP PTRAILING a
//TRAILING STOP
Thank you for your post proposal into the library. any ideas or codes proposed will do anything that will move the community forward 🙂 Moved it here to discuss about:
1/ Overfit is the first thing that come to mind, did you try at least to validate your optimized variables on an Out Of Sample (OOS) period? To prevent over fitting, develop your idea on a 70% time period and validate it on the last 30% period.
2/ The conditions to exit position (long or short) are exactly the same between lines 273 to 281?
Hi,
I have do the Walk Forward analysis and it seems ok and confirm the parameters optimized. I add some screenshoot. Thanks
Nice to see that WFA validate the optimisation. How much variables optimized here?
The only variables that influence the results are those below. The other parameters constitute valid filters for each instrument and TF.
I= 6
P = 26
U = 146
Even the SL and TP levels are valid for any period. I also did, with SL and TP, a separate optimization and the Walk Forward Analysis provides positive results.
I concentrated to find reliability only on Germany cash 1 euro. If anyone in the community wants to help me to make it even more efficient on forex I would be grateful.
Thanks
Hello,
I would have liked to test this strategy.
Unfortunately, he doesn’t want to show me anything.
Not an error message either.
Would it be possible for Nicolas to test it?
Thank you in advance!
Kind regards,
Tom
I tried it also both on SB and CFD and not one single trade over 100k bars on DAX 3H TF … weird??
I have not tested it, but the difference between the MA should be converted to pointsize, change the lines:
TTlong= MM - MM[2] >= 1.4*pointsize AND CLOSE >MM AND CLOSE > MM2
TTshort= MM[2] - MM >= 1.35*pointsize AND CLOSE < MM AND CLOSE < MM2
Thank You Nicolas, but it still doesn’t execute any trades.
Has to be something simple?
I have tried everything I can think of. I’ll wait until @volpiemanuele comes back on and hopefully sorts it?
GaelParticipant
Average
I can ask you for the file in itf, please
There you go, I changed TTlong and TTshort as suggested by Nicolas, then replaced TenkanSen and KijunSen by TenkanSenX and KijunSenX not to be confused with new v11 keywords.
As reported by GraHal no trades were opened. There must be some error in the logic that volpiemanuele could fix (he’s likely to have already fixed it).