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 2,433 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
Search this Thread
  #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?
CME Group Fee Schedule Changes Hit All Four Exchanges -- …
Traders Hideout
CME Lists U.S. Election Event Contracts as 2028 Democrat …
Prediction Markets & Event Contracts
Kalshi Rockets to $22B, Passes Polymarket in Volume -- B …
Prediction Markets & Event Contracts
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
Ceasefire in Name Only: Three Numbers That Define the Ir …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
BERN ALGOS algo trading journal
8 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642


hong615,

welcome to NexusFi (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 X 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:	257
Size:	35.8 KB
ID:	140883  
Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,642

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 X 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


© 2026 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 - Downloads - Top
no new posts