Announcement

Collapse
No announcement yet.

How to "set" study parms from the EFS code?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to "set" study parms from the EFS code?

    I am looking for the way to "setValue" for the Study Parameters from within the EFS code. Or may be some other way to store the values.

    I use mouse double click to set values to the study variables (like here is the potential "target", here is the "stop loss" - show me what comes out).

    My problem is that if I change the interval of the chart, my variable values are "reset".

    I have also programmed an option to enter the values thru the Edit Parms Window - and in this case they are preserved after the interval change! But it is very cumbersome and unwieldy this way so I really have to find the way to use the mouse clicks.

    One way to solve the problem of "reset" would be to get values from the mouse and store them in the study parms. Can it be done. I couldn't find any "setValue" method for the params.
    Do you know the correct method or any workaround?

    Thanks in advance for any help offered,
    Leon

    P.S. setGlobalValue is no good since I want to have this study active in several windows at the same time.

  • #2
    squark,

    I would suggest creating a file or using setGlobalValue. What you would do in either case would be to add the symbol to the file or global variable name. For example, here is what I do when I setGlobalValue:
    PHP Code:
    setGlobalValue ((nSymbol+"name"),  value); 
    where I have a function
    PHP Code:
    function vName(){
     var 
    re1 = / /gi;
     var 
    re2 = /#/gi;
     
    var re3 = /=/gi;
     var 
    tmpa getSymbol();
     
    tmpa=tmpa.replace(re1"");
     
    tmpa=tmpa.replace(re2"");
     
    tmpa=tmpa.replace(re3"");
     return 
    tmpa;

    I define nSymbol as a global outside main() and preMain(). Within main(), I then set nSymbol as follows:

    PHP Code:
    if (getBarState() == BARSTATE_ALLBARS) {//true once during initial load and subsequent reload
     
    nSymbol=vName();
     var 
    tmp getGlobalValue ((nSymbol+"name"));
     if (
    tmp != null)value tmp;

    After I get nSymbol, then I check to see if there is a global out there with a value and use that. If you want the values to stick around between sessions then you would have to go the way of setting up a file associated with a given symbol.

    If you want to figure out how to use mouse clicks, this efs has a set of mouse functions which may be adapted for your use.

    I hope this is helpful.

    Comment


    • #3
      This does it

      Thanks, Steve
      your advice is "right on target"

      It even accomplishes more than I wanted to - now if I set study in one window, then, if I open another window with the same symbol - the study is already set there.

      Thanks a lot,
      Leon

      P.S. I just hope that there is no serious limitation on the number of the "global" variables - otherwise I might hit the limit - I will be using somewhere around 100 of those - 5 per symbol that I actively work with.

      Comment


      • #4
        Hi Leon,

        You are most welcome. There is no practical limit to these, I operate with hundreds active myself. The only time I ever ran into problems was when I was putting calculated values out as globals and the number of decimal points were not limited (e.g. 5.33332345835304). I now make it a practice to limit the number of decimal points to 2 or 4 by appending the value with .toFixed(2)*1.

        Regarding 5 values per symbol, you may want to consider using an object or array with 5 values which would only require one set/get GlobalValue declaration.

        for example here is one of my object declarations:

        var value = { x1 : 0, y1 : 0, x2 : 0, y2 : 0, slope : 0, bar : 0 , bars_out : 0 };

        the variables are then value.x1, value.y1, etc

        and here is an array declaration:

        var value = new Array(0,0,0,0,0);

        the variables are then value[0], value[1], etc

        Using either an object or an array minimizes greatly the number of times you have to use setGlobalValue and getGlobalValue.

        Comment


        • #5
          You are right, Steve

          using array is a better way
          thanks again.
          Leon

          Comment

          Working...
          X