I have a one-second IQFeed DB, and am using multiple timeframes in my charts, to pull some EMAs from higher timeframes for plotting. I am probably doing something wrong, or missed an important sentence in the docs, or have an incorrect setting.
In the charts below, the blue and red lines are EMAs in the timeframe of that chart, while the light blue and pink dashed lines are EMAs from higher timeframes (light blue is one TF higher and pink is two TFs higher). When I say one or two TFs higher, I have a function that returns the number of seconds in the higher TF according to this way of looking at TFs.
I should be able to verify that the code is pulling the correct values just by looking at the prices labels, however I can see that incorrect values are being returned. For example, in the 5-second chart (top left):
- the light blue number 4534.39 (TF1EMA21) should agree with the 15-second chart's blue number of 4534.33 (EMA21)
- the pink number 4534.38 (TF2EMA5) should agree with the 1-minute chart's red number of 4534.17 (EMA5)
Another issue is that the 4-hour chart does not have any value for the pink number (TF2EMA5).
Here is the chart code:
// Higher TF test
function NextTF( Seconds )
{
// Returns the interval one timeframe higher than the one passed to the function, in seconds.
switch( Seconds )
{
case 1: Output = 5; break;
case 5: Output = 15; break;
case 15: Output = 60; break;
case 60: Output = 300; break;
case 300: Output = 900; break;
case 900: Output = 3600; break;
case 3600: Output = 14400; break;
case 14400: Output = 86400; break;
case inDaily: Output = inWeekly; break;
case inWeekly: Output = inMonthly; break;
case inMonthly: Output = inQuarterly; break;
case inQuarterly: Output = inYearly; break;
default: Output = Null; break;
}
return Output;
}
TF0 = Interval(0);
TF1 = NextTF( TF0 );
TF2 = NextTF( TF1 );
EMA5 = EMA( C, 5 );
EMA21 = EMA( C, 21 );
if( TF1 > TF0 )
{
TimeFrameSet( TF1 );
TF1EMA21 = EMA( C, 21 );
TimeFrameRestore();
TF1EMA21 = TimeFrameExpand( TF1EMA21, TF1 );
}
else TF1EMA21 = Null;
if( TF2 > TF0 )
{
TimeFrameSet( TF2 );
TF2EMA5 = EMA( C, 5 );
TimeFrameRestore();
TF2EMA5 = TimeFrameExpand( TF2EMA5, TF2 );
}
else TF2EMA5 = Null;
// CHARTING
SetChartOptions( 2, chartShowArrows | chartShowDates | chartWrapTitle );
LowerStyle = styleLine | styleThick;
HigherStyle = styleStaircase | styleDashed | styleThick;
//Plot( C, "Close", colorDefault, styleCandle | styleNoTitle, Null, Null, Null, 0 );
Plot( EMA5, "EMA5", colorRed, LowerStyle, Null, Null, Null, 1 );
Plot( EMA21, "EMA21", colorBlue, LowerStyle, Null, Null, Null, 1 );
Plot( TF1EMA21, "TF1EMA21", ColorBlend( colorBlue, colorWhite, 0.5 ), HigherStyle, Null, Null, Null, 1 );
Plot( TF2EMA5, "TF2EMA5", ColorBlend( colorRed, colorWhite, 0.5 ), HigherStyle, Null, Null, Null, 1 );
And here are some relevant settings:
I must have a blind spot here since I haven't found my error, and I appreciate any help you all can provide.
- Peter