Announcement

Collapse
No announcement yet.

Keltner Channel Problem

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Keltner Channel Problem

    Hi there.
    I`m having some trouble with this formula. Don`t know why but it plots nothing...
    It's an EMA based Keltner Channel. The formula is
    ema +/- ConstantCoeficient * sma( 2 * emaPeriod, high - low);
    The code has 2 pairs of channels, each one relative to a constant.

    Hope someone can.
    Here is the code:

    -------------------------------------------------------
    var fpArray = new Array();

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("MA Long Keltner Channel");

    setCursorLabelName("OUTSIDE UP Keltner Channel",0);
    setPlotType(PLOTTYPE_DOT,0);
    setDefaultBarFgColor(Color.RGB(255,255,0),0);

    setCursorLabelName("INSIDE UP Keltner Channel",1);
    setPlotType(PLOTTYPE_DOT,1);
    setDefaultBarFgColor(Color.RGB(255,255,0),1);

    setCursorLabelName("MEDIA Keltner Channel",2);
    setPlotType(PLOTTYPE_DOT,2);
    setDefaultBarFgColor(Color.RGB(255,255,0),2);

    setCursorLabelName("INSIDE DOWN UP Keltner Channel",3);
    setPlotType(PLOTTYPE_DOT,3);
    setDefaultBarFgColor(Color.RGB(255,255,0),3);

    setCursorLabelName("OUTSIDE DOWN DOWN Keltner Channel",4);
    setPlotType(PLOTTYPE_DOT,4);
    setDefaultBarFgColor(Color.RGB(255,255,0),4);

    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(120);
    }
    fpArray[x] = new FunctionParameter("Coef_Out", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(5);
    }
    fpArray[x] = new FunctionParameter("Coef_In", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(1.5);
    }
    }
    var AMP = null;
    var MAL = null;
    var bInit = false;
    var CHOH = 0;
    var CHOL = 0;
    var CHIH = 0;
    var CHIL = 0;
    var valorMediaAMP = 0;
    var valorMediaMAL = 0;
    function main(Length, Coef_Out, Coef_In) {
    if(bInit==false){
    MAL = ema(Length);
    intervalo = 2*Length;
    seriesma = getSeries(high() - high());
    AMP = sma(intervalo, seriesma);
    bInit=true;
    }
    valorMediaMAL = MAL.getValue(0);
    valorMediaAMP = AMP.getValue(0);

    CHOH = valorMediaMAL + (Coef_Out*valorMediaAMP);
    CHOL = valorMediaMAL - (Coef_Out*valorMediaAMP);
    CHTH = valorMediaMAL + (Coef_In*valorMediaAMP);
    CHTL = valorMediaMAL - (Coef_In*valorMediaAMP);

    return new Array(CHOH,CHOL,valorMediaMAL,CHTH,CHTL);

    }
    ---------------------------------------------------

  • #2
    Re: Keltner Channel Problem

    bdfranca
    seriesma is not a series hence you cannot use it as a source of the sma() function you are assigning to the variable AMP
    To create a series you need to calculate your equation of the range in a separate function or external efs which you then call using the efsInternal() or efsExternal() functions. This series created by the efsInternal() or efsExternal() functions can then be used as a source for the built-in studies. For the description of the efsInternal() and efsExternal() functions and the required syntax see the links above which will take you to the corresponding articles in the EFS KnowledgeBase.
    You can find additional examples in this thread on the efsInternal() and efsExternal() functions and in this thread that shows how you can create studies on studies using these functions
    Also search the forum as most of the topics related to these functions have been discussed at length before
    Alex


    Originally posted by bdfranca
    Hi there.
    I`m having some trouble with this formula. Don`t know why but it plots nothing...
    It's an EMA based Keltner Channel. The formula is
    ema +/- ConstantCoeficient * sma( 2 * emaPeriod, high - low);
    The code has 2 pairs of channels, each one relative to a constant.

    Hope someone can.
    Here is the code:

    -------------------------------------------------------
    var fpArray = new Array();

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("MA Long Keltner Channel");

    setCursorLabelName("OUTSIDE UP Keltner Channel",0);
    setPlotType(PLOTTYPE_DOT,0);
    setDefaultBarFgColor(Color.RGB(255,255,0),0);

    setCursorLabelName("INSIDE UP Keltner Channel",1);
    setPlotType(PLOTTYPE_DOT,1);
    setDefaultBarFgColor(Color.RGB(255,255,0),1);

    setCursorLabelName("MEDIA Keltner Channel",2);
    setPlotType(PLOTTYPE_DOT,2);
    setDefaultBarFgColor(Color.RGB(255,255,0),2);

    setCursorLabelName("INSIDE DOWN UP Keltner Channel",3);
    setPlotType(PLOTTYPE_DOT,3);
    setDefaultBarFgColor(Color.RGB(255,255,0),3);

    setCursorLabelName("OUTSIDE DOWN DOWN Keltner Channel",4);
    setPlotType(PLOTTYPE_DOT,4);
    setDefaultBarFgColor(Color.RGB(255,255,0),4);

    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(120);
    }
    fpArray[x] = new FunctionParameter("Coef_Out", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(5);
    }
    fpArray[x] = new FunctionParameter("Coef_In", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(0);
    setDefault(1.5);
    }
    }
    var AMP = null;
    var MAL = null;
    var bInit = false;
    var CHOH = 0;
    var CHOL = 0;
    var CHIH = 0;
    var CHIL = 0;
    var valorMediaAMP = 0;
    var valorMediaMAL = 0;
    function main(Length, Coef_Out, Coef_In) {
    if(bInit==false){
    MAL = ema(Length);
    intervalo = 2*Length;
    seriesma = getSeries(high() - high());
    AMP = sma(intervalo, seriesma);
    bInit=true;
    }
    valorMediaMAL = MAL.getValue(0);
    valorMediaAMP = AMP.getValue(0);

    CHOH = valorMediaMAL + (Coef_Out*valorMediaAMP);
    CHOL = valorMediaMAL - (Coef_Out*valorMediaAMP);
    CHTH = valorMediaMAL + (Coef_In*valorMediaAMP);
    CHTL = valorMediaMAL - (Coef_In*valorMediaAMP);

    return new Array(CHOH,CHOL,valorMediaMAL,CHTH,CHTL);

    }
    ---------------------------------------------------

    Comment


    • #3
      Thanks a lot Alexis.
      You can be sure that the forum is my last choice. I already know the whole EFS support and knowledgebase.
      But as I'm new to this language I still get stuck even in simple problems.
      Anyway, problem solved!

      Here is the final code for those interested:




      var fpArray = new Array();

      function preMain() {

      setPriceStudy(true);
      setStudyTitle("MA Long Keltner Channel");

      setCursorLabelName("OUTSIDE UP Keltner Channel",0);
      setPlotType(PLOTTYPE_DOT,0);
      setDefaultBarFgColor(Color.RGB(255,255,0),0);

      setCursorLabelName("INSIDE UP Keltner Channel",1);
      setPlotType(PLOTTYPE_DOT,1);
      setDefaultBarFgColor(Color.RGB(255,255,0),1);

      setCursorLabelName("MEDIA Keltner Channel",2);
      setPlotType(PLOTTYPE_DOT,2);
      setDefaultBarFgColor(Color.RGB(255,255,0),2);

      setCursorLabelName("INSIDE DOWN UP Keltner Channel",3);
      setPlotType(PLOTTYPE_DOT,3);
      setDefaultBarFgColor(Color.RGB(255,255,0),3);

      setCursorLabelName("OUTSIDE DOWN DOWN Keltner Channel",4);
      setPlotType(PLOTTYPE_DOT,4);
      setDefaultBarFgColor(Color.RGB(255,255,0),4);

      askForInput();

      var x=0;
      fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setLowerLimit(1);
      setDefault(120);
      }
      fpArray[x] = new FunctionParameter("Coef_Out", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setLowerLimit(0);
      setDefault(5);
      }
      fpArray[x] = new FunctionParameter("Coef_In", FunctionParameter.NUMBER);
      with(fpArray[x++]){
      setLowerLimit(0);
      setDefault(1.5);
      }
      }
      var AMP = null;
      var MAL = null;
      var bInit = false;
      var CHOH = 0;
      var CHOL = 0;
      var CHIH = 0;
      var CHIL = 0;
      var valorMediaAMP = 0;
      var valorMediaMAL = 0;

      function main(Length, Coef_Out, Coef_In) {
      if(bInit==false){
      MAL = ema(Length);
      intervalo = 2*Length;
      seriesma = efsInternal("ampl");
      AMP = sma(intervalo, seriesma);
      bInit=true;
      }
      valorMediaMAL = MAL.getValue(0);
      valorMediaAMP = AMP.getValue(0);

      CHOH = valorMediaMAL + (Coef_Out*valorMediaAMP);
      CHOL = valorMediaMAL - (Coef_Out*valorMediaAMP);
      CHTH = valorMediaMAL + (Coef_In*valorMediaAMP);
      CHTL = valorMediaMAL - (Coef_In*valorMediaAMP);

      return new Array(CHOH,CHOL,valorMediaMAL,CHTH,CHTL);

      }

      function ampl() {
      return high() - low();
      }

      Comment

      Working...
      X