API from C++ DLL is called continuously

I have exported few API from the C++ DLL created using ADK. I can see these APIs in the AFL Formula Editor. I can also call those functions, but what I see is that this function is getting called continuously from the AFL program. Below is the code
i = DLLIndicatorInit();
Plot(i, "i", colorBlue, styleThick);
_SECTION_END(); (edited)
Here I see that the 'i' being plotted is getting incremented. The logic written in the DLL API is to return a number when it is called and increment that number if the API is called again.
But this is undesirable, as I have called the API only once.

Thanks in advance.

It operates exactly as it should. Each chart redraw/refresh means formula execution. So if you place your function in the formula it gets called as it should. If you to call it once, call it YOURSELF once, like this

// use parameter window to call your function at button press
if( ParamTrigger("call it now", "call it now" ) )

The thing is that all kind of coding like all kind of AFL "init" functions that ASSUME that they will be called once is essentially bad coding. If user decides to put such code in multiple windows it may be called multiple times. If you really need any kind of Initialization of your plugin it should be put in proper Init function described in ADK (re-read ADK docs and plugin.h header file). Such function is NOT called from AFL, it is called when DLL is loaded and then it is really called once.

1 Like

Thanks Tomasz. Being a C programmer I was thinking more sequentially where I was trying to work on each Bar details for my algorithm and compute the values. I will consider re-designing my system .