Announcement

Collapse
No announcement yet.

Previous Value

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

  • Previous Value

    I built a new own indicator called vStop.

    Now i would like to build a new indicator that uses the previous value of vStop.

    I am also a Metastock user and in metastock i can write NewIndicator(-1) to obtain the previous value.

    How i can do this in EFS?

    tks

    PippoTrader

  • #2
    PippoTrader
    There are several ways to retrieve historical values of a custom variable (that is not a series)
    If the variable is in your return statement you could use the ref() function. If not then you have two methods.
    If you only want two or three values back then the easiest method is to declare your variables [for example myVar_0, myVar_1, etc] as global variables [ie outside of main and preMain] and then as the first thing in main() write
    PHP Code:
    if(getBarState()==BARSTATE_NEWBAR){//at every new bar
        
    myVar_2 myVar_1;//transfer the value of myVar_1 to myVar_2
        
    myVar_1 myVar_0;//transfer the value of myVar_0 to myVar_1

    At that point myVar_1 is the value of myVar_0 one bar back and myVar_2 is the value of myVar_0 two bars back.
    If instead you have to retrieve historical values beyond two or three bars back then you may want to look at creating an array to store the historical values. For information on arrays see this article in the EFS KnowledgeBase
    Alex

    Comment


    • #3
      I tried, but it seems that it doesn't work.


      Version 1.0

      Notes:
      February 2005 Issue - "The Truth About Volatility"

      Formula Parameters: Defaults:
      ATR Periods 10
      Thickness 2
      ************************************************** ***************/

      function preMain() {
      setPriceStudy(true);
      setStudyTitle("VAI ");
      setCursorLabelName("VStop", 0);
      setCursorLabelName("VStop2", 0);
      setDefaultBarThickness(2, 0);
      setDefaultBarFgColor(Color.red, 0);

      setShowTitleParameters(false);

      }
      var BarCntr = 0;
      var myValue1, myValue2;

      function main() {


      if(getBarState()==BARSTATE_NEWBAR){//at every new bar
      myValue2 = myValue1;//transfer the value of myVar_1 to myVar_2
      }

      var HCh;
      var LCh;
      var myRef;


      myVar = efsExternal("Volatility Avvenire Index.efs");

      myValue1=getSeries(myVar,1);


      debugPrintln("Bar Index: " + getCurrentBarIndex() + " myValue1= " + myValue1 + " myValue2= " + myValue2);






      return(myValue1);



      }

      Comment


      • #4
        PIPPOTRADER
        For that method to work myValue1 needs to be a value and not a series. This is why in my previous reply I wrote "to retrieve historical values of a custom variable (that is not a series)"
        Since myValue1 is a series you can directly access its prior values using the .getValue(barIndex) method where barIndex is the bar index of the value you want to retrieve ie 0 for current bar, -1 for the prior bar, -2, for two bars ago, etc. For example myValue1.getValue(-1) is the value of myValue1 at the prior bar.
        Alex

        Comment

        Working...
        X