GFX Drawings / StaticVars showing up every other restart

Hello!

I don't know if the subject describes my issue accurately so please change if need be.

I am coming here for help... not sure I have the knowhow to understand exactly what is going on with my formula.

I have modified a formula I found on this forum (unsure where at this point) to start drawing lines when I have the Right Shift key down... and it does it perfectly.

Where I have an issue is that the drawings don't seem to load with every start... for example I draw stuff, close amibroker, restart it... they are not there. Close Amibroker again and restart and then they show back up. Could anyone give me pointers as to what I should do to understand what is going on here?

Images below because video is too big:

Image 1 shows 10 drawings...

Then I close amibroker and restart... nothing shows up... see below.

Then I close again and restart... drawings shows up again

Not sure if I am allowed to post outside links here but here goes just in case a link to the full video

Formula here:

_SECTION_BEGIN("Drawings");

	EnableTextOutput(False);

	GfxSetZOrder(0);
	GfxSetCoordsMode(1);
	
	X=GetCursorXPosition(0);
	Y=GetCursorYPosition(0);

	ChartID=Name()+Interval()+GetChartID();
	
	DrCounter=StaticVarGet("DrawCount"+ChartID);
	printf("\nDrCounter="+DrCounter);

	GetClick=GetCursorMouseButtons();
	
	Click8=GetClick&8;
	Click9=GetClick&9;
	Click4=GetClick&4;

	if (GetAsyncKeyState(161)<0) { 

		if (Click8) {
			DrCounter=Nz(StaticVarGet("DrawCount"+ChartID));
			StaticVarSet("DrawX1"+ChartID+(DrCounter+1),X,1);
			StaticVarSet("DrawY1"+ChartID+(DrCounter+1),Y,1);
			StaticVarSet("DrawCount"+ChartID,DrCounter+1,1);
		}
		if (Click9) {
			DrCounter=Nz(StaticVarGet("DrawCount"+ChartID));
			StaticVarSet("DrawX2"+ChartID+DrCounter,X,1);
			StaticVarSet("DrawY2"+ChartID+DrCounter,Y,1);
		}	
		if (Click4) {
			DrCounter=Nz(StaticVarGet("DrawCount"+ChartID));
			StaticVarRemove("DrawX1"+ChartID+DrCounter);
			StaticVarRemove("DrawY1"+ChartID+DrCounter);
			StaticVarRemove("DrawX2"+ChartID+DrCounter);
			StaticVarRemove("DrawY2"+ChartID+DrCounter);
			StaticVarSet("DrawCount"+ChartID,Max(DrCounter-1,0),1);
		}
		RequestMouseMoveRefresh();
		
	}

	Index=BarIndex();	

	GfxSetBkMode(1);
	GfxSetTextColor(colorRed);
	GfxSelectPen(colorRed,2);

	if (DrCounter>0) {
		for (i=1;i<=DrCounter;i++) {

			DrawX1=Lookup(Index,StaticVarGet("DrawX1"+ChartID+i));
			DrawX2=Lookup(Index,StaticVarGet("DrawX2"+ChartID+i));
			
			DrawY1=StaticVarGet("DrawY1"+ChartID+i);	
			DrawY2=StaticVarGet("DrawY2"+ChartID+i);
			
			printf("\nY1-"+i+"_"+NumToStr(DrawY1,1.2,False));
			printf("\nY2-"+i+"_"+NumToStr(DrawY2,1.2,False));
			
			if (DrawX1!=0 && DrawX2!=0) {
				GfxMoveTo(DrawX1,DrawY1);
				GfxLineTo(DrawX2,DrawY2);
			}
		}
	}
		
	RequestTimedRefresh(1);

_SECTION_END();


Hello

You must say what Amibroker version you are running?

I test you code with AB ver 6.28, and I restart many times with no problem.

Hi @PanoS

Thank you for responding.

I honestly don't have any clue as to what might be causing this and no idea where to start looking.

I am currently using:
Standard Edition
32 Bits
Version 6.30

Without ALL information it is guessing game. Please follow this advice: How to ask a good question

My guess would be that some 3rd party tool that you have installed is messing up with your system (antivirus, GOOGLE DRIVE???).
It is recommended NOT to store AmiBroker databases on "Google Drive" or any other "cloud", because all those "cloud" softwares are not written properly to handle databases and interfere with normal operation of file system.
The behavior that you described looks like third party tool ("cloud") is serving you CACHED (older) version of the file and does not keep up with updates.

I currently have my Formulas folder synced with Google Drive... not the database itself.

Would that cause this behavior in your opinion?

With a problem like this @shavedlemon, it is probably best to start stripping things out of the code and see if that reveals what is causing the problem. Try a local file store first and if things don't improve then trim down the code so there is only one key click, one line drawn etc. Then you can start adding things back in slowly if the problem goes away.

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