It does not auto click. SelectedValue becomes LastValue at last bar. It is just kept previous value.
Here is one way to prevent your results at last bar:
//https://forum.amibroker.com/t/transferring-staticvar-data-to-array-elements/15489/3
//https://forum.amibroker.com/t/bar-replay-automatically-click-my-guibutton/15630
idCount = 1;
idReset = 2;
idchangeText = 3;
bi = BarIndex();
sbi = SelectedValue(bi);
dt = DateTime();
static_dt = StaticVarGet("static_dt");
count = Nz(StaticVarGet("countStaticVar"));
data = Nz(StaticVarGet("dataStaticVar"));
myArray = 0;
printf("\ndata = " + data);
function CreateButtonGUI()
{
GuiButton( "Count+", idCount, 100, 10, 70, 30, notifyClicked );
GuiButton( "Reset", idReset, 160, 10, 70, 30, notifyClicked );
GuiButton( "Change Count Button", idChangeText, 100, 40, 130, 30, notifyClicked );
}
function Counter()
{
count++;
StaticVarSet("countStaticVar", count);
data = 10;
printf("\ndata = :" + data);
StaticVarSet("dataStaticVar", data);
mydt = StaticVarGet("static_dt");
mydt[sbi] = SelectedValue(dt);
StaticVarSet("static_dt", mydt);
myArray = Nz(StaticVarGet("myArray"));
myArray[sbi] = data;
StaticVarSet("myArray", myArray);
}
function Reset()
{
StaticVarRemove("countStaticVar");
StaticVarRemove("dataStaticVar");
StaticVarRemove("myArray");
StaticVarRemove("static_dt");
}
function ChangeButtonText()
{
GuiSetText("Counter", idCount );
}
function HandleEvents()
{
for( n = 0; id = GuiGetEvent( n, 0 ); n++ )
{
switch ( id )
{
case idCount:
Counter();
break;
case idReset:
Reset();
break;
case idChangeText:
ChangeButtonText();
break;
}
}
}
CreateButtonGUI();
HandleEvents();
printf("\ncount: " + count);
myArray = IIf(dt == static_dt, StaticVarGet("myArray"), 0);
cumMyArray = Cum(myArray);
Plot( myArray, "myArray", colorBrightGreen, styleNoLabel );
Plot( cumMyArray, "cumMyArray", colorWhite, styleNoLabel );
fvbi = Status( "FirstVisibleBar" );
lvb = Min(Barcount-1, Status("lastvisiblebar"));
printf("\ncumMyArray: " + cumMyArray);
Title = "";