Retrieve Values Only if Interval() or Name() has changed

Dear Sirs,

I need to Retrieve some Array Values from an ODBC Data source for plotting on chart.
For the sake of conserving resources I wish to Retrieve/Refresh Values Only if Interval() or Name() has changed.

For that purpose I am using the following code:

if( Name() != VarGetText( "SYMBOL_XYZ" ) OR Interval(2) != VarGetText( "Interval_XYZ" ) )
{
    VarSetText( "SYMBOL_XYZ", Name() );
    VarSetText( "Interval_XYZ", Interval(2) );
    VarSetText( "mNOW" , Now( 2 ) );
    // Retrieve Values from ODBC Source
}

Title = VarGetText( "mNOW") ;
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

In this sample code, I expect the Title to update only on change in Interval() or Name() -
It should not change on chart scrolls, Zooms or simple clicks etc.

However, the title is changing even on Simple clicks on chart.
{Incidentally the AFL is going to be used on a Layout with Multiple charts, with multiple Intervals (Sharing same chart_ID ) }

It will be very nice if the Seniors please guide about what should be corrected in the AFL.

With Thanks and Regards

Sanjiv Bansal

First you should use static variables (staticvarset) because only static variables keep vales between executions

1 Like

Dear Sir,

Thank you very much for your guidance.
My initial code was also using Static Variables,
However, the StaticVariables that I was creating were composites of Name() and Interval().
And these Composite StaticVariables were not compatible with MultiChart Multi_Interval Layouts.

Now, I have removed Interval() from my Text StaticVariables and things seem to be progressing in desired direction.

Thank you again for your guidance and Nice Software.

With Regards

Sanjiv Bansal