Capture certain time periods of an array  [SOLVED]

Questions about MultiCharts and user contributed studies.
evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Capture certain time periods of an array

Postby evdl » 04 Dec 2012

I have made an array of the price range (high -/- low) of the day.

The array calculates all the price ranges of the days that are on the chart.

I am now looking for the weekly price range and montly price range.

This is the code I use for the daily, weekly and monthly price range:

Code: Select all

Inputs:
plot_right_corner(true),
print_indicator_daily(false),
print_indicator_weekly(false),
print_indicator_monthly(false),
filename_daily_PR("C:\users\evdl\documents\" + "Daily price range  " + getsymbolname + ".txt"),
filename_weekly_PR("C:\users\evdl\documents\" + "Weekly price range  " + getsymbolname + ".txt"),
filename_monthly_PR("C:\users\evdl\documents\" + "Monthly price range  " + getsymbolname + ".txt");

Variables: 
// Pricerange variabels
Count(0),
Count_week(0),
Count_month(0),
// Daily
Price_range(0),
Average_pricerange(0),
Average_open_gap (0),
TodayHigh(0),
TodayLow(0),
TodayHigh_trigger(0),
TodayLow_trigger(0),
Highest_pricerange(0),
TodayHigh_array(0),
TodayLow_array(0),
// Weekly
Price_range_week(0),
Average_pricerange_week(0),
Highest_pricerange_week(0),
WeekHigh(0),
WeekLow(0),
WeekHigh_trigger(0),
WeekLow_trigger(0),
WeekHigh_array(0),
WeekLow_array(0),
// Monthly
Price_range_month(0),
Average_pricerange_month(0),
Highest_pricerange_month(0),
MonthHigh(0),
MonthLow(0),
MonthHigh_trigger(0),
MonthLow_trigger(0),
MonthHigh_array(0),
MonthLow_array(0),
Init_daily(true),
Init_weekly(true),
Init_monthly(true),
Textstring(""),
Dateformat_open(""),
Dateformat_open_week(""),
Dateformat_open_month("");
     
Array:
day_high_array[] (0),
day_low_array[] (0),
price_range_day_array[] (0),
week_high_array[] (0),
week_low_array[] (0),
price_range_week_array[] (0),
month_high_array[] (0),
month_low_array[] (0),
price_range_month_array[] (0);

// END OF DECLARATIONS -----------------------------------------------------

If (barstatus(1) = 2) and (sessionlastbar = true) then begin
 
   TodayHigh = highd(0);
   TodayLow = lowd(0);
   Dateformat_open = formatdate("dd-MM-yyyy", eldatetodatetime(date));
   TodayHigh_trigger = 0;
   TodayLow_trigger = 99999;

   // increment the count at the beginning of a new day
   count = count + 1;

   // expand the array by one
   Array_setmaxindex(day_high_array, count);
   Array_setmaxindex(day_low_array, count);
   Array_setmaxindex(price_range_day_array, count); 
             
   // post data to array
   day_high_array[count] = maxlist( TodayHigh_trigger , Todayhigh);
   day_low_array[count] = minlist( Todaylow_trigger, TodayLow);
           
   // Use variabels for array's
   TodayHigh_array = day_high_array[count];
   TodayLow_array = day_low_array[count];
             
   // calculate the price range
   price_range_day_array[count] =  TodayHigh_array - TodayLow_array;
   price_range = price_range_day_array[count];   
 
   // calculate the average price range
   average_pricerange = AverageArray(price_range_day_array,count);
     
   // calculate the highest price range
   highest_pricerange = HighestArray(price_range_day_array, count);
   
End;
// END OF CALCULATING PRICERANGE ------------------------------------ 

// BEGIN CALCULATING OF THE WEEKLY HIGH, LOW ----------------------- 

If (barstatus(1) = 2) and (sessionlastbar = true) then begin
 
   WeekHigh = highW(0);
   WeekLow = lowW(0);
   Dateformat_open_week = formatdate("dd-MM-yyyy", eldatetodatetime(date));
   WeekHigh_trigger = 0;
   WeekLow_trigger = 99999;
 
   // increment the count at the beginning of a new day
   count_week = count_week + 1;

   // expand the array by one
   Array_setmaxindex(week_high_array, count_week);
   Array_setmaxindex(week_low_array, count_week);
   Array_setmaxindex(price_range_week_array, count_week); 
          
   // post data to array
   week_high_array[count_week] = maxlist( Weekhigh_trigger , WeekHigh );
   week_low_array[count_week] = minlist( WeekLow_trigger, WeekLow );
   
   // Use variabels for array's
   WeekHigh_array = week_high_array[count_week];
   WeekLow_array = week_low_array[count_week];
           
   // calculate the price range
   price_range_week_array[count_week] = WeekHigh_array - WeekLow_array;
   price_range_week = price_range_week_array[count_week];   
 
   // calculate the average price range
   average_pricerange_week = AverageArray(price_range_week_array,count_week);
   
   // calculate the highest price range
   highest_pricerange_week = HighestArray(price_range_week_array, count_week);
End;
// END CALCULATING OF THE WEEKLY HIGH, LOW --------------------------------------- 

// BEGIN CALCULATING OF THE MONTLY HIGH, LOW -------------------------------------
If (barstatus(1) = 2) and (sessionlastbar = true) then begin
   
   MonthHigh = HighM(0);
   MonthLow = LowM(0);
   Dateformat_open_month = formatdate("dd-MM-yyyy", eldatetodatetime(date));
   MonthHigh_trigger = 0;
   MonthLow_trigger = 99999;
 
   // increment the count at the beginning of a new day
   count_month = count_month + 1;

   // expand the array by one
   Array_setmaxindex(month_high_array, count_month);
   Array_setmaxindex(month_low_array, count_month);
   Array_setmaxindex(price_range_month_array, count_month); 
          
   // post data to array
   month_high_array[count_month] = maxlist( Monthhigh_trigger , MonthHigh );
   month_low_array[count_month] = minlist( MonthLow_trigger, MonthLow );
   
   // Use variabels for array's
   MonthHigh_array = month_high_array[count_month];
   MonthLow_array = month_low_array[count_month];
           
   // calculate the price range
   price_range_month_array[count_month] = Monthhigh_array - Monthlow_array;
   price_range_month = price_range_month_array[count_month];   
 
   // calculate the average price range
   average_pricerange_month = AverageArray(price_range_month_array,count_month);
   
   // calculate the highest price range
   highest_pricerange_month = HighestArray(price_range_month_array, count_month);
End;
// END CALCULATING OF THE MONTLY HIGH, LOW ---------------------------------------   

// PRINT TO FILE DAILY VALUES
if print_indicator_daily then begin

// Start printing at switching on the indicator
  If init_daily then begin
   init_daily = false; //print only once
   FileDelete(filename_daily_PR);
   Fileappend(filename_daily_PR,"Datum;   High;   Low;   Price range;   Avg price range;   Highest price range"+ Newline);
  end;

If (barstatus(1) = 2) and (sessionlastbar = true) then begin

// Text formatting in file
   textstring = dateformat_open + ";";
   textstring = textstring + numtostr(TodayHigh,2) + ";";
   textstring = textstring + numtostr(TodayLow,2) + ";";
   textstring = textstring + numtostr(price_range,2) + ";";
   textstring = textstring + numtostr(average_pricerange,2) + ";";
   textstring = textstring + numtostr(highest_pricerange,2);
   Fileappend(filename_daily_PR, textstring + newline);
 end;
end;

// PRINT TO FILE WEEKLY VALUES
If print_indicator_weekly then begin

// Start printing at switching on the indicator
  If init_weekly then begin
   init_weekly = false; //print only once
   FileDelete(filename_weekly_PR);
   Fileappend(filename_weekly_PR,"Datum;   High;   Low;   Price range;   Avg price range;   Highest price range"+ Newline);
  end;

 If (barstatus(1) = 2) and (sessionlastbar = true) then begin

// Text formatting in file
   textstring = dateformat_open_week + ";";
   textstring = textstring + numtostr(weekhigh,2) + ";";
   textstring = textstring + numtostr(weeklow,2) + ";";
   textstring = textstring + numtostr(price_range_week,2) + ";";
   textstring = textstring + numtostr(average_pricerange_week,2) + ";";
   textstring = textstring + numtostr(highest_pricerange_week,2) + ";";
   Fileappend(filename_weekly_PR, textstring + newline);
 
  end;
End;

// PRINT TO FILE MONTLY VALUES
if print_indicator_monthly then begin

// Start printing at switching on the indicator
  If init_monthly then begin
   init_monthly = false; //print only once
   FileDelete(filename_monthly_PR);
   Fileappend(filename_monthly_PR,"Datum;   High;   Low;   Price range;   Avg price range;   Highest price range"+ Newline);
  end;

   If (barstatus(1) = 2) and (sessionlastbar = true) then begin
 
// Text formatting in file
   textstring = dateformat_open_month + ";";
   textstring = textstring + numtostr(MonthHigh,2) + ";";
   textstring = textstring + numtostr(MonthLow,2) + ";";
   textstring = textstring + numtostr(price_range_month,2) + ";";
   textstring = textstring + numtostr(average_pricerange_month,2) + ";";
   textstring = textstring + numtostr(highest_pricerange_month,2);
   Fileappend(filename_monthly_PR, textstring + newline);
   end;
End;


With "if(barstatus(1) = 2) and (sessionlastbar = true then begin" all the values during the day will be evaluated and the highs and lows will be in the file per day. But also for the week and month values. If you have one year of data on the chart, there should be 52 lines for the price range of the weeks and 12 lines for the monthly values.

I tried to use "Dayofweek(date) > dayofweek(date[1]) then begin" for the weeks and "month(date) <> Month(date[1]) then begin" for thr month values.

Problem with this is, that I will get the 52 lines and 12 lines, but those are the values of the first bar of the last day in that particular period.

How do I get the high/lows (= price range) per week and per month or any other interval I would like?

arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: Capture certain time periods of an array

Postby arjfca » 05 Dec 2012

Hello
Here is some code that I have done

Month:

Code: Select all

//MonthBegin
// Return true if the bar is the first bar of a new month

MonthBegin = False;
If (Month(date) <> Month(date[1])) then MonthBegin = true;


Week

Code: Select all

//WeekBegin
//Return true if the first bar is the begining of the week

//If actual day = Sunday and the previous
WeekBegin = False;
If (dayofweek(date) = 0 or dayofweek(date) = 1 ) and dayofweek(date[1]) = 5 then weekBegin = True;


Now to get the high and low between these period

Code: Select all

// - Create variables 
Var: WeekHigh (0),
WeekLow (9999) ,
MonthHiigh (0),
MonthLow (9999);

If High > WeekHigh then WeekHigh = High
If Low < WeekLow then WeekLow = Low

If High > MonthHigh > then MonthHigh = High
If Low < MonthLow then MonthLow = Low

If WeekBegin = true then Begin   // Since the week begin, the last week is terminated
  HistoricWeekHigh = WeekHigh
  HistoricWeekLow = WeekLow
 
  WeekHigh = 0
  WeekLow = 9999
end


Just written for you.. May have error and ";" not put Just to show how I have done it.

Martin

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 05 Dec 2012

Thank you Martin,

I will try this and let you know.

Best regards,

Edwin

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 09 Dec 2012

I am not sure how to incorporate the suggestion of martin in my signal. I tried different possibilities.

The best I have managed to do, is to get the daily values of the pricerange, average rang and highest rang and calculate an average on that weekly and monthly.

But that is different then having a weekly or monthly value and calculate an average on that value.

For those interested, see the excel file. I will have to experiment so more.

But thank you Martin for the suggestion.

greetings
Edwin
Attachments
Dax values.xls
(76 KiB) Downloaded 82 times

arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: Capture certain time periods of an array

Postby arjfca » 09 Dec 2012

evdl wrote:I am not sure how to incorporate the suggestion of martin in my signal. I tried different possibilities.

The best I have managed to do, is to get the daily values of the pricerange, average rang and highest rang and calculate an average on that weekly and monthly.

But that is different then having a weekly or monthly value and calculate an average on that value.

For those interested, see the excel file. I will have to experiment so more.

But thank you Martin for the suggestion.

greetings
Edwin

Evdl

Could you describe your questioning.
- Is it in Excel
- Did you get your data in Excel
- If yopu want to get advise in Excel, look for MrExcel forum... the best one for me
- Is it on how to get those values
- Is it on how to calculate average
- Etc

- Best suggestion is, as user TJ ** may wrote you, take a pencil and paper and wrote down your idea. Explain what you want to achieve etc. Once your idea as been clarified then the step to get it will be more clear. Look at small step at the time, not the whole project.

Looking at your Annexed document, your interrogation seem to be with Excel. I'm not good with formula in cell, better with VBA. Again, you may ask your question on MrExcel forum about how to get sub total
1- Create a subtotal per month
2- Calculate, How many days in the month
3- the average will be the total of the month / how many days in the month

Good luck
Martin

**User TJ: One of the best on this forum

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 10 Dec 2012

The indicator is printing the values to excel. I don't do any calculating in excel, it is a way of showing the results for me.

With the code I have, it is possible to calculate the daily price range, an average of the daily price range and the highest ever daily pricerange. This works ok.

I also want to calculate the weekly price range, an average of the weekly price range and the highest ever weekly pricerange. And this also monthly.

If you see the following weekly price ranges:
Date DailyHigh DailyLow Pricerange avg PR highest PR
05-11-12 7337,47 7304,45 33,02 185,70 432,79
06-11-12 7388,98 7304,45 84,53 185,28 432,79
07-11-12 7434,96 7226,60 208,36 185,38 432,79
08-11-12 7434,96 7184,18 250,78 185,65 432,79
09-11-12 7434,96 7064,34 370,62 186,42 432,79 370,62(this I need)
12-11-12 7196,00 7138,17 57,83 185,88 432,79
13-11-12 7196,00 7074,87 121,13 185,62 432,79
14-11-12 7196,00 7074,87 121,13 185,35 432,79
15-11-12 7196,00 7021,62 174,38 185,31 432,79
16-11-12 7196,00 6954,43 241,57 185,54 432,79 241,57(this I need)

The above is the calculated weekly high and lows, and pricerange. But as you see it calculates this every day (with the use of "If (barstatus(1) = 2) and (sessionlastbar = true) then begin"). It will hold the high and low for every day. And on a friday the high and low of the week is the final high and low. I am only interested in the final values. I want the weekly high/low and priceranges calculating like this:

Date WeeklyHigh WeeklyLow Pricerange avg PR highest PR
09-11-12 7434,96 7064,34 370,62 186,42 432,79
16-11-12 7196,00 6954,43 241,57 185,54 432,79
23-11-12 etc.

I tried to use dayofdate(date) > dayofdate(date[1]) then begin.

But what then happens is like the two lines above, but only the high and low and pricerange is calculated over the first bar of the first day of a week. And it not calculates the high and low and pricerange over the whole week (monday till friday).

How can I code the indicator, that it will screen every day, but only store the high/low and pricerange per week and month. And use this values to calculate the avg pricerange.

arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: Capture certain time periods of an array

Postby arjfca » 10 Dec 2012

Hello
Look inside of my code. I use it as a deliminator of week and months on a chart

Code: Select all

// Week and months deliminator by Martin Theriault  2012/12/10
Inputs:   

WeekColor (Blue),
MonthColor ( darkGreen);

Var:
LineTime_1 (0),
LineNumHigh_Intra (0),
LineNumLow_Intra (0),
Offset(0),
HighIntra (0),
LowIntra (0),
StartTheHighLow (false),
Bardone (false),
UpperPrice (0),
LowerPrice (0);
 
Offset = 50* Minmove/PriceScale;
//LineTime_2 = calctime_S(lineTime,120);
{
If barnumber = 0 then begin
         LineNumHigh_Intra = TL_New_s (Date, Time_s,0, Date, Time_s, 0);
         LineNumLow_Intra =   TL_New_s (Date, Time_s,0, Date, Time_s, 0);
end;
}
If barstatus = 2 then begin

   Lowerprice = getappinfo(ailowestDispValue)*.5;
   UpperPrice = getappinfo(aiHighestDispValue)*4;


   If weekbegin = true then begin
      Bardone = True;
      Value1 = TL_New_S(D,Time_S,H+(Offset),D,Time_S,upperprice);
      TL_SetColor(Value1,WeekColor);
      TL_SetStyle(Value1,Tool_dotted);
      TL_SetSize(Value1,0.5);
      Value10 = TL_New_S(D,Time_s,l-offset,D,Time_S,lowerPrice);
      TL_SetColor(Value10,WeekColor);
      TL_SetStyle(Value10,Tool_dotted);
      TL_SetSize(Value10,0.5);
   End;

   If Monthbegin = true then begin
      Bardone = True;
      Value1 = TL_New_S(D,Time_S,H+(Offset),D,Time_S,upperprice);
      TL_SetColor(Value1,MonthColor);
      TL_SetStyle(Value1,Tool_Solid);
      TL_SetSize(Value1,0.5);
      Value10 = TL_New_S(D,Time_s,l-offset,D,Time_S,lowerPrice);
      TL_SetColor(Value10,MonthColor);
      TL_SetStyle(Value10,Tool_Solid);
      TL_SetSize(Value10,0.5);
   End;
End; //Barstatus =2


Now, At the begining og a week, reset a value after having compute the previous week result.
Weekhigh = 0
Weeklow = 99
WeekAverage = 0
Daycount = 0

If High > WeekHigh than weekhigh = High
If Low < WeekLow then WeekLow = Low
Weekaverage = weekaverage + Close[1] // add the value of the last close
If a new day the daycount = daycount +1

When a new weekstart, The previous variable hold your info
LastWeekRange = WeekHigh - WeekLow
LastWeekAverage =WeekAverage / Daycount
etc.

One step at the time. First thing first, deliminate your week and month
- Compute and accumulate info between the period
- Once terminated or begining of a new one, do a wrapup and calculate your range and average

Hope it help

Martin

arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: Capture certain time periods of an array

Postby arjfca » 10 Dec 2012

Hello
Look inside of my code. I use it as a deliminator of week and months on a chart

Code: Select all

// Week and months deliminator by Martin Theriault  2012/12/10
Inputs:   

WeekColor (Blue),
MonthColor ( darkGreen);

Var:
LineTime_1 (0),
LineNumHigh_Intra (0),
LineNumLow_Intra (0),
Offset(0),
HighIntra (0),
LowIntra (0),
StartTheHighLow (false),
Bardone (false),
UpperPrice (0),
LowerPrice (0);
 
Offset = 50* Minmove/PriceScale;
//LineTime_2 = calctime_S(lineTime,120);
{
If barnumber = 0 then begin
         LineNumHigh_Intra = TL_New_s (Date, Time_s,0, Date, Time_s, 0);
         LineNumLow_Intra =   TL_New_s (Date, Time_s,0, Date, Time_s, 0);
end;
}
If barstatus = 2 then begin

   Lowerprice = getappinfo(ailowestDispValue)*.5;
   UpperPrice = getappinfo(aiHighestDispValue)*4;


   If weekbegin = true then begin
      Bardone = True;
      Value1 = TL_New_S(D,Time_S,H+(Offset),D,Time_S,upperprice);
      TL_SetColor(Value1,WeekColor);
      TL_SetStyle(Value1,Tool_dotted);
      TL_SetSize(Value1,0.5);
      Value10 = TL_New_S(D,Time_s,l-offset,D,Time_S,lowerPrice);
      TL_SetColor(Value10,WeekColor);
      TL_SetStyle(Value10,Tool_dotted);
      TL_SetSize(Value10,0.5);
   End;

   If Monthbegin = true then begin
      Bardone = True;
      Value1 = TL_New_S(D,Time_S,H+(Offset),D,Time_S,upperprice);
      TL_SetColor(Value1,MonthColor);
      TL_SetStyle(Value1,Tool_Solid);
      TL_SetSize(Value1,0.5);
      Value10 = TL_New_S(D,Time_s,l-offset,D,Time_S,lowerPrice);
      TL_SetColor(Value10,MonthColor);
      TL_SetStyle(Value10,Tool_Solid);
      TL_SetSize(Value10,0.5);
   End;
End; //Barstatus =2


Now, At the begining og a week, reset a value after having compute the previous week result.
Weekhigh = 0
Weeklow = 99
WeekAverage = 0
Daycount = 0

If High > WeekHigh than weekhigh = High
If Low < WeekLow then WeekLow = Low
Weekaverage = weekaverage + Close[1] // add the value of the last close
If a new day the daycount = daycount +1

When a new weekstart, The previous variable hold your info
LastWeekRange = WeekHigh - WeekLow
LastWeekAverage =WeekAverage / Daycount
etc.

One step at the time. First thing first, deliminate your week and month
- Compute and accumulate info between the period
- Once terminated or begining of a new one, do a wrapup and calculate your range and average

Hope it help

Martin

arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: Capture certain time periods of an array

Postby arjfca » 10 Dec 2012

A point to note also

If you want your variable to be valid all accross the process, you may need to declare them as Intrabarpersist

like: IntrabarpersistWeekHigh (0);

Other wise, after each new bar, ( day bar per example) the variable WeekHigh will be reset.

Your Main question was also about array
To declare them
Array: WeekAverageValue[52](0);
will declare an array named WeekAverageValue that have 52 spaces allocated to it and the initial value is 0
- If you declare it with no number between the brackets like [] then there is no space limit to your array.
- If you place a number between the parenthesis, then each part of the array will have this value like (99) ... WeekAverageValue[3] = 99

Martin

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 10 Dec 2012

Thanks a lot for your time Martin, appreciate it.

I have been testing all day and for the week priceranges I came up with a solution

Before I used:

Code: Select all

If (barstatus(1) = 2) and (sessionlastbar = true)then begin


Replaced it with:

Code: Select all

If DayOfWeek( Date ) = 5 and (sessionlastbar = true) then begin 


Now it will check the latest day of the week when all high and lows are registrated and then with the highW and lowW function I have the right values in the array.

For the month values, it is a bit more difficult because the last day can also be in a weekend. So I need the last trade day of the month and then use highM and lowM.

this code does not work:

Code: Select all

If (dayofmonth(date) = LastDayOfMonth(Month(date)) and (sessionlastbar = true) then begin


Because the months with 30 days and 28 days are not calculated. So I am busy testing that at the moment.

arjfca
Posts: 1263
Joined: 23 Nov 2010
Has thanked: 717 times
Been thanked: 221 times

Re: Capture certain time periods of an array

Postby arjfca » 10 Dec 2012

For the month,,, not to hard

Look here
https://www.multicharts.com/trading-soft ... .php/Month

You could also use the date of the bar
- From it, Extract the month value
- If Month_date <> Month_date [1] then newmont = true

Martin
These users thanked the author arjfca for the post:
evdl

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 18 Dec 2012

Manage to get the monthly values (high/low, average) and then only display the values of the last trading day of the month at the lastbar of the month. This is different then on the first bar of the month with "month(date) <> month(date[1])". The trouble was to detect saturday and sunday. That was a bit of trial and error, because if you test it on a symbol that is not traded in the weekends, there is no bar data and you can not use dayofweek(date) = 6 or 0 to detect these days. I didn't know that.

Code: Select all

// BEGIN CALCULATING OF THE MONTLY HIGH, LOW -------------------------------------

// Determine last tradingday of the month
   Month# = Month(date);

   // January
   If (Month# = 1) then begin
    January_trigger = true;
   End;

   If (month# <> 1) then begin
    january_trigger = false;
   end;

   If january_trigger = true and dayofweek(date) =5 and dayofmonth(date) = 29 or
    (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=31 then begin
    LastTradingDayOfMonth_january = true;
   end;

   If january_trigger = false then begin
    LasttradingDayofmonth_january = false;
   End;

   // February
   If (Month# = 2) then begin
    February_trigger = true;
   end;

   If (month# <> 2) then begin
    February_trigger = false;
   end;

   If february_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 26 or
    (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=28 then begin
    LastTradingDayOfMonth_february = true;
   end;

   If February_trigger = false then begin
    LasttradingDayofmonth_february = false;
   End;

   // March
    If (Month# = 3) then begin
     march_trigger = true;
    End;

    If (month# <> 3) then begin
     march_trigger = false;
    end;

    If march_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 29 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=31 then begin
     LastTradingDayOfMonth_march = true;
    end;

    If march_trigger = false then begin
     LasttradingDayofmonth_march = false;
    End;

    // April
    If (Month# = 4) then begin
     April_trigger = true;
    End;

    If (month# <> 4) then begin
     April_trigger = false;
    end;

    If april_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 28 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=30 then begin
     LastTradingDayOfMonth_april = true;
    end;

    If April_trigger = false then begin
     LasttradingDayofmonth_april = false;
    End;

    // May
    If (Month# = 5) then begin
     may_trigger = true;
    End;

    If (month# <> 5) then begin
     May_trigger = false;
    end;

    If may_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 29 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=31 then begin
     LastTradingDayOfMonth_may = true;
    end;

    If may_trigger = false then begin
     LasttradingDayofmonth_may = false;
    End;

    // June
    If (Month# = 6) then begin
     june_trigger = true;
    End;

    If (month# <> 6) then begin
     june_trigger = false;
    end;

    If june_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 28 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=30 then begin
     LastTradingDayOfMonth_june = true;
    end;

    If june_trigger = false then begin
     LasttradingDayofmonth_june = false;
    End;

    // July
    If (Month# = 7) then begin
     july_trigger = true;
    End;

    If (month# <> 7) then begin
     july_trigger = false;
    end;

    If july_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 29 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=31 then begin
     LastTradingDayOfMonth_july = true;
    end;

    If july_trigger = false then begin
     LasttradingDayofmonth_july = false;
    End;

    // August
    If (Month# = 8) then begin
     august_trigger = true;
    End;

    If (month# <> 8) then begin
     august_trigger = false;
    end;

    If august_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 29 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=31 then begin
     LastTradingDayOfMonth_august = true;
    end;

    If august_trigger = false then begin
     LasttradingDayofmonth_august = false;
    End;

    // September
    If (Month# = 9) then begin
     september_trigger = true;
    End;

    If (month# <> 9) then begin
     september_trigger = false;
    end;

    If september_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 28 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=30 then begin
     LastTradingDayOfMonth_september = true;
    end;

    If september_trigger = false then begin
     LasttradingDayofmonth_september = false;
    End;

    // October
    If (Month# = 10) then begin
     October_trigger = true;
    End;

    If (month# <> 10) then begin
     October_trigger = false;
    end;

    If october_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 29 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=31 then begin
     LastTradingDayOfMonth_october = true;
    end;

    If october_trigger = false then begin
     LasttradingDayofmonth_october = false;
    End;

    // November
    If (Month# = 11) then begin
     november_trigger = true;
    End;

    If (month# <> 11) then begin
     november_trigger = false;
    end;

    If november_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 28 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=30 then begin
     LastTradingDayOfMonth_november = true;
    end;

    If november_trigger = false then begin
     LasttradingDayofmonth_november = false;
    End;

    // December
    If (Month# = 12) then begin
     December_trigger = true;
    End;

    If (month# <> 12) then begin
     December_trigger = false;
    end;

    If december_trigger = true and dayofweek(date) =5 and dayofmonth(date) >= 29 or
     (dayofweek(date) >=1 and dayofweek(date) < 5) and dayofmonth(date)=31 then begin
     LastTradingDayOfMonth_december = true;
    end;

    If December_trigger = false then begin
     LasttradingDayofmonth_december = false;
    End;
// END DETERMINE LASTTRADING DAY ------------------------------------------------------------------

If lastTradingDayOfMonth_january = true and (sessionlastbar = true) or
lastTradingDayOfMonth_february = true and (sessionlastbar = true) or
lastTradingDayOfMonth_march = true and (sessionlastbar = true) or
lastTradingDayOfMonth_april = true and (sessionlastbar = true) or
lastTradingDayOfMonth_may = true and (sessionlastbar = true) or
lastTradingDayOfMonth_june = true and (sessionlastbar = true) or
lastTradingDayOfMonth_july = true and (sessionlastbar = true) or
lastTradingDayOfMonth_august = true and (sessionlastbar = true) or
lastTradingDayOfMonth_september = true and (sessionlastbar = true)or
lastTradingDayOfMonth_october = true and (sessionlastbar = true) or
lastTradingDayOfMonth_november = true and (sessionlastbar = true) or
lastTradingDayOfMonth_december = true and (sessionlastbar = true) then begin
   
   MonthHigh = HighM(0);
   MonthLow = LowM(0);
   Dateformat_open_month = formatdate("dd-MM-yyyy", eldatetodatetime(date));
   MonthHigh_trigger = 0;
   MonthLow_trigger = 99999;
 
   // increment the count at the beginning of a new day
   count_month = count_month + 1;

   // expand the array by one
   Array_setmaxindex(month_high_array, count_month);
   Array_setmaxindex(month_low_array, count_month);
   Array_setmaxindex(price_range_month_array, count_month); 
          
   // post data to array
   month_high_array[count_month] = MonthHigh;
   month_low_array[count_month] = MonthLow;
     
   // Use variabels for array's
   MonthHigh_array = month_high_array[count_month];
   MonthLow_array = month_low_array[count_month];
           
   // calculate the price range
   price_range_month_array[count_month] = Monthhigh_array - Monthlow_array;
   price_range_month = price_range_month_array[count_month];   
 
   // calculate the average price range
   average_pricerange_month = AverageArray(price_range_month_array,count_month);
   
   // calculate the highest price range
   highest_pricerange_month = HighestArray(price_range_month_array, count_month);
End;
// END CALCULATING OF THE MONTLY HIGH, LOW ---------------------------------------


will give you this (only issue is the leapyear, but that is only february 2012, but I am not going to spend more time at the moment to solve this):

Code: Select all

Datum;   High;   Low;   Price range;   Avg price range;   Highest price range
30-12-2011;5965.35;5637.53;327.82;327.82;327.82
31-01-2012;6574.19;5900.18;674.01;500.92;674.01
28-02-2012;6971.03;6482.56;488.47;496.77;674.01
29-02-2012;6971.03;6482.56;488.47;494.69;674.01
30-03-2012;7194.33;6612.61;581.72;512.10;674.01
30-04-2012;7081.06;6499.07;581.99;523.75;674.01
31-05-2012;6875.87;6208.09;667.78;544.32;674.01
29-06-2012;6427.49;5914.43;513.06;540.41;674.01
31-07-2012;6835.19;6324.53;510.66;537.11;674.01
31-08-2012;7105.43;6596.21;509.22;534.32;674.01
28-09-2012;7478.53;6892.86;585.67;538.99;674.01
31-10-2012;7447.81;7120.68;327.13;521.33;674.01
30-11-2012;7442.54;6954.43;488.11;518.78;674.01
These users thanked the author evdl for the post (total 2):
TJnuno-online

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 18 Dec 2012

Nice work evdl. Thanks for sharing.

Here are some snippets you can consider:

to collect month high/low data, instead of using highM lowM, you can try this. I found them more efficient than using the functions. And if you use the same concept on weeks, you do not have to worry about non-trading days.

Code: Select all

var:
high.of.the.month(0),
low.of.the.month(0);

if h > high.of.the.month then
high.of.the.month = h;

if L < low.of.the.month then
low.of.the.month = L;


to detect the end of the week:

Code: Select all

var:
new.week(false);

new.week = dayofweek(date) < dayofweek(date[1]);
These users thanked the author TJ for the post:
evdl

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 18 Dec 2012

Hello TJ,

If you use high and low as you suggest. What do you use for getting the weekly or monthly time interval?

For example:

Code: Select all

if month(date) > month(date[1]) then or month(date) <> month(date[1] then)
or
date > date[1] then

"high /low calculating"


I had problems with getting the monthly / weekly interval and still covering all the data in the wanted time interval. And not only the high/lows of the first bar of the day, week or month. I worked around it with creating variabels and using sessionlastbar and certain days in the week and month to cover the whole wanted period.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 18 Dec 2012

you can try this

Code: Select all

var:
high.of.month(0),
low.of.month(0),
high.of.week(0),
low.of.week(0);

if month(date) <> month(date[1]) then // new month
begin
     array.high.month[month(date[1])] = high.of.month[1]; // pseudo code to assigns recording to array
     array.low.month[month(date[1])] = low.of.month[1]; //  pseudo code to assigns recording to array

     high.of.month = h;  // resets the variable at the beginning of each month
     low.of.month = L;  // resets the variable at the beginning of each month
end
else
begin // accumulates high/low data for the month

     if h > high.of.month then high.of.month = h;
     if L < low.of.month then low.of.month = L;
end;

I hope you get the idea. You can duplicate the effort for the week stats.


note: the array portion is pseudo code only. You have to define the detail.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 18 Dec 2012

ps. you do have to add a route to account for January (1) being a smaller number than December (12).

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 18 Dec 2012

Just tried what you suggested. What I noticed is that indeed december and january is missing. And the calculating time is longer.

With your solution the values are calculated with referencing historical (month(date[1])). And with the way I did it, the script is calculating at the end of the monthly timeinterval.

For high and low and the pricerange both methods work (except for the first months) and yours is way shorter. But I encounter in a problem with the average and highest pricerange. Because it reference historical and when the chart history ends (I have 365 days on chart), the high and or low is 0 which creates strange values for the first month and for the averages on the whole period.

Code: Select all

Datum;   High;   Low;   Price range;   Avg price range;   Highest price range
01-02-2012;6574.19;0.00;6574.19;6188.51;6574.19
01-03-2012;6971.03;6482.56;488.47;4026.91;6574.19
02-04-2012;7194.33;6612.61;581.72;3021.45;6574.19
02-05-2012;7081.06;6499.07;581.99;2523.20;6574.19
01-06-2012;6875.87;6208.09;667.78;2156.26;6574.19
02-07-2012;6427.49;5914.43;513.06;1895.03;6574.19
01-08-2012;6835.19;6324.53;510.66;1683.07;6574.19
03-09-2012;7105.43;6596.21;509.22;1525.03;6574.19
01-10-2012;7478.53;6892.86;585.67;1419.33;6574.19
01-11-2012;7447.81;7120.68;327.13;1299.92;6574.19
03-12-2012;7442.54;6954.43;488.11;1218.51;6574.19


I used this code:

Code: Select all

var:
high.of.month(0),
low.of.month(0),
high.of.week(0),
low.of.week(0);

if month(date) > month(date[1]) then begin
   
   Dateformat_open_month = formatdate("dd-MM-yyyy", eldatetodatetime(date));
   high.of.month = h;  // resets the variable at the beginning of each month
   low.of.month = L;  // resets the variable at the beginning of each month
   end
   else
   begin // accumulates high/low data for the month
    if h > high.of.month then high.of.month = h;
    if L < low.of.month then low.of.month = L;
 
  // increment the count at the beginning of a new day
   Count_month = count_month + 1;

   // expand the array by one
   Array_setmaxindex(month_high_array, Count_month);
   Array_setmaxindex(month_low_array, Count_month);
   Array_setmaxindex(price_range_month_array, Count_month); 
         
   // post data to array
   month_high_array[Count_month] = high.of.month[1];
   month_low_array[Count_month] = low.of.month[1];
         
   // Use variabels for array's
   MonthHigh_array = month_high_array[Count_month];
   MonthLow_array = month_low_array[Count_month];
           
   // calculate the price range
   price_range_month_array[Count_month] = Monthhigh_array - Monthlow_array;
   price_range_month = price_range_month_array[Count_month];   
 
   // calculate the average price range
   average_pricerange_month = AverageArray(price_range_month_array,Count_month);
   
   // calculate the highest price range
   highest_pricerange_month = HighestArray(price_range_month_array, Count_month);
End;
// END CALCULATING OF THE MONTLY HIGH, LOW ---------------------------------------   

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 18 Dec 2012

TJ wrote:ps. you do have to add a route to account for January (1) being a smaller number than December (12).

I should have used the following code. It should cure the problem.
I have corrected the code above.
Note: <>

Code: Select all

if month(date) <> month(date[1]) then
begin


evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 18 Dec 2012

Thanks TJ, I will try that tomorrow and see how that works out.

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 19 Dec 2012

I should have used the following code. It should cure the problem.
I have corrected the code above.
Note: <>

Code:

if month(date) <> month(date[1]) then
begin


This will indeed solve the december/january issue. But the average and highest price range issue still exist with using the above code. Notice the 0.00 for the Low and de avg price range and highest price range, due to referencing historical for data that is outside the chart settings.

Code: Select all

Datum;   High;   Low;   Price range;   Avg price range;   Highest price range
02-01-2012;5965.35;0.00;5965.35;5938.43;5965.35
01-02-2012;6574.19;5900.18;674.01;1980.42;5965.35
01-03-2012;6971.03;6482.56;488.47;1369.34;5965.35
02-04-2012;7194.33;6612.61;581.72;1104.79;5965.35
02-05-2012;7081.06;6499.07;581.99;978.66;5965.35
01-06-2012;6875.87;6208.09;667.78;895.15;5965.35
02-07-2012;6427.49;5914.43;513.06;821.79;5965.35
01-08-2012;6835.19;6324.53;510.66;754.54;5965.35
03-09-2012;7105.43;6596.21;509.22;711.34;5965.35
01-10-2012;7478.53;6892.86;585.67;684.73;5965.35
01-11-2012;7447.81;7120.68;327.13;639.13;5965.35
03-12-2012;7442.54;6954.43;488.11;614.81;5965.35

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 19 Dec 2012

evdl wrote:
I should have used the following code. It should cure the problem.
I have corrected the code above.
Note: <>

Code:

if month(date) <> month(date[1]) then
begin


This will indeed solve the december/january issue. But the average and highest price range issue still exist with using the above code. Notice the 0.00 for the Low and de avg price range and highest price range, due to referencing historical for data that is outside the chart settings.

Code: Select all

Datum;   High;   Low;   Price range;   Avg price range;   Highest price range
02-01-2012;5965.35;0.00;5965.35;5938.43;5965.35
01-02-2012;6574.19;5900.18;674.01;1980.42;5965.35
01-03-2012;6971.03;6482.56;488.47;1369.34;5965.35
02-04-2012;7194.33;6612.61;581.72;1104.79;5965.35
02-05-2012;7081.06;6499.07;581.99;978.66;5965.35
01-06-2012;6875.87;6208.09;667.78;895.15;5965.35
02-07-2012;6427.49;5914.43;513.06;821.79;5965.35
01-08-2012;6835.19;6324.53;510.66;754.54;5965.35
03-09-2012;7105.43;6596.21;509.22;711.34;5965.35
01-10-2012;7478.53;6892.86;585.67;684.73;5965.35
01-11-2012;7447.81;7120.68;327.13;639.13;5965.35
03-12-2012;7442.54;6954.43;488.11;614.81;5965.35

Why do you have 0.00 for the Low ?
Is that due to bad data?

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 19 Dec 2012

Yes, I don't know why I get 0.00. I checked quotemanager and all the data is in. That is why I started to think of another method in the first place. Because at first I also tried the month(date) <> Month(date[1]). Resulting in bad values like this.

I just examined some more and noticed that the first bar that is calculated (= 20 dec 2011) of the high is also 0, but on the second bar it gives the right value for the high.(that is normal behaviour, because you always start with 0).

The values of the low are 0 for the whole december month and only gives values from the first bar of 2 jan 2012 (the first trading day of 2012). So from 20 dec 2011 to 2 jan 2012 there are no values calculated for the low. The high and the low values are in quotemanager. I have no idea what this can be. Maybe something in the low function?

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 19 Dec 2012

evdl wrote:Yes, I don't know why I get 0.00. I checked quotemanager and all the data is in. That is why I started to think of another method in the first place. Because at first I also tried the month(date) <> Month(date[1]). Resulting in bad values like this.

I just examined some more and noticed that the first bar that is calculated (= 20 dec 2011) of the high is also 0, but on the second bar it gives the right value for the high.(that is normal behaviour, because you always start with 0).

The values of the low are 0 for the whole december month and only gives values from the first bar of 2 jan 2012 (the first trading day of 2012). So from 20 dec 2011 to 2 jan 2012 there are no values calculated for the low. The high and the low values are in quotemanager. I have no idea what this can be. Maybe something in the low function?

Have you set your maxbarsback?

You should correct the data in 20 dec 2011, otherwise you will always have bad calculations in all of your indicators.

you can start your indicator on 21 dec if that helps.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 19 Dec 2012

ok, I've got it... you have to initialize the variables differently:

Code: Select all

var:
high.of.month(0),
low.of.month(999999); // or any number that is larger than the largest in your dataset

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 19 Dec 2012

Yes, that's it! Strange how the obvious (zero is the lowest low) is always the most difficult to see.

The high and low and the highest price are the right values. I have still one issue with the month(date) <> month(date[1] method. And that is the average price.

With this method it will take an average of all the priceranges over all the days on the chart. What I wanted to achieve is, to get the pricerange of a month. That is the highest high -/- the lowest low of a month, and take a average of that. So if you have 12 months you will have 12 values of price ranges and take an average of that. With the method we are testing it will take the pricerange of a day and that for every day of the month (example 31 days of priceranges for january) and take an average of that. And that is the average price of january that is calculated now.

See the difference in averages:

My very long method, at the lastbar of the last trading day of the month:

Code: Select all

datum;         High;       Low;      Price range;   Avg price range;   Highest price range
30-12-2011; 5965.35;  5637.53; 327.82;  327.82;  327.82
31-01-2012; 6574.19;  5900.18; 674.01;  500.92;  674.01
28-02-2012; 6971.03;  6482.56; 488.47;  496.77;  674.01
29-02-2012; 6971.03;  6482.56; 488.47;  494.69;  674.01
30-03-2012; 7194.33;  6612.61; 581.72;  512.10;  674.01
30-04-2012; 7081.06;  6499.07; 581.99;  523.75;  674.01
31-05-2012; 6875.87;  6208.09; 667.78;  544.32;  674.01
29-06-2012; 6427.49;  5914.43; 513.06;  540.41;  674.01
31-07-2012; 6835.19;  6324.53; 510.66;  537.11;  674.01
31-08-2012; 7105.43;  6596.21; 509.22;  534.32;  674.01
28-09-2012; 7478.53;  6892.86; 585.67;  538.99;  674.01
31-10-2012; 7447.81;  7120.68; 327.13;  521.33;  674.01
30-11-2012; 7442.54;  6954.43; 488.11;  518.78;  674.01


Month(date) <> month(date[1]) method, at first bar of new month:

Code: Select all

Datum;   High;   Low;   Price range;   Avg price range;   Highest price range
02-01-2012; 5965.35; 5637.53; 327.82;  282.35;  327.82
01-02-2012; 6574.19; 5900.18; 674.01;  372.39;  674.01
01-03-2012; 6971.03; 6482.56; 488.47;  372.72;  674.01
02-04-2012; 7194.33; 6612.61; 581.72;  392.20;  674.01
02-05-2012; 7081.06; 6499.07; 581.99;  406.85;  674.01
01-06-2012; 6875.87; 6208.09; 667.78;  429.71;  674.01
02-07-2012; 6427.49; 5914.43; 513.06;  426.57;  674.01
01-08-2012; 6835.19; 6324.53; 510.66;  413.22;  674.01
03-09-2012; 7105.43; 6596.21; 509.22;  412.64;  674.01
01-10-2012; 7478.53; 6892.86; 585.67;  415.30;  674.01
01-11-2012; 7447.81; 7120.68; 327.13;  397.02;  674.01
03-12-2012; 7442.54; 6954.43; 488.11;  393.76;  674.01


Both methods of calculated averages could have a function, but you have to be aware there is a difference and what the average is saying. (one is calculated per day and displayed per month, and the other is calculated per month and displayed per month(=my long way))

Debugging is a lot of work, but very usefull for getting better in coding. Thanks for your solutions and time TJ!

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 19 Dec 2012

When you say "average", you are really looking at the mid-price between the high of the month and the low of the month. (in a running daily update).

you can add these lines...

Code: Select all

var:
mid.of.month(0);

    if h > high.of.month then high.of.month = h;
    if L < low.of.month then low.of.month = L;
    mid.of.month = (high.of.month + low.of.month)/2;


You can calculate the mid-price before submitting the value to your array.

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array

Postby evdl » 20 Dec 2012

The initial thought was to get the price range of the week and month (high - low). So I can determine the price movement on a certain interval.

The average I was trying to calculate was the monthly pricerange and take an average of that.

I am not sure I get your idea about the midpoint. Do you take the high -/- midpoint as value to the array?

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 20 Dec 2012

evdl wrote:The initial thought was to get the price range of the week and month (high - low). So I can determine the price movement on a certain interval.
The average I was trying to calculate was the monthly pricerange and take an average of that.
I am not sure I get your idea about the midpoint. Do you take the high -/- midpoint as value to the array?

I think I misunderstood your original intent.
These users thanked the author TJ for the post:
evdl

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: Capture certain time periods of an array  [SOLVED]

Postby evdl » 21 Dec 2012

No problem, you have been more then helpfull again. Thank you.

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Capture certain time periods of an array

Postby TJ » 21 Dec 2012

evdl wrote:No problem, you have been more then helpfull again. Thank you.

no problem... you are welcome.


Return to “MultiCharts”