Optuma Forums › Optuma Scripting › average of given days › Reply To: average of given days
December 29, 2020 at 8:06 am
#61858
- Topics: 5
- Replies: 625
- Posts: 630
Hi,
I believe you can achieve what you are after with the following script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
//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:
The plot shows the average of the first 15 days of Jan and July each year.