average of given days

Hi Team,

is it possible to plot first 15 days average till Jun and first 15days of July for rest of the year on chart.
below is the formula i am looking for

value = (1stday open(first bar open in year) + last day close(last bar close in 15days) + high in 15 days + low in 15 days) /4

thanks.

Hi,

I believe you can achieve what you are after with the following script:

//Set Months
V1 = MONTHNUM() ;
//Find Change from December to Jan
V2 = V1 == 1 and V1[1] == 12;
//Find 15 Bars into Jan
V3 = TIMESINCESIGNAL(V2) == 15;
//Find Change from June to July
V4 = V1 == 7 and V1[1] == 6;
//Find 15 Bars into July
V5 = TIMESINCESIGNAL(V4) == 15;
//Set 15 Day Moving Average
V6 = MA(BARS=15, CALC=OHLC) ;
//Set Switch between the two Date Zones
V7 = SWITCH(V3,V5);
//Find 15SMA Value for each zome
RES1 = VALUEWHEN(V6,V3);
RES2 = VALUEWHEN(V6,V5);
//Show MA Value based on which Date Zone we are in
IF(V7 == 1,RES1,RES2)

Here is how it looks on a chart:

Ex1

The plot shows the average of the first 15 days of Jan and July each year.