Ok let's try this:
Something very simple.
Futures S&P E-mini contract. Data includes after hours trade starting at 5:00
PM on Sunday nights.
Work from within a 15 minute time frame, create a moving average of the daily
high, but do not include Sunday's or Holidays in the moving average. The code
below creates an accurate 4 day moving average of each day's high. However if
you read the output of this formula on any day but Friday you will see the
average includes Sunday as a day in the range. Since Sunday has no trade
occurring at 9:30 am through 4:00 pm, the code copies the high from the
previous Friday and uses that for Sunday. It does the same for holidays.
I need some help modifying this simple code so that it will not include
Sunday's, or any other day which does not have a regular market open and close
(holiday's).
Thanks for taking the time to look at this.
Pete :-)
//////////////////////////TESTING/////////////////////////////////
DlyHigh = HighestSince(TimeNum == 093000, High);
DlyHighest = ValueWhen(TimeNum == 160000, DlyHigh);
tstAvgH = MA(TimeFrameCompress(DlyHighest, inDaily),4);
printf("TstAvgH: " +TimeFrameExpand(tstAvgH, inDaily) +"\n");
//////////////////////////TESTING/////////////////////////////////
--- In [email protected], "Pete" <dryhe...@...> wrote:
>
> Perhaps I've answered my own question. Check this out.
> Set up another variable:
> TradeDays = Day() >= 1 and Day() <=5;
>
> Then I use this in the moving average??? But where?
>
> RngMinAvg = MA(ValueWhen(TradeDays,DlyRngMin) , 10);
>
> or
>
> RngMinAvg = MA(DlyRngMin , ValueWhen(TradeDays,10));
>
> I don't know, I've given up coding for today and haven't plugged these in to
> test them. I don't think it would work.
>
>
> --- In [email protected], "Pete" <dryheat3@> wrote:
> >
> > Ok, here's the problem, The program skews the calculation when you try to
> > take intra-day Futures data and compress to daily. the compression into
> > daily tweaks the whole thing up because of Sunday's and holidays. Yes, the
> > program is taking any trading which occurs on Sunday night and holidays and
> > including this in the range. I need to exclude non-trade days from the
> > moving average range and every attempt to do so has found me yelling and
> > screaming at the computer.
> >
> > So my question is this. How to calculate the daily moving average of say,
> > the lessor of (H-O) or (O-L), and use only the market trading hours,
> > excluding Sundays and Holidays. My attempt below was to use the TimeOpen
> > and TimeClose variables to restrict the O,H,L,C values I picked up along
> > the way. This indeed works but when I try to create a moving average on a
> > daily time frame it includes Sundays and Holidays in the 'Range' value of
> > the moving average argument even though the trades occur outside of trading
> > hours (Sunday) or do not trade the entire day (holidays).
> >
> > TimeOpen = 093000;
> >
> > TimeClose = 160000;
> > CurBarTime = TimeNum();
> > //Determine the value of the market open. Initial setting is for
> > //9:30 AM to match US Market Open. Adjust as need for your market
> > MrktOpen = ValueWhen(CurBarTime == TimeOpen , Open);
> > //Determine the highest high for each day's trading.
> > //Adjust time as needed for your market.
> > DlyHigh = HighestSince(CurBarTime == TimeOpen , High);
> > //Take a snapshot value of the day's high at the time of market
> > //close. Intial setting is 4:00 pm to match US Market Close.
> > //Adjust as needed for your market.
> > DlyHighest = ValueWhen(CurBarTime == TimeClose , DlyHigh);
> > printf("DlyH: " +DlyHighest +"\n");//////////////////////////////
> > //Do the same for the lowest value of the trading day.
> > //Adjust time as needed for your market.
> > DlyLow = LowestSince(CurBarTime == TimeOpen , Low);
> > DlyLowest = ValueWhen(CurBarTime == TimeClose , DlyLow);
> > printf("DlyL: " +DlyLowest +"\n");
> > //determine the market closing price
> > DlyClose = ValueWhen(CurBarTime == TimeClose , C);
> > printf("DlyC: "+DlyClose +"\n");//////////////////////////////
> > //Now calculate the min range value using Open, Low and High
> > //variables calculated above
> > RngMin = Min(DlyHighest - MrktOpen, MrktOpen - DlyLowest);
> > //Compres this to a daily time frame in order to capture
> > //the final value of the Range Min for each trading day
> > DlyRngMin = TimeFrameCompress(RngMin, inDaily, compressLast);
> > //Use the compressed variable to calculate a 10 day average\
> > RngMinAvg = MA(DlyRngMin , 10);
> >
>