Favorite Futures: Gameplay Klownbine® Trading of Globex
Posts: 1,276 since Jul 2009
Thanks: 1,227 given,
Practical Application of Global Variables - Request for Comments
Let's postulate a workspace with ~10, ~20 charts, or N charts of one instrument that I want to pretend I am trading, in the simulator, of course! Let's call the charts that I use for my "trading" decisions the "client" charts.
Suppose that for some reason I want to be able to put the daily pivots and previous N days VWAPS, Highs, Lows, PoC's etc on all of those charts.
It would NOT be necessary to add pivot, VWAP and profile level indicators to all of these "client" charts. There would be one chart with an indicator that calculates these values and pushes them to another indicator that stores the values in a static DataTable. So the calculations to determine the values only need to be done on ONE chart.
Now that these values are stored in a static DataTable, my understanding is that they would then be accessible to very simple read only indicators on the "client" charts. These indicators would not need to do any calculations and, since the DataTable is static, would not be reliant upon instances of external indicators - they would just grab the values from the static DataTable.
In this particular case all of the static data remain unchanged during the course of the session, so the size of the DataTable would be very small. But even if we extend the concept to include in the table something like the CURRENT DAY VWAP, and the width of its various types of deviation bands, at [for example] one minute intervals, the size of the DataTable would remain manageable.
And, for non-historical operation, the pushing indicators could update the values of static variables, so that the very latest real time values could always be available. So the DataTable would be used only to backfill the "client" charts.
"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.” Prof. Albert Bartlett
The following 3 users say Thank You to Zondor for this post:
sorry about the late reply, I only just saw your post.
I use my global variables exactly the way you outline it. As you probably saw I have written the receiving indicator in such a way that it caches the latest value. So in my humble opinion there is little overhead for pushing out real time values to the lower time frame charts. You just need to let the sending indicator update real time.
I have written a new indicator that picks up the global variable values. If I recall correctly it can handle up to 8 different global variables. That makes it a bit easier to handle. It also has a parameter for showing the name of the GV on the chart. It then really helps to have a good naming standard for the global variable names, like for instance <instrument><bar size><indicator><key indicator setting (for instance length)>. And of course it makes sense to let the GV plot identically to the original indicator so that you visually recognize the plot.
The following 4 users say Thank You to Geir for this post:
in case your question relates to my initial post there is actually a small omission in my explanation. You need to reference System.Data.dll by right clicking in the NT window for coding and choose References. Then you need to figure out where to find System.Data.dll. Mine is under C:\Windows\Microsoft.NET\Framework64\v2.0.50727\System.Data.dll
The following user says Thank You to Geir for this post:
First I would like to thank all that contributed to the code and ideas in this section, this is exactly what I was looking for in order to solve a problem that I was having with a few indicators I am in the process of developing. I agree that the sharing of global variables in a multiprocessor environment requires a locking mechanism.
So, if I understood your instructions all of your code (with the necessary modifications) needed to be placed into the partial indicator containing the methods as provided by @Geir. Note I tested the unmodified version first and everything worked fine. There are a number of errors that are displayed by the receiver when the chart first comes up (see SS). However, they do not appear when refreshing the chart (F5). They also do not appear if both indicators are deleted, applied and then re-added.
Also, the second problem is that the output of the indicators do not match, sometimes. Although I did not do extensive testing of the unmodified version, after an F5 refresh they plots always matched. The only difference between the unmodified and the modified version is the addition of the locking code. What I also noticed is that they go back into sync after refreshing the historical data even through they did from an F5 refresh, however they begin to go out of sync after the refresh.
I may need to retest the original code again but before I remove the locking to do so I wanted to make sure I understood your instructions correctly and maybe clear up the error messages when it first starts up.
Thank you for your assistance.
Last edited by Cheech; January 29th, 2015 at 08:37 PM.
It looks like your GetGlobalVariable() is getting called before the gvTable and it's columns are initialized. In GetGlobalVariable() you need to make sure your gvTable.Columns.Count > 0 before doing the gvTable.Select().
The clues were in the error message
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).
Favorite Futures: Currency Futures, my Harley Davidson
Posts: 90 since Jun 2012
Thanks: 41 given,
OK thank you, I will do that, give it a shot, and report the results.
That said, the second problem is that after the historical data is plotted (correctly) they go out of sync. I didn't modify any of the original code when I added in the locks and at this point not sure if the original code worked. Should the locaks have prevented this from happening or is there something missing in the original code?