Disable Auto- Padding in Staticvars?

Hi there,

Quick question. If I want to save an actual RT Trade Price in a Static Array then obviously the trade happens at the last BarIndex. As time moves on and I recall my Trade Price using StaticVarGet for plotting, it will auto-pad my array and I get a Trade Price in every BarIndex after the BarIndex where the trade actually took place. Basically the Auto-Padding causes this and how do I remove that?

AutoPadding

Thanks,

Jorgen

Hi,

I think you should share the code that you are using. Your code may not be right.

I tried doing it this way in real time for the last bar.

bc = BarCount - 1;
a = StaticVarGet( "MyArray" );   // store Array in temp
// update last bar Only
a[bc] = LastValue( C );     // or your trade price 

StaticVarSet( "MyArray", a, True);    // Save the Array again

Other values in the Array at different Timestamp will not get disturbed in the same timeframe.
Very old bars may not get stored as Bar count changes with QuickAFL so you need to check this along with your other code.

Put this bit of code only when your trade is triggered.

Another way i found in the help is to use StaticVarAdd() with keepAll = True and you can still still add the Price value to temp array initialized with 0 and only use index element at last location.
You can try this.

Hi nsm51!

That's interesting information! I will try this during the weekend and I will come back to post my results.

Thank you so much!!!

Jorgen

I wrote a quick test code based on your suggestion. But it didn't work, so I guess I misunderstood something- or?

BC = BarCount - 1;
BuyTest = ParamTrigger( "Test", "BUY" );
BuyArray = 0;

if( BuyTest )
{
TempBuyArray = StaticVarGet( "~BuyArray" );
TempBuyArray[ BC ] = LastValue( Close );
StaticVarSet( "~BuyArray", TempBuyArray, True );
}

BuyArray = Nz( StaticVarGet( "~BuyArray" ) );
Buy = IIf( BuyArray > 0, 1, 0 );
BuyPrice = BuyArray;

PlotShapes( IIf( Buy, shapeUpTriangle, Null ), colorBrightGreen, 1, L, -20 );
PlotShapes( IIf( BuyPrice, shapeHollowSmallCircle, Null ), colorWhite, 1, BuyPrice, 0 );
Plot( C, "Price", colorDefault, styleCandle );

Thanks and Regards,

Jorgen

Looks similar to this one (see green line in animation).

It outputs when DateTime() is equal to static var's DateTime.
Instead of equality check operator between datetimes you may rather use DateTimeDiff(dt1, dt2) == 0.


BTW, please read here

On how to use code tags when inserting code to post.

That's interesting! I will take a look at this.

Thanks!

Jorgen

I just delayed the plot of the trade arrows and then it works fine.

Jorgen