Look back days with different resolutions  [SOLVED]

Questions about MultiCharts and user contributed studies.
evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Look back days with different resolutions

Postby evdl » 12 Mar 2013

I have a chart with minute data with my strategy on it. I use ADE in my code to get macd values of another chart with daily data.

In my script I try to get the macd data of yesterday and the day before yesterday from the daily data chart.

When you use

Code: Select all

If date <> date[1] then begin
and use macd[1] and macd[2] it will use the minute bar resolution to look back on the daily data. For value[1] it will work and gets the value of yesterday (lastbar of yesterday). But because it uses the minute resolution to look back, value[2] is the bar before the lastbar of yesterday, and not the daily bar of two days ago from the daily chart. The result is that value[2] is also giving the yesterday value. Because it looks in minutes and not in daily bars.

How do I get the historical bars from the daily data chart, when the code on the chart I trade with has 1 minute resolution.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Look back days with different resolutions  [SOLVED]

Postby TJ » 12 Mar 2013

I have a chart with minute data with my strategy on it. I use ADE in my code to get macd values of another chart with daily data.

In my script I try to get the macd data of yesterday and the day before yesterday from the daily data chart.

When you use

Code: Select all

If date <> date[1] then begin
and use macd[1] and macd[2] it will use the minute bar resolution to look back on the daily data. For value[1] it will work and gets the value of yesterday (lastbar of yesterday). But because it uses the minute resolution to look back, value[2] is the bar before the lastbar of yesterday, and not the daily bar of two days ago from the daily chart. The result is that value[2] is also giving the yesterday value. Because it looks in minutes and not in daily bars.

How do I get the historical bars from the daily data chart, when the code on the chart I trade with has 1 minute resolution.
You should set up an array and store the required info in the array for easy access.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Look back days with different resolutions

Postby evdl » 13 Mar 2013

Thanks TJ.

I thought I knew how to get an array work for me, but I don't know a way of getting a particular value out of the array (for example value of 6 days back).

I use this code for the array (in the strategy code of the 1 minute resolution)

I fetch the daily macd values of another daily chart (other workspace) with ADE.

Code: Select all

Arrays:
// macd ade values
IntrabarPersist macd_day_array[](0), // macd values
IntrabarPersist macd_day_avg_array[](0), // macd trigger line (avg)
IntrabarPersist macd_day_diff_array[](0); // difference between macd value / trigger line

If Currentbar = 1 and Usefile then

Value27 = ADE.OpenMap(Class_MACD, "MACD", Interval_daily);

// Retrieve the data for this symbol and bar interval.
// ADE.GetBarInfo will copy the information from the appropriate DataMap into our InfoMap.

value27 = ADE.GetBarInfo(Class_MACD, "MACD", Interval_daily, ADE.BarID, MACD_Daily_map);

If date > date[1] then begin

// fetch the values from the "_" Map into variables
Macd_day_ade = MapSN.Get(MACD_Daily_map, "MACD Daily");
Macd_avg_day_ade = MapSN.Get(MACD_Daily_map, "MACD Daily Avg");
Macd_diff_day_ade = MapSN.Get(MACD_Daily_map, "MACD Daily Diff");

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

// expand the array by one
Array_setmaxindex(macd_day_array, macd_count);
Array_setmaxindex(macd_day_avg_array, macd_count);
Array_setmaxindex(macd_day_diff_array, macd_count);

// post data to array
Macd_day_array[macd_count] = Macd_day_ade;
Macd_day_avg_array[macd_count] = Macd_avg_day_ade;
Macd_day_diff_array[macd_count] = Macd_diff_day_ade;

end;
How to get the value of 2 days ago? Tried something like this:
macd_2daysback = macd_day_array[2];
but that gives an error about using the wrong index.

So as an workaround I now changed the code in the ADE sender code and send the value[1] and value[2] from the daily chart to the minute chart. But I still like to know how to get the value for example 50 days back out of an array. So I don't have to code value1 to value 50 and wright it all out.

edit: never mind, I found the way to get the value of 50 days back or any other day:
Macd_2daysback = macd_day_array[macd_count] [50];


Return to “MultiCharts”