Hi everyone. I would appreciate some clarity on this specific problem with timeframe expand. In this link https://www.amibroker.com/members/library/detail.php?id=1411&hilite=TimeFrameExpand
The trailing stop set to 1440 min (which is daily, so inDaily) is correct in the daily timeframe, but when switched to a 4 hr chart, it should expand the daily values(trailstop) to the 4hr chart. Timeframeset, Timeframeexpand and timeframerestore are all correct. Here is and example and the code snippet from the link above.
I have read this link Multiple Time Frame Support
and still everything seems to be correct, so there is something I'm missing! I have my intervals set correctly.
Here is the code snippet from the AFL library, from @empottasch
So the question is why is the Daily trailing stop not the exact same on a lower timeframe ?
_SECTION_BEGIN("Formula 182");
// Amibroker AFL code by Edward Pottasch, Oct 2012
// alternative ZIG type function based on the ATR and VSTOP functions
// added multiple timeframes. Maximum timeframe set to 1440 minutes
x=xx=BarIndex();
//tc=ParamList("Display Mode","ZIG|VSTOP|ZIG&VSTOP",0);
//disp=ParamToggle("Display labels","Off|On",1);
tf=Param("Time Frame (min)",5,1,1440,1);tfrm=in1Minute*tf;
perBull=Param("perBull",20,1,150,1);
perBear=Param("perBear",20,1,150,1);
multBull=Param("multBull",2,0.05,4,0.05);
multBear=Param("multBear",2,0.05,4,0.05);
//perc=Param("Percentage Range (S/R lines)",6,0.05,15,0.01);
//npiv=Param("N Pivots Used (S/R lines)",3,1,250,1);
//disp2=ParamToggle("Display S/R levels","Off|On",0);
TimeFrameSet(tfrm);
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;
}
trBull=multBull*ATR(perBull);
trBear=multBear*ATR(perBear);
trailArray = vstop_func(trBull,trBear);
ts=IIf(trailArray>C,trailArray,Null);
tl=IIf(trailArray<C,trailArray,Null);
TimeFrameRestore();
ts=TimeFrameExpand(ts,tfrm,expandFirst);
tl=TimeFrameExpand(tl,tfrm,expandFirst);
Plot(ts,"\ntrailShort",colorRed,styleLine,0,0,0,1,1);
//Plot(llls,"",colorRed,styleDashed,0,0,0,1,1);
Plot(tl,"\ntrailLong",colorGreen,styleLine,0,0,0,1,1);
//Plot(hhhs,"",colorGreen,styleDashed,0,0,0,1,1);
GraphXSpace=5;
SetChartOptions(0, chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle Up Color",
colorBrightGreen),IIf(C<=O,ParamColor("Candle Down Color",
colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Shadow Up Color",
colorBrightGreen),IIf(C<=O,ParamColor("Shadow Color",
colorRed),colorLightGrey)),64,0,0,0,0,1);

