Timeframe has different values

Hi there guys.

I have an issue with this trailstop. When I have the time frame on 1hr (which is what the timeframe is set to). The value of the trail stop is 14.3121. But when I change to say a 40min chart trail stop value is 14.2956. Could anyone perhaps explain what I'm doing wrong here ? Thanks very much!

40min
60min

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
function vstop_func(trBull,trBear)
{
	trailArray[0]=C[0];
	for(i=1;i<BarCount;i++)
	{
		prev=trailArray[i-1];
 
		if(C[i]>prev AND C[i-1]>prev)
		{
			trailArray[i]=Max(prev,C[i]-trBull[i]);
		}
		else if(C[i]<prev AND C[i-1]< prev)
		{
			trailArray[i]=Min(prev,C[i]+trBear[i]);
		}
		else if (C[i]>prev)
		{
			trailArray[i]=C[i]-trBull[i];
		}
		else
		{
			trailArray[i]=C[i]+trBear[i];	
		}
	}
	return trailArray;
}

////////////////////////Short Term Trail/////////////////////////
ST_TRAIL=Param("ST Trail (hrs)",1,1,10,1)*60;
ST_TRAIL_1=in1Minute*ST_TRAIL;
TimeFrameSet(ST_TRAIL_1);
ST_Periods=Param("ST_periods",100,1,500,1);
ST_dev=Param("ST_deviation",2.5,0.05,20,0.05);
ST_trBull=ST_dev*ATR(ST_Periods);
ST_trBear=ST_dev*ATR(ST_Periods);
ST_trailArray = vstop_func(ST_trBull,ST_trBear);
ST_ts=IIf(ST_trailArray>C,ST_trailArray,Null);
ST_tl=IIf(ST_trailArray<C,ST_trailArray,Null);
TimeFrameRestore();
ST_ts=TimeFrameExpand(ST_ts,ST_TRAIL_1,expandFirst);
ST_tl=TimeFrameExpand(ST_tl,ST_TRAIL_1,expandFirst);

if ( ParamToggle( "1hr Trail Stop", "OFF|ON", 1 ) )
{
Plot(ST_ts , "", colorYellow,styleDashed,0,0,0,0,0 );
Plot(ST_tl , "", colorYellow,styleDashed,0,0,0,0,0 );
}

60 minute TF is not a (integer) multiple of 40 minute time frame.
On the other hand 60 minute is 2 times 30 minute and 4 times 15 minute and 12 times 5 minute.

But 60 divided by 40 is 1.5 times so result has fractional part.
That's the reason for difference.


As for looping and mult time frame see here in addition

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.