DLL Coding - using Thread Local Storage

 

I am writing a DLL where I need to keep information between calls from MT4. As a result, I allocated Thread Local Storage (TLS) in DLL Main. In tester mode, the DLL functions properly. The TLS retains the information stored between calls. In real trading mode, however, the DLL can find the TLS (same TLS address between calls) but all of the saved information is gone (binary 0). Is there something different about how the Strategy Tester handles DLL calls and the normal trade platform?

While investigating this problem using the Visual Studio debugger, I see that MT4 (not Strategy Tester) does a Thread Attach and Detach at every tick. Why doesn't Strategy Tester exhibit the same behavior? How and why does it keep the Thread alive between ticks? It seems that the normal Trading Platform strategy of Attach/Detach is destroying my access to the TLS.

FYI, the DLL Thread Attach and Detach occurs at every tick even if the MT4 Expert does not call the DLL. Seems like unnecessary overhead.

 

Tick incomes -> Thread begins -> Start function launched -> Thread ends

If tick incomes and thread lives (start function does not complete and process previous tick) then incoming tick missed

 

"Tick incomes -> Thread begins -> Start function launched -> Thread ends"

Let's say you're working on 15 minutes time frame then the candle that it is forming incomes only at the end of the 15 minutes or it incomes every x seconds ? In this case hw much is x?

Thanks

 

The Start() function is invoked at every tick. It is not x seconds. It may be several times per second or less.