Very important
Very important
07 Sep 2019, 01:07
Many entities, such as sockets, require execution closing methods, but indicators do not have OnStop(); It is very important to add this logic.
Replies
firemyst
22 Sep 2019, 15:42
RE:
trader.calgo said:
Many entities, such as sockets, require execution closing methods, but indicators do not have OnStop(); It is very important to add this logic.
Have you tried surrounding your socket code with the C# using statement?
For example:
using (var socket = new Socket(/*...*/)) { // operations socket.Shutdown(SocketShutdown.Both); socket.Close(); }
The above code is expanded into the following by the compiler at compile time:
{ Socket socket = new Socket(/*...*/); try { // operations socket.Shutdown(SocketShutdown.Both); socket.Close(); } finally { if (socket != null) ((IDisposable)socket).Dispose(); } }
It will suck with each call to the calculate method as you'll have to open/close the socket each time, but at least it gives you a temporary work around if you need it.
Past values of the indicator won't be too bad; it's the latest calculate index that'll cause the problem. So other options are:
1) only open the socket if the parameter "index" for calculate has changed from the previous value
2) if you need the socket open more frequently for the current index, only open it every 5, 8, 13, or whatever calls to calculate on the current index. For example:
calculate (int index) { //_calculateCount is a global variable if ( _calculateCount % 5 == 0) { using (Socket s = new Socket....) {} } _calculateCount += 1; }
@firemyst
PanagiotisCharalampous
09 Sep 2019, 10:35
Hi trader.calgo,
Please use the Suggestions section for such siggestions.
Best Regards,
Panagiotis
@PanagiotisCharalampous