Using C# Events instead of concurrentDictionary (Global Variables)  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
johnromeronc
Posts: 53
Joined: 18 Feb 2011
Has thanked: 11 times
Been thanked: 13 times

Using C# Events instead of concurrentDictionary (Global Variables)  [SOLVED]

Postby johnromeronc » 17 Sep 2019

Thoughts ... Comments ... Advise ....

As I think about implementing a sharing mechanism for plots and other values between my indicators and signals I looked at a number of possible solutions, that meet what I think are my needs, I have read about the following areas.
1 - Concurrent Dictionary - Global Variables - native c#
2 - Singleton -
3 - static declaration and public naming of things to share -- plots, variables etc.
4 - Using Events, which are native to c#.

I am leaning to using events.
- # of events to create 3 time frames x 10 = 30. I would want it to scale, lets say I go wild in tracking everything under the sun and it goes to 500
events.
- The creator / sender of the event would be the indicator / strategy that produced it.
(Don't know what it would take to expand this to portfolio trader
- Some of my 'things', - very, very few - will be on the tick level
- Most will update / send event on bar completion, which is 2 - 4 minutes for most, 5-15 minutes for others
- This will eliminate the need for continuous checking for new value
- Receivers (strategies, signals, other indicators, during start up will set place holders for event data to a default value to start.
- Larger overall strategy will create buy / sell signals in real time (intrabar) to broker to be executed. (moving trailing stops, etc)
- No need for locking mechanism, as I will share the value(s) as part of the event message structure.
- Seems like a performance advantage using Events, but a memory hit, unless I use dynamic events.
I'll probably start with static events and see how much memory I am eating up as I add more things to be watched.

John

RonS
Posts: 21
Joined: 16 Sep 2018
Has thanked: 7 times
Been thanked: 3 times

Re: Using C# Events instead of concurrentDictionary (Global Variables)

Postby RonS » 22 Sep 2019

I set up Global Variables using the Forum concurrentDictionary code and it worked after everything was initialized. Had some issues with the strategy running first and then my indicators, which were supplying the Global Variables. Finally just gave up and am using BarsOfData(n). Backtesting and Optimization work great.

johnromeronc
Posts: 53
Joined: 18 Feb 2011
Has thanked: 11 times
Been thanked: 13 times

Re: Using C# Events instead of concurrentDictionary (Global Variables)

Postby johnromeronc » 22 Sep 2019

RonS,

First thanks for the time to reply. I am having a similar issue of start up timing, and reported it. They hope to have a fix soon. (Early 14 builds?) My situation is an indicator that uses the Volume Profile data. The VP has not finished loading / displaying and the indicator is trying to access it. It then gets a null, and I need to go into the menu and modify the indicator status to 'On' again and all is well. I might end up having a similar situation using Events with the event subscribers starting before the events are established in a different piece of code.

John


Return to “MultiCharts .NET”