Exploring a simple script(2)
OK a few apologies are in order. When the script was posted yesterday, there were a few errors that found their way into the post. So today at the end of this post you will find a link to down load the file. It will be unlocked and fully accessible for changes.
Today I want to talk about the use of Global variables versus Local variables. This script uses 5 global variable to pass along information. The difference in the two variables is how long the information is held by the variable anf what has access to that information.
Local: Declares a local variable in the chart. These variables remain accessible only within the particular script. These variables can be assigned an initial value. This value is held only as long as the specified condition is true.
Global: Declares a global variable in the chart. These variables remain accessible from every IntelliScript that are attached to the same Data Series. These variables can be assigned an initial value. The value can be held as long as you wish.
For today’s discussion, I am going to explain the first two global variables, because the concept behind them is detailed enough to fill this post.
global int ii
global int hh
When we initially wanted to set up the script we needed a way to count the process that we were going through. This counting needed to be done for several reasons, none of which are used in the final iteration of the script but we left in so we could test other changes as well.
The original reason was to add contract names. Remember that you cannot have more than 1 trade open in one direction at a time. That is unless they have different names. Counting was a way to add a different name. After each addbuyentry/addsellentry you will see the following lines of code
hh=hh+1
ii=ii+1
This steps the value up 1 for every time the group is “true” and a new signal is created. We could then add:
Contract = “+ii+” or Contract = “+hh+” behind the addbuyentry or addsellentry and new positions in the same direction would be created with a contract name of a number. Now lest you think it’s all that easy, remember you would also have to exit each of those contracts too. For this reason we abandoned this strategy in favor of another but left it there in case we wanted it in the future.
0 اضافة رد:
إرسال تعليق