LineArray and fixed interval

good morning to all,
I'm having some troubles with LineArray, because the interval it should affect is not "Static" and moves as new data is given.

[this video] shows my issue. I need that the interpolated part goes out of the window at a certain time, but it runs forward as new data is available.

This is the code I've written:

//	I need to edit an interval of a serie (for ex. the Close one)
//	by interpolating its values between an initial and an ending positions

CIP = custInitPos = 50;
CIV = custInitValue = C[custInitPos];
CEP = custEndingPos = 100;
CEV = custEndingValue = C[custEndingPos];
bi = BarIndex();

OD = originaData = C;

newData = IIf((bi < CIP) OR (bi > CEP), C, LineArray(CIP, CIV, CEP, CEV, 0, True)); 

Plot(OD, "original", colorBlack, styleLine);
Plot(newData, "new", colorRed, styleLine);
PlotShapes(shapeSmallCircle, colorBlue,0,newData,0,0); 

The LineArray help states that the parameter "usebarindex" should locks the index:

usebarindex parameter controls if x coordinates are interpreted as current array indexes (from 0..BarCount-1) (when usebarindex = False) or as absolute bar indexes (returned by BarIndex() function) when usebarindex = True. These two may differ if QuickAFL feature is turned on.

This but this doesn't work for my code.

Searching into the forum I've found that the issue is quite similar to this topic:

lineArrays saved to static and drawn from static move when scrolling

but by changing the var to static as suggested I can't managed to make it works:

// my code snipped for static var:
newData = StaticVarGet("myStaticArray", align = False);
newData = IIf((bi < CIP) OR (bi > CEP), C, LineArray(CIP, CIV, CEP, CEV, 0, True)); 
StaticVarSet("myStaticArray", newData);

What I'm doing wrong?
Many thanks for any help

No, you do not need Static vars !!! Also it is wrong.

As written in other post you linked to what you observe is because of QuickAFL.

Instead of just using bar index use specific dates' indexes (by using LookUp function).

bi = BarIndex();
start_date = _DT("2021-09-01");// insert start date
end_date = _DT("2021-11-01");// insert end date
CIP = custInitPos = Lookup(bi, start_date);
CIV = custInitValue = Lookup(C, start_date);
CEP = custEndingPos = Lookup(bi, end_date, -1);
CEV = custEndingValue = Lookup(C, end_date, -1);
1 Like

Thank you Fxshrat, understood. So I have to use explicit dates and not refer to their bar index due to the Quick AFL logic.
I'll work on this.
Many thanks for the insight and the code's corrections
Marco

P.S.: for the ones that could be interested, seeing that this behavior is related to QuickAFL then according to the quickAFL guide it could be disabled using the following command:

SetBarsRequired(sbrAll, sbrAll);

this also solves my issue.
(obviously running time should not a big issue if you adopt this method)

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