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;
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?