Hi:
I hope someone can help me with this, it is driving me nuts!
I am using 3 timeframes, 3 minute, 6 minute and 9 minute charts within the same window. If I apply any indicator to each of the 3 timeframes separately and display their output in the same subgraph everything works correctly.
However, I need to be able to calculate the values of the indicator on the close of each time frame from within the same indicator / strategy to make further decisions. I am using barstatus = 2 to check for the bar closing events of data1 (3 min), data2 (6 min) and data3 (9 min). When I do this I get completely different results for the indicator in the 3 time frames. The time frame that the indicator is applied to in the study is correct, but the other two always are not correct. ie if I apply it to data1 that is correct, but then data2 and data3 are not correct, and if I apply it to data2, that is correct but then data1 and data3 are not correct.
The code below illustrates what I am currently doing with the indicator / strategy being applied to data1.
Input: Len(20);
vars: price1(0),
price2(0),
price3(0),
RSI1(0),
RSI2(0),
RSI3(3);
If barstatus(1) = 2 then
begin
price1 = Close of data1;
RSI1 = RSI(Price1, Len);
end;
If barstatus(2) = 2 then
begin
price2 = Close of data2;
RSI2 = RSI(Price2, Len);
end;
If barstatus(3) = 2 then
begin
price3 = Close of data3;
RSI3 = RSI(Price3, Len);
end;
Plot1(RSI1, "RSI1");
Plot2(RSI2, "RSI2");
Plot3(RSI3, "RSI3");
The values of each of the RSI's using data1, data2 and data3 from within the same indicator is always different from the values of the RSI's, (or any other study, this is just an example) when they are applied to separate data streams explicitly.
Am I doing something wrong here? All help is greatly appreciated.
Close data of 3 timeframes using barstatus = 2 problem
- Anastassia
- Posts: 179
- Joined: 18 Jan 2010
- Been thanked: 4 times
Re: Close data of 3 timeframes using barstatus = 2 problem
Hi chisound,
Please modify your code as follows and let me know if it helps:
Thank you
Please modify your code as follows and let me know if it helps:
Code: Select all
Input: Len(20);
vars: price1(0),
price2(0),
price3(0),
RSI1(0),
RSI2(0),
RSI3(3);
If barstatus(1) = 2 then
begin
price1 = Close of data1;
RSI1 = RSI(Price1, Len);
end;
If barstatus(2) = 2 then
begin
price2 = Close of data2;
RSI2 = RSI(Price2, Len) of data2;
end;
If barstatus(3) = 2 then
begin
price3 = Close of data3;
RSI3 = RSI(Price3, Len) of data3;
end;
Plot1(RSI1, "RSI1");
Plot2(RSI2, "RSI2");
Plot3(RSI3, "RSI3");
Re: Close data of 3 timeframes using barstatus = 2 problem
Hi:
Thanks for the suggestion, however, I get the same results. Interestingly enough when I run the following code I get repeat values for price3 as Multicharts seems to add the current value of data3 to the variable price3 at the lowest resolution timeframe, ie data1. If Multicharts does this correctly it should only add a new closing value to the variable price3 on the close of data3 only, not on the close of the timeframe that the chart or study is applied to, in this case 3 minutes. That happens is that there are 3 entries for every 3 minutes (data1 resolution) of the data3 bar (9 minutes). I therefore have 3 data points that are the same for every 1 data point in price3 not 1 as there should be which obviously causes any study or strategy based on this to be incorrect. Any other suggestions? Is this a bug?
vars: price1(0),
price2(0),
price3(0),
If barstatus(1) = 2 then price1 = Close of data1;
If barstatus(2) = 2 then price2 = Close of data2;
If barstatus(3) = 2 then price3 = Close of data3;
Print(File("C:\temp\timestest.txt"), price3 , price[1], price[2], price[3]);
Here is what the output was from the above print statement this afternoon from the Dec10 E-MiniS&P500 future. data1 is 3 min, data2 is 6 min and data3 is 9 min charts.
1191.75 1192.5 1192.5 1192.5 1192.25
1191.75 1191.75 1192.5 1192.5 1192.5
1191.75 1191.75 1191.75 1192.5 1192.5
1191.25 1191.75 1191.75 1191.75 1192.5
1191.25 1191.25 1191.75 1191.75 1191.75
1191.25 1191.25 1191.25 1191.75 1191.75
1191.25 1191.25 1191.25 1191.25 1191.75
1191.25 1191.25 1191.25 1191.25 1191.25
Thanks for any help with this,
Chris
Thanks for the suggestion, however, I get the same results. Interestingly enough when I run the following code I get repeat values for price3 as Multicharts seems to add the current value of data3 to the variable price3 at the lowest resolution timeframe, ie data1. If Multicharts does this correctly it should only add a new closing value to the variable price3 on the close of data3 only, not on the close of the timeframe that the chart or study is applied to, in this case 3 minutes. That happens is that there are 3 entries for every 3 minutes (data1 resolution) of the data3 bar (9 minutes). I therefore have 3 data points that are the same for every 1 data point in price3 not 1 as there should be which obviously causes any study or strategy based on this to be incorrect. Any other suggestions? Is this a bug?
vars: price1(0),
price2(0),
price3(0),
If barstatus(1) = 2 then price1 = Close of data1;
If barstatus(2) = 2 then price2 = Close of data2;
If barstatus(3) = 2 then price3 = Close of data3;
Print(File("C:\temp\timestest.txt"), price3 , price[1], price[2], price[3]);
Here is what the output was from the above print statement this afternoon from the Dec10 E-MiniS&P500 future. data1 is 3 min, data2 is 6 min and data3 is 9 min charts.
1191.75 1192.5 1192.5 1192.5 1192.25
1191.75 1191.75 1192.5 1192.5 1192.5
1191.75 1191.75 1191.75 1192.5 1192.5
1191.25 1191.75 1191.75 1191.75 1192.5
1191.25 1191.25 1191.75 1191.75 1191.75
1191.25 1191.25 1191.25 1191.75 1191.75
1191.25 1191.25 1191.25 1191.25 1191.75
1191.25 1191.25 1191.25 1191.25 1191.25
Thanks for any help with this,
Chris
Re: Close data of 3 timeframes using barstatus = 2 problem
Apologies the last print statement in my reply above should be:
Print(File("C:\temp\testctrank.txt"), price3, price3[1], price3[2],price3[3],price3[4]);
The output from this statement that I posed above is correct.
Sorry,
Chris
Print(File("C:\temp\testctrank.txt"), price3, price3[1], price3[2],price3[3],price3[4]);
The output from this statement that I posed above is correct.
Sorry,
Chris
Re: Close data of 3 timeframes using barstatus = 2 problem
Hi,
Could You try this way:
Input: Len(20);
vars: price1(0,data1),
price2(0,data2),
price3(0,data3),
RSI1(0,data1),
RSI2(0,data2),
RSI3(0,data3);
that should help.
Could You try this way:
Input: Len(20);
vars: price1(0,data1),
price2(0,data2),
price3(0,data3),
RSI1(0,data1),
RSI2(0,data2),
RSI3(0,data3);
that should help.
-
- Posts: 82
- Joined: 20 Jun 2009
- Been thanked: 1 time
Re: Close data of 3 timeframes using barstatus = 2 problem
Rommi is right. You need to reference each variable to the data it refers to. By default every variable refers to data1 if not referenced differently.
Also I recommend referencing functions, e.g. RSI2 = RSI(close of data2, Len) of data2;
If your code works correct you do not need to use
If barstatus(2) = 2 then
begin
...
end;
In general: you should consider different data (data1, data2, data3, ...) as independent arrays. When you make calculations based on this array you need to reference each variable to the array. By the way it helps a lot if you use functions instead of writing the calcuations directly to your indicator/signal.
I hope this helps.
Also I recommend referencing functions, e.g. RSI2 = RSI(close of data2, Len) of data2;
If your code works correct you do not need to use
If barstatus(2) = 2 then
begin
...
end;
In general: you should consider different data (data1, data2, data3, ...) as independent arrays. When you make calculations based on this array you need to reference each variable to the array. By the way it helps a lot if you use functions instead of writing the calcuations directly to your indicator/signal.
I hope this helps.
Re: Close data of 3 timeframes using barstatus = 2 problem
Hi Rommi and Smashthepound, that worked a treat, makes perfect sense. Thanks guys!