NexusFi: Find Your Edge


Home Menu

 





Calculating a Previous 2 Days average in a 5-mins time frame


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,858 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
Search this Thread

Calculating a Previous 2 Days average in a 5-mins time frame

  #1 (permalink)
hong615
hong kong
 
Posts: 4 since Mar 2014
Thanks Given: 0
Thanks Received: 0

Hi, I am new to coding in Multicharts. Seems like it should be an easy script, I am trying to find a hints on what's the most efficient way of coding this. So here's is what I am trying to do.

In a 5-mins chart, I would to calculate the average of the previous 2 days price. So, say today is N, I want the 5-mins average of N-1 and N-2.

Can this be done easily? Anyone can give me any advice? Thanks in advance.

Appreciate any help!

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


hong615,

welcome to futures.io (formerly BMT). Can you please clarify your request a little bit by giving an example? What exactly is the "previous 2 days price"? What would be the length of your average?
Do you want to compute the (High + Low)/2 price for every 5 minute bar of the preceding two days and then plot this result today as a straight line? Do you have an image of what you are looking for?

Regards,
ABCTG

Follow me on Twitter Reply With Quote
  #4 (permalink)
hong615
hong kong
 
Posts: 4 since Mar 2014
Thanks Given: 0
Thanks Received: 0

ABCTG,

Thanks for nice welcome :-P

Here's a bit more details of what I wanted to do:

it's similar to a moving average, but instead i don't want it to be moving, say today is Mar 19, I want the average of Mar 18 and Mar 17 of all the closing price of a 5-min bar. So the value will be the same within a single date. and updated the next day. The blue line is similar to what i want, but it's using CloseD, will it be possible to use the average close of all the bars?

Thanks again!

Attached Thumbnails
Click image for larger version

Name:	5min.PNG
Views:	200
Size:	35.8 KB
ID:	140883  
Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

hong615,

here you go, I wrote this script for you and it should do what you have in mind.
I didn't hard code the 2 days for the average, you can adapt the amount of days with the "DaysToAverage" input.
All days within the average have the same weight, so it doesn't matter if one of the days is longer than the others they will all have the same influence on the average.

Regards,
ABCTG

 
Code
Inputs:
	DaysToAverage		(2);
	
Variables:
	BarCounter		(0),
	DailyAverage		(0),
	XDayAvg		(0),
	ArrayFull		(false),
	DayCounter		(-1);
		
Arrays:
	DayAverage []		(0);

once
begin
	Array_SetMaxIndex(DayAverage, DaysToAverage-1);
end;

//store daily Average and compute new x day average for today
if Date <> Date[1] then
begin	
	DayCounter += 1;
	
	if DayCounter >= DaysToAverage then
	begin
		once ArrayFull = true;
		DayCounter = 0;
	end;
	
	//store previous day's average
	if BarCounter <> 0 then
		DayAverage[DayCounter] = DailyAverage / BarCounter;

	//compute x day average
	if ArrayFull then
		XDayAvg = Array_Sum(DayAverage, 0, DaysToAverage-1) / DaysToAverage;

	//reset tracking variables
	BarCounter = 0;
	DailyAverage = 0;
end;

//increment counter and track value for daily average
BarCounter += 1;
DailyAverage += Close;

//output x day average
Plot1(XDayAvg, "XDayAvg");

Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
hong615
hong kong
 
Posts: 4 since Mar 2014
Thanks Given: 0
Thanks Received: 0

thanks, ABCTG. That helps a lot!

Reply With Quote




Last Updated on March 28, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts