Announcement

Collapse
No announcement yet.

Determine if in price study or seperate pane?

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

  • Determine if in price study or seperate pane?

    Is there anyway to determine within premain or main, whether the efs is being run in the price study pane or another indicator pane???

  • #2
    michaelmakuch
    You determine where the study is going to run through the use of the setPriceStudy() function in preMain
    Alex


    Originally posted by michaelmakuch
    Is there anyway to determine within premain or main, whether the efs is being run in the price study pane or another indicator pane???

    Comment


    • #3
      There is a premain() directive to make a study run as a price study:

      setPriceStudy(true);

      By default an EFS will run in an indicator pane, but you can force it by changing true to false in the above statement:

      setPriceStudy(false);

      Of course you can set the boolean to be a variable ... there may be reasons to do this if you want to determine where the study will display as the study first loads. Note that changes to the setPriceStudy after the indicator has loaded will not result in any change. You will need to remove and then reload the study if you change the directive.

      Garth
      Garth

      Comment


      • #4
        Yes...

        I didn't explain enough. Yes, I know about setPriceStudy().

        I'd like to output into 2 panes with the same efs. Why? Example: price average and buy/sell indicators on price study pane and stochastic indicator on separate pane.

        The trade signal uses both the MA's and a stoch indicator yet they can't both be displayed in the same pane AFAIK (because the values are of very different ranges).

        Only thing I know to do is to load my efs twice. The first instance will handle the price pane stuff and the 2nd the other.

        I've now figured I can do this with a global and increment it in preMain().

        Is there any other way, cleaner?

        What would be nice is if one could specify the pane# when drawing text and shapes, plotting values etc. But I do not see this functionality.

        Thanks
        Last edited by michaelmakuch; 01-30-2008, 08:10 PM.

        Comment


        • #5
          You are doing what I do in such instances (though you shouldn't need to increment anything...just set the universal global to true after checking to see if it is true). Note that there is some small potential for a race condition since there isn't an atomic instruction in EFS (that I'm aware of). I view this a a very nominal risk however.

          wrt scaling, there are methods of scaling indicators to price. If you do a search you will find them. They tend to be a bit resource intensive however (or at least used to be, they may be better now that some new series functions).

          Garth
          Garth

          Comment


          • #6
            Output into two panes for trade signal

            I am attempting the same thing to get buy/sell signals from a combination of indicators with differing scales.

            I would be very grateful if you would post or email me some sample code that configures the globals as stated in the last two posts.

            I don't know what "race condition" or "atomic instruction" mean but I will try to find out.

            Thanks in advance.

            Wayne

            Comment


            • #7
              Count instances of script loaded...

              Something like this;


              // MultiInstance test/example


              var nInstance = 0;
              function postMain() {
              nInstance = getGlobalValue("MultiInstance");
              nInstance--;
              if (nInstance < 0) nInstance = 0;
              setGlobalValue("MultiInstance", nInstance);

              debugPrintln("postMain");
              debugPrintln("nInstance:" + nInstance);
              }

              function preMain() {
              nInstance = getGlobalValue("MultiInstance");
              debugPrintln("nInstance:" + nInstance);

              if (0 == nInstance) {
              setPriceStudy(true);
              setStudyTitle("MultiInstance 0");
              } else {
              var title = "MultiInstance " + nInstance
              setStudyTitle(title);
              }
              nInstance++;
              setGlobalValue("MultiInstance", nInstance);

              setShowCursorLabel(true);
              setCursorLabelName("MultiInstance");

              // This tells eSignal to only call our script at the close of
              // each candle, rather than each tick.
              setComputeOnClose(true);

              }


              function main() {
              // if (1 != nInstance) {
              // addBand(50, PS_SOLID, 1, Color.blue, "X");
              // }
              //
              // if (1 == nInstance) {
              // plot = xMA.getValue(0);
              // } else {
              // plot = xStochD.getValue(0);
              // }


              // return plot;
              }

              Comment


              • #8
                Race

                As far as the race condition:

                Say a chart is loading with 2 instances of the script. There is a race condition on the global "MultiInstance" since we have no way to syncronize access to it.

                So we can't guarantee that it'll work as intended.

                But it appears to work.

                An atomic instruction could solve the race problem if we had one available, i.e. a 'test and set' instruction.

                Comment

                Working...
                X