Seasonality Analysis

Category: Indicators By: Vonasi Created: January 8, 2018, 1:36 PM
January 8, 2018, 1:36 PM
Indicators
7 Comments

Being aware of seasonality is an important part of any traders toolbox so I wrote this indicator to analyse any market month by month from any available date in the past to the present month.

Apply on any market but only on monthly charts.

It is always a good idea to compare shorter look back periods with a longer look back period to help gauge the reliability of seasonality results. You can enter the start year and start month required so you can quickly compare market seasonality over different look back periods.

The results you are interested in are the last ones under the current months candle. They are as follows:

Return: The average pips return in that month over the period tested. If you had opened a long bet at the beginning of that month and closed it at the end of that month every year then this is how much you would have gained or lost on average each month.

Rank%: The best performing monthly average return and the worst performing monthly average return are ranked at 100% and -100%. All months in between are given a ranking% relative to these. This is useful if you want to alter position sizing in a strategy month by month based on seasonality. You might want to place position size of 100% of your maximum bet size in months rated at 100% and only 33% in months rated 33% for example.

Reliability%: The number of up months and number of down months are totalled up and a reliability percentage calculated. For example if you test over 10 years and have ten tests of January and January’s results favour long positions then if 7 of those months see a gain and 3 a loss then the reliability is 70%. You may wish to only go long in months with a Reliability% of over 70% for example.  This reliability% helps you decide the probability of future results matching historical results.

I suggest downloading the .ITF file and importing it to get full functionality rather than cutting and pasting the code.

//Seasonality Analysis
//Created by Vonasi

//StartMonth = 1
//StartYear = 1997

IF OpenYear = StartYear and OpenMonth = StartMonth THEN
Flag = 1
ENDIF

IF Flag = 1 THEN
IF OpenMonth = 1 THEN
JanTotal = JanTotal + (close - open)
JanCount = JanCount + 1
IF close > open THEN
JanUp = JanUp + 1
ENDIF
ENDIF

IF OpenMonth = 2 THEN
FebTotal = FebTotal + (close - open)
FebCount = FebCount + 1
IF close > open THEN
FebUp = FebUp + 1
ENDIF
ENDIF

IF OpenMonth = 3 THEN
MarTotal = MarTotal + (close - open)
MarCount = MarCount + 1
IF close > open THEN
MarUp = MarUp + 1
ENDIF
ENDIF

IF OpenMonth = 4 THEN
AprTotal = AprTotal + (close - open)
AprCount = AprCount + 1
IF close > open THEN
AprUp = AprUp + 1
ENDIF
ENDIF

IF OpenMonth = 5 THEN
MayTotal = MayTotal + (close - open)
MayCount = MayCount + 1
IF close > open THEN
MayUp = MayUp + 1
ENDIF
ENDIF

IF OpenMonth = 6 THEN
JunTotal = JunTotal + (close - open)
JunCount = JunCount + 1
IF close > open THEN
JunUp = JunUp + 1
ENDIF
ENDIF

IF OpenMonth = 7 THEN
JulTotal = JulTotal + (close - open)
JulCount = JulCount + 1
IF close > open THEN
JulUp = JulUp + 1
ENDIF
ENDIF

IF OpenMonth = 8 THEN
AugTotal = AugTotal + (close - open)
AugCount = AugCount + 1
IF close > open THEN
AugUp = AugUp + 1
ENDIF
ENDIF

IF OpenMonth = 9 THEN
SepTotal = SepTotal + (close - open)
SepCount = SepCount + 1
IF close > open THEN
SepUp = SepUp + 1
ENDIF
ENDIF

IF OpenMonth = 10 THEN
OctTotal = OctTotal + (close - open)
OctCount = OctCount + 1
IF close > open THEN
OctUp = OctUp + 1
ENDIF
ENDIF

IF OpenMonth = 11 THEN
NovTotal = NovTotal + (close - open)
NovCount = NovCount + 1
IF close > open THEN
NovUp = NovUp + 1
ENDIF
ENDIF

IF OpenMonth = 12 THEN
DecTotal = DecTotal + (close - open)
DecCount = DecCount + 1
IF close > open THEN
DecUp = DecUp + 1
ENDIF
ENDIF
ENDIF

Jan = Round(JanTotal/JanCount)
Feb = Round(FebTotal/FebCount)
Mar = Round(MarTotal/MarCount)
Apr = Round(AprTotal/AprCount)
May = Round(MayTotal/MayCount)
Jun = Round(JunTotal/JunCount)
Jul = Round(JulTotal/JulCount)
Aug = Round(AugTotal/AugCount)
Sep = Round(SepTotal/SepCount)
Oct = Round(OctTotal/OctCount)
Nov = Round(NovTotal/NovCount)
Dec = Round(DecTotal/DecCount)

IF Jan > 0 THEN
JanR = 0
JanG = 128
JanRel = Round((JanUp/JanCount)*100)
ELSE
JanR = 128
JanG = 0
JanRel = Round(((JanCount - JanUp)/JanCount)*100)
ENDIF

IF Feb > 0 THEN
FebR = 0
FebG = 128
FebRel = Round((FebUp/FebCount)*100)
ELSE
FebR = 128
FebG = 0
FebRel = Round(((FebCount - FebUp)/FebCount)*100)
ENDIF

IF Mar > 0 THEN
MarR = 0
MarG = 128
MarRel = Round((MarUp/MarCount)*100)
ELSE
MarR = 128
MarG = 0
MarRel = Round(((MarCount - MarUp)/MarCount)*100)
ENDIF

IF Apr > 0 THEN
AprR = 0
AprG = 128
AprRel = Round((AprUp/AprCount)*100)
ELSE
AprR = 128
AprG = 0
AprRel = Round(((AprCount - AprUp)/AprCount)*100)
ENDIF

IF May > 0 THEN
MayR = 0
MayG = 128
MayRel = Round((MayUp/MayCount)*100)
ELSE
MayR = 128
MayG = 0
MayRel = Round(((MayCount - MayUp)/MayCount)*100)
ENDIF

IF Jun > 0 THEN
JunR = 0
JunG = 128
JunRel = Round((JunUp/JunCount)*100)
ELSE
JunR = 128
JunG = 0
JunRel = Round(((JunCount - JunUp)/JunCount)*100)
ENDIF

IF Jul > 0 THEN
JulR = 0
JulG = 128
JulRel = Round((JulUp/JulCount)*100)
ELSE
JulR = 128
JulG = 0
JulRel = Round(((JulCount - JulUp)/JulCount)*100)
ENDIF

IF Aug > 0 THEN
AugR = 0
AugG = 128
AugRel = Round((AugUp/AugCount)*100)
ELSE
AugR = 128
AugG = 0
AugRel = Round(((AugCount - AugUp)/AugCount)*100)
ENDIF

IF Sep > 0 THEN
SepR = 0
SepG = 128
SepRel = Round((SepUp/SepCount)*100)
ELSE
SepR = 128
SepG = 0
SepRel = Round(((SepCount - SepUp)/SepCount)*100)
ENDIF

IF Oct > 0 THEN
OctR = 0
OctG = 128
OctRel = Round((OctUp/OctCount)*100)
ELSE
OctR = 128
OctG = 0
OctRel = Round(((OctCount - OctUp)/OctCount)*100)
ENDIF

IF Nov > 0 THEN
NovR = 0
NovG = 128
NovRel = Round((NovUp/NovCount)*100)
ELSE
NovR = 128
NovG = 0
NovRel = Round(((NovCount - NovUp)/NovCount)*100)
ENDIF

IF Dec > 0 THEN
DecR = 0
DecG = 128
DecRel = Round((DecUp/DecCount)*100)
ELSE
DecR = 128
DecG = 0
DecRel = Round(((DecCount - DecUp)/DecCount)*100)
ENDIF

Avg = Round((Jan + Feb + Mar + Apr + May + Jun + Jul + Aug + Sep + Oct + Nov + Dec)/12)
AvgCount = (JanCount + FebCount + MarCount + AprCount + MayCount + JunCount + JulCount + AugCount + SepCount + OctCount + NovCount + DecCount)
AvgUp = (JanUp + FebUp + MarUp + AprUp + MayUp + JunUp + JulUp + AugUp + SepUp + OctUp + NovUp + DecUp)

IF Avg > 0 THEN
AvgR = 0
AvgG = 128
AvgRel = Round((AvgUp/AvgCount)*100)
ELSE
AvgR = 128
AvgG = 0
AvgRel = Round(((AvgCount - AvgUp)/AvgCount)*100)
ENDIF

IF StartMonth = 1 THEN
DrawText("            From Jan #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 2 THEN
DrawText("            From Feb #StartYear#" ,barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 3 THEN
DrawText("            From Mar #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 4 THEN
DrawText("            From Apr #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 5 THEN
DrawText("            From May #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 6 THEN
DrawText("            From Jun #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 7 THEN
DrawText("            From Jul #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 8 THEN
DrawText("           From Aug #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 9 THEN
DrawText("            From Sep #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 10 THEN
DrawText("            From Oct #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 11 THEN
DrawText("            From Nov #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

IF StartMonth = 12 THEN
DrawText("            From Dec #StartYear#",barindex,15.5,SansSerif,Standard,10)coloured(0,0,0)
ENDIF

Bottom = Min(Dec,Min(Nov,Min(Oct,Min(Sep,Min(Aug,Min(Jul,Min(Jun,Min(May,Min(Apr,Min(Mar,MIN(Feb,Jan)))))))))))
Top = Max(Dec,Max(Nov,Max(Oct,Max(Sep,Max(Aug,Max(Jul,Max(Jun,Max(May,Max(Apr,Max(Mar,Max(Feb,Jan)))))))))))

IF Jan > 0 THEN
JanPerc = Round((Jan/Top)*100)
ELSE
JanPerc = 0 - Round((ABS(Jan)/ABS(Bottom))*100)
ENDIF

IF Feb > 0 THEN
FebPerc = Round((Feb/Top)*100)
ELSE
FebPerc = 0 - Round((ABS(Feb)/ABS(Bottom))*100)
ENDIF

IF Mar > 0 THEN
MarPerc = Round((Mar/Top)*100)
ELSE
MarPerc = 0 - Round((ABS(Mar)/ABS(Bottom))*100)
ENDIF

IF Apr > 0 THEN
AprPerc = Round((Apr/Top)*100)
ELSE
AprPerc = 0 - Round((ABS(Apr)/ABS(Bottom))*100)
ENDIF

IF May > 0 THEN
MayPerc = Round((May/Top)*100)
ELSE
MayPerc = 0 - Round((ABS(May)/ABS(Bottom))*100)
ENDIF

IF Jun > 0 THEN
JunPerc = Round((Jun/Top)*100)
ELSE
JunPerc = 0 - Round((ABS(Jun)/ABS(Bottom))*100)
ENDIF

IF Jul > 0 THEN
JulPerc = Round((Jul/Top)*100)
ELSE
JulPerc = 0 - Round((ABS(Jul)/ABS(Bottom))*100)
ENDIF

IF Aug > 0 THEN
AugPerc = Round((Aug/Top)*100)
ELSE
AugPerc = 0 - Round((ABS(Aug)/ABS(Bottom))*100)
ENDIF

IF Sep > 0 THEN
SepPerc = Round((Sep/Top)*100)
ELSE
SepPerc = 0 - Round((ABS(Sep)/ABS(Bottom))*100)
ENDIF

IF Oct > 0 THEN
OctPerc = Round((Oct/Top)*100)
ELSE
OctPerc = 0 - Round((ABS(Oct)/ABS(Bottom))*100)
ENDIF

IF Nov > 0 THEN
NovPerc = Round((Nov/Top)*100)
ELSE
NovPerc = 0 - Round((ABS(Nov)/ABS(Bottom))*100)
ENDIF

IF Dec > 0 THEN
DecPerc = Round((Dec/Top)*100)
ELSE
DecPerc = 0 - Round((ABS(Dec)/ABS(Bottom))*100)
ENDIF

IF Avg > 0 THEN
AvgPerc = Round((Avg/Top)*100)
ELSE
AvgPerc = 0 - Round((ABS(Avg)/ABS(Bottom))*100)
ENDIF

DrawText("Jan     #Jan#       #JanPerc#        #JanRel#",barindex,12,SansSerif,Standard,10)coloured(JanR,JanG,0)
DrawText("Feb     #Feb#       #FebPerc#        #FebRel#",barindex,11,SansSerif,Standard,10)coloured(FebR,FebG,0)
DrawText("Mar     #Mar#       #MarPerc#        #MarRel#",barindex,10,SansSerif,Standard,10)coloured(MarR,MarG,0)
DrawText("Apr     #Apr#       #AprPerc#        #AprRel#",barindex,9,SansSerif,Standard,10)coloured(AprR,AprG,0)
DrawText("May     #May#       #MayPerc#        #MayRel#",barindex,8,SansSerif,Standard,10)coloured(MayR,MayG,0)
DrawText("Jun     #Jun#       #JunPerc#        #JunRel#",barindex,7,SansSerif,Standard,10)coloured(JunR,JunG,0)
DrawText("Jul     #Jul#       #JulPerc#        #JulRel#",barindex,6,SansSerif,Standard,10)coloured(JulR,JulG,0)
DrawText("Aug     #Aug#       #AugPerc#        #AugRel#",barindex,5,SansSerif,Standard,10)coloured(AugR,AugG,0)
DrawText("Sep     #Sep#       #SepPerc#        #SepRel#",barindex,4,SansSerif,Standard,10)coloured(SepR,SepG,0)
DrawText("Oct     #Oct#       #OctPerc#        #OctRel#",barindex,3,SansSerif,Standard,10)coloured(OctR,OctG,0)
DrawText("Nov     #Nov#       #NovPerc#        #NovRel#",barindex,2,SansSerif,Standard,10)coloured(NovR,NovG,0)
DrawText("Dec     #Dec#       #DecPerc#        #DecRel#",barindex,1,SansSerif,Standard,10)coloured(DecR,DecG,0)
DrawText("Avg     #Avg#       #AvgPerc#      #AvgRel#",barindex,-1,SansSerif,Standard,10)coloured(AvgR,AvgG,0)

DrawText("                 Return  Rank%  Reliability%",barindex,14,SansSerif,Standard,10)coloured(0,0,0)

Hi = 16.5
Mid = 13
Mid2 = 0
Lo = -2
 
Return Hi, Lo, Mid, Mid2

 

Download
Filename: Seasonality-Analysis-1-1.itf
Downloads: 168
Vonasi Master
V-oyaging ON A S-mall I-ncome
Author’s Profile

Comments

Logo Logo
Loading...