Announcement

Collapse
No announcement yet.

Stochastic from 2 TimeFrames - Average

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

  • Stochastic from 2 TimeFrames - Average

    Hi,

    I'm trying to make an Stochastic-Indikator which is calculated on 2 Timeframes. That means I have e.g. 1 Stochastic-Value from 1min and a second Stochastic-Value from 2min. This I have already done.
    I want then finally have the average of this 2 values above. I don't know how.
    Here is my modified code from customStochastic that give the values for a stochastic-Indicator from 2 timeframes. But I don't know how to calculate the average.

    /************************************************** *******
    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("StochasticAverage");
    setCursorLabelName("%K",0);
    setCursorLabelName("%K2",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 average = 0;
    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("Interval1", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setName( "Interval 2" );
    setLowerLimit(1);
    setDefault(2);
    }
    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,In terval1,Upper,Lower,Params) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    var vSymbol1 = Symbol+","+Interval1;
    //var average = 0;
    xStochK = stochK(KLength,KSmoothing,DLength,sym(vSymbol));
    xStochK1 = stochK(KLength,KSmoothing,DLength,sym(vSymbol1));
    //xStochD = stochD(KLength,KSmoothing,DLength,sym(vSymbol));
    average = (xStochK + xStochK1)/2;
    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(xStochK1));//,getSeries(average));
    }

    I think its not that complicated but I'm new to EFS. Maybe someone could help?
    Thank you!

  • #2
    have you tried creating a variable:

    say

    var xstochMA = (stoch(1min) + stoch(2min)) / 2

    and then putting then new variable into the return statment?

    Comment


    • #3
      Hi amclister,

      thank you for your answer.

      I have that already done and its called "average".
      Also when I not exclude:"//var average = 0;"
      It doesn't work.

      Maybe you have got another idea?

      Comment


      • #4
        Hi, MHundred,

        Try the attached efs. I also corrected:
        PHP Code:
        fpArray[x] = new FunctionParameter("Interval1"FunctionParameter.NUMBER); 
        with:
        PHP Code:
        fpArray[x] = new FunctionParameter("Interval1"FunctionParameter.STRING); 
        Wayne
        Attached Files
        Last edited by waynecd; 01-26-2010, 07:28 PM.

        Comment


        • #5
          Ive had a quick look at fixing your efs.

          I have got it to calculate the average but I cant get it to graph, anyway it seems waynced has sorted it for you.

          good luck,

          p.s. heres my code (note it doesnt work):
          Attached Files

          Comment


          • #6
            Thank you waynecd. Its working like I thought.

            Thank you also amclister for your efforts.

            Comment

            Working...
            X