Announcement

Collapse
No announcement yet.

Alex, I'm trying to figure out BBof_Template, and I can't seem to find

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

  • Alex, I'm trying to figure out BBof_Template, and I can't seem to find

    how I can feed the bollinger band my ratio of spy / qqq.
    it says:

    aValue = close(Offset,-Length); //insert the result of user defined variable here

    ...how do I insert my variable, which is RATIO = Symbol1 / Symbol2; ?

  • #2
    asherisaac
    In my original formula just replace aValue = close(Offset,-Length); with aValue = close(Offset,-Length,"SPY /QQQ");
    At that point you will need to add aValue[0] to the return (and add some preMain() statements) if you also wish to plot the ratio.
    Alex

    Comment


    • #3
      alex, sorry to bother you again. i think i'm getting close, but it's not plotting. i thought i made the requisite premain adjustments and adjustment in the return statement but it's not plotting anything. i'm trying to plot a bollinger band of the ratio of two instruments (ie; qqq/spy).

      Alexis C. Montenegro © March 2004
      Use and/or modify this code freely. If you redistribute it
      please include this and/or any other comment blocks and a
      description of any changes you make.
      ************************************************** ********/

      function preMain() {
      setPriceStudy(false);
      setStudyTitle("BBof_template");
      setCursorLabelName("Upper",0);
      setCursorLabelName("Basis",1);
      setCursorLabelName("Lower",2);
      setDefaultBarFgColor(Color.blue,0);
      setDefaultBarFgColor(Color.red,1);
      setDefaultBarFgColor(Color.blue,2);
      setDefaultBarThickness(1,0);
      setDefaultBarThickness(1,1);
      setDefaultBarThickness(1,2);

      // checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/BBof_template.efs"); //Comment this line out if modifying the code

      var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
      fp1.setLowerLimit(1);
      fp1.setDefault(20); //Edit this value to set a new default

      var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
      fp2.setDefault(0); //Edit this value to set a new default

      var fp3 = new FunctionParameter("StdDev", FunctionParameter.NUMBER);
      fp3.setLowerLimit(0);
      fp3.setDefault(2); //Edit this value to set a new default

      var fp4 = new FunctionParameter("s1", FunctionParameter.STRING);
      fp1.setDefault("SPY"); //Edit this value to set a new default

      var fp5 = new FunctionParameter("s2", FunctionParameter.STRING);
      fp2.setDefault("QQQ"); //Edit this value to set a new default


      }

      var aValue = null;

      function main(Length, Offset, StdDev, s1, s2) {

      aValue = new Array(Length);

      var nSum = 0;
      var ySum = 0;
      var Basis = 0;
      var vStdDev = 0;
      var s1;
      var s2;

      var Sym1 = getValue("Open", 0, 1, s1);
      var Sym2 = getValue("Open", 0, 1, s2);
      var RATIO = Sym1 / Sym2;


      //calculate here the user defined variable


      aValue = close(Offset,-Length, "RATIO"); //insert the result of user defined variable here
      if (aValue == null) {
      return;
      }
      //end user defined variable

      for(i = 0; i < Length; i++){
      nSum += (aValue[i]);
      }
      Basis=nSum/Length;

      for(i = 0; i < Length; i++){
      ySum += (aValue[i]-Basis)*(aValue[i]-Basis);
      }
      vStdDev=Math.sqrt(ySum/(Length));

      var Upper = Basis+(StdDev*vStdDev);
      var Lower = Basis-(StdDev*vStdDev);
      // drawTextRelative(0, close(), Upper, Color.blue, Color.RGB(255,255,255), Text.LEFT, "Arial", 20);

      return new Array(Upper,Basis,Lower, aValue[0]);
      }

      Comment


      • #4
        asherisaac
        Please follow the suggestion I made in my prior message and replace
        aValue = close(Offset,-Length, "RATIO");
        with
        aValue = close(Offset,-Length,"SPY /QQQ");
        If instead you still want to use the variable RATIO then you will need to create an array to store the historical values for that variable as they do not exist. You can find information and examples on how to create arrays in the EFS KnowledgeBase under EFS Function Reference->Utility Functions->Arrays
        Alex

        Comment

        Working...
        X