Announcement

Collapse
No announcement yet.

How to reference a study to other periods?

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

  • How to reference a study to other periods?

    I got a reply from the support people at eSignal about my problem trying to reference a study to another period. I was told that I should use the callFunction command to do this.

    Well, I've tried for several hours to use this command to reference the Demand Index study to the previous period

    i.e. if Demand Index > Demand Index (previous period)

    I can't get anywhere - the software just locks up. This is really annoying and frustrating for such a simple thing. I also use MetaStock Pro and to do this kind of task is a piece of cake. I would prefer to use eSignal 7.4 as it has some better features - except the programming. There must be many people out there trying to do the same thing, so don't you think it would be a good idea to give an example on the EFS library page showing how to reference a custom study with other periods?

    Thanks,
    Jamie

  • #2
    If you are looking to display diferent time intervals, here is an example (tried to attach a file, but did not work?!?).

    Declare the studies INSIDE main, at "ALLBARS" time.
    There you can use parameters to vary the studies created.
    For example:

    var nBarState = getBarState();
    If (nBarState == BARSTATE_ALLBARS) {
    studyX = new XYZstudy(Param1*M1, Param2*M1);
    }

    I use this technique for many indicators: Oscilators, CCI, Stochastic, MACD, ROC, etc.
    NOTE: It does not work properly for indicators based on Welles Summation, like: ADX, RSI.

    Good Luck!
    Last edited by mbuta; 09-06-2003, 06:35 PM.
    Mihai Buta

    Comment


    • #3
      Hello Jamie,

      What you need to do is create two global variables. Use one for the current value of the DI (call is vDI) and one for the previous bar's DI (call it vDI_1). At the top of main add a routine that checks for a new bar and set vDI_1 to the last value of vDI. Then later in your formula you can compare the current bar's DI with the previous bar's DI. If I've misunderstood what you're asking for, please post your code here and give me some more details.

      Here's the basic structure of this example:

      PHP Code:

      var vDI null;
      var 
      vDI_1 null;

      function 
      main() {
          if (
      getBarState() == BARSTATE_NEWBAR && vDI != null) {
              
      vDI_1 vDI;
          }
          
          
      // calc for vDI;
          
      vDI your calc
          
          
      if (vDI vDI_1) {
              
      // do something
          
      } else {
              
      // do something else
          
      }
          
          return 
      vDI;

      If you need to reference more than just the previous bar's data you could explore the following alternatives.

      One method would be to use the ref() function. This allows you to reference the previous bar's data that you've returned to the chart. Visit the links below for a more detailed code example.

      RefUsage.efs
      RefUsage2.efs

      You could also store your formula values in an array for reference on a later bar. Visit the link below for a more detailed code example.
      CustomFuncRef.efs
      Jason K.
      Project Manager
      eSignal - an Interactive Data company

      EFS KnowledgeBase
      JavaScript for EFS Video Series
      EFS Beginner Tutorial Series
      EFS Glossary
      Custom EFS Development Policy

      New User Orientation

      Comment

      Working...
      X