Announcement

Collapse
No announcement yet.

Auto Insert 3 times the current Interval

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

  • Auto Insert 3 times the current Interval

    I am trying to auto insert the value of the Interval = 2 * Interval of the current chart interval so that when I do the switching between different time frames the interval is automatically doubled & inserted rather than having to recalculate & be inserted by myself.

    ie. Current Chart Interval= 300T
    Interval = 2*"Current Chart Interval" = 600T

    Below is the Custom Stochastic from the Efs2 Custom Folder Originally written by Alexis C. Montenegro:

    /************************************************** *******
    By Alexis C. Montenegro for eSignal © December 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.
    ************************************************** ********/

    var fpArray = new Array();

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("Stochastic");
    setCursorLabelName("%K",0);
    setCursorLabelName("%D",1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setPlotType(PLOTTYPE_LINE,0);
    setPlotType(PLOTTYPE_LINE,1);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("KLength", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setName("%K");
    setLowerLimit(1);
    setDefault(14);
    }
    fpArray[x] = new FunctionParameter("KSmoothing", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setName("%KSmooth");
    setLowerLimit(1);
    setDefault(1);
    }
    fpArray[x] = new FunctionParameter("DLength", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setName("%D");
    setLowerLimit(1);
    setDefault(3);
    }
    fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Upper", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(80);
    }
    fpArray[x] = new FunctionParameter("Lower", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(20);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }

    var bInit = false;
    var xStochK = null;
    var xStochD = null;

    function main(KLength,KSmoothing,DLength,Symbol,Interval,Up per,Lower,Params) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xStochK = stochK(KLength,KSmoothing,DLength,sym(vSymbol));
    xStochD = stochD(KLength,KSmoothing,DLength,sym(vSymbol));
    addBand( Upper, PS_SOLID, 1, Color.black,"Upper");
    addBand( Lower, PS_SOLID, 1, Color.black,"Lower");
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    return new Array (getSeries(xStochK),getSeries(xStochD));
    }



    I have replaced the line above "setDefault()" for the "Interval" with 2*getInterval() but the efs seems to run in an endless loop.

    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault(2*getInterval());

    Would someone pls tell me why is it not working or what should I do to get this to work.

    Thank you so much in advance for all your inputs.

    Ted
    Last edited by Ted608; 03-05-2011, 07:40 PM.

  • #2
    How to get inv() to work in Tick ?

    I got the codes fixed as below, but it is only working in minute intervals NOT in Ticks. Would someone pls show me how I can fix this efs to work in Ticks. Thanks.


    var fpArray = new Array();

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("Stochastic");
    setCursorLabelName("%K",0);
    setCursorLabelName("%D",1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setPlotType(PLOTTYPE_LINE,0);
    setPlotType(PLOTTYPE_LINE,1);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("KLength", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setName("%K");
    setLowerLimit(1);
    setDefault(14);
    }
    fpArray[x] = new FunctionParameter("KSmoothing", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setName("%KSmooth");
    setLowerLimit(1);
    setDefault(1);
    }
    fpArray[x] = new FunctionParameter("DLength", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setName("%D");
    setLowerLimit(1);
    setDefault(3);
    }
    fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Upper", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(80);
    }
    fpArray[x] = new FunctionParameter("Lower", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(20);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }

    var bInit = false;
    var xStochK = null;
    var xStochD = null;

    var vInterval = null;

    function main(KLength,KSmoothing,DLength,Symbol,Interval,Up per,Lower,Params,vInterval) {

    if(bInit == false){
    var vInterval = 2*getInterval();
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xStochK = stochK(KLength,KSmoothing,DLength,inv(vInterval));
    xStochD = stochD(KLength,KSmoothing,DLength,inv(vInterval));
    addBand( Upper, PS_SOLID, 1, Color.black,"Upper");
    addBand( Lower, PS_SOLID, 1, Color.black,"Lower");
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    return new Array (getSeries(xStochK),getSeries(xStochD));
    }

    Comment


    • #3
      Re: How to get inv() to work in Tick ?

      Ted608
      If the interval is a string that contains a combination of alphanumerical characters [eg 300T, 1500V, 2R, etc] you need to parse the numerical portion of that string prior to being able to perform any math operations on that. Once you have performed the math you would then need to concatenate back to the resulting value the letter that defines the type of tick based interval.
      There are a number of ways you can parse the numerical content such as by using the parseInt() function or by manipulating the string using the appropriate methods of the String Object. The latter is also required to capture the letter in the original string so as to be able to reuse it in the new string
      See as an example the basic code shown in the enclosed image. Also if you search the forums you will find other examples of how to do this as this topic has been covered before
      Alex




      Originally posted by Ted608
      I got the codes fixed as below, but it is only working in minute intervals NOT in Ticks. Would someone pls show me how I can fix this efs to work in Ticks. Thanks.


      var fpArray = new Array();

      function preMain() {

      setPriceStudy(false);
      setStudyTitle("Stochastic");
      setCursorLabelName("%K",0);
      setCursorLabelName("%D",1);
      setDefaultBarFgColor(Color.blue, 0);
      setDefaultBarFgColor(Color.red, 1);
      setPlotType(PLOTTYPE_LINE,0);
      setPlotType(PLOTTYPE_LINE,1);
      setDefaultBarThickness(1,0);
      setDefaultBarThickness(1,1);
      askForInput();

      var x=0;
      fpArray[x] = new FunctionParameter("KLength", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setName("%K");
      setLowerLimit(1);
      setDefault(14);
      }
      fpArray[x] = new FunctionParameter("KSmoothing", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setName("%KSmooth");
      setLowerLimit(1);
      setDefault(1);
      }
      fpArray[x] = new FunctionParameter("DLength", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setName("%D");
      setLowerLimit(1);
      setDefault(3);
      }
      fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
      with(fpArray[x++]){
      setDefault();
      }
      fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
      with(fpArray[x++]){
      setDefault();
      }
      fpArray[x] = new FunctionParameter("Upper", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setLowerLimit(0);
      setDefault(80);
      }
      fpArray[x] = new FunctionParameter("Lower", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setLowerLimit(0);
      setDefault(20);
      }
      fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
      with(fpArray[x++]){
      setName("Show Parameters");
      setDefault(false);
      }
      }

      var bInit = false;
      var xStochK = null;
      var xStochD = null;

      var vInterval = null;

      function main(KLength,KSmoothing,DLength,Symbol,Interval,Up per,Lower,Params,vInterval) {

      if(bInit == false){
      var vInterval = 2*getInterval();
      if(Symbol == null) Symbol = getSymbol();
      if(Interval == null) Interval = getInterval();
      var vSymbol = Symbol+","+Interval;
      xStochK = stochK(KLength,KSmoothing,DLength,inv(vInterval));
      xStochD = stochD(KLength,KSmoothing,DLength,inv(vInterval));
      addBand( Upper, PS_SOLID, 1, Color.black,"Upper");
      addBand( Lower, PS_SOLID, 1, Color.black,"Lower");
      setShowTitleParameters(eval(Params));
      bInit = true;
      }

      return new Array (getSeries(xStochK),getSeries(xStochD));
      }

      Comment

      Working...
      X