draw n day moving average on intraday charts?

 
Can someone help me write a script which calculate n day simple moving average ( shifted to the right by one day so that no calculation is needed for any newly incoming ticks ) and draw it on intraday charts? Thanks.
 
Can someone help me write a script which calculate n day simple moving average ( shifted to the right by one day so that no calculation is needed for any newly incoming ticks ) and draw it on intraday charts? Thanks.


here ya go...

it is the indicator with same parameters as standard moving average, with addition of the "timeframe" parameter which should be set to timeframe (in minutes) you wish to calculate average for
so, in your case, you should set timeframe to 1440 and all other parameters to your likings

it makes no sense to try to display average from shorter timeframe in longer one (for instance 1H average on a daily chart)

hope this helps
swacc

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red


extern int timeframe=1440;  //minutes
extern int period=14;
extern int shift=0;
extern int method=MODE_SMA;
extern int applyToPrice=PRICE_CLOSE;

double movingAverage[];


int init()  {
	SetIndexStyle(0,DRAW_LINE);
	SetIndexShift(0,0);
	SetIndexDrawBegin(0,0);
	SetIndexEmptyValue(0,0.0);
	SetIndexLabel(0,"Moving Average");
	SetIndexBuffer(0,movingAverage);
	
	IndicatorShortName("Moving Average " + timeframe + " minutes, shown on " + (Time[0]-Time[1])/60 + " min chart");
	
return(0);
}



int deinit()   {
	return(0);
}




int start() {
	int limit=0;
	int i=0;	
	int counted_bars=IndicatorCounted();
	static int longerTimeframeBarShift=0;
	
	
	if(counted_bars<0) {
		return(-1);
	}
	if(counted_bars>0){
		counted_bars--;
	}

	limit=Bars-counted_bars;
	for(i=0; i<limit; i++) {
		if(Time[i]%60 == 0 && (Time[i]/60)%timeframe == 0) {
			longerTimeframeBarShift++;
		}
		movingAverage[i]=iMA(NULL, timeframe, period, shift, method, PRICE_CLOSE, longerTimeframeBarShift);
	}
return(0);
}