Announcement

Collapse
No announcement yet.

Incorrect Values for Slope of Stochastics

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

  • Incorrect Values for Slope of Stochastics

    Hi,
    I have tried two formulas for slope but they produce wrong results. Any help is appreciated. Below are the two formulas and attached is a screen shot of the two studies on a graph. Thanks.
    (I left out the preMain for space purposes but will send full script if needed)

    ///Start of 1st Formula

    function main(S1K, S1KSmooth, S1D, S1FastColor, S1SlowColor,Multi,AdjustmentU,AdjustmentD,vDegrees ,vDegrFontSize,vDegrTextOffset,vDegrTopOffset) {
    var myVar1;
    var myVar1_1;
    var sDisplayPrice1;

    if ( bInit == false ) {

    myStudy1 = stochK( S1K, S1KSmooth, S1D );

    bInit = true;

    }
    setBarFgColor(S1FastColor, 0); //(0,238,0), 0);//lime
    setBarFgColor(S1SlowColor, 1); //(0,238,0), 0);//lime

    //retrieve the current values
    myVar1 = myStudy1.getValue(0);
    myVar1_1 = myStudy1.getValue(-1);

    var Slope1 = ((myVar1/myVar1_1)-1)* Multi;

    if(myVar1==null||myVar1_1==null) return;

    var adjustedmyVar1 = myVar1+AdjustmentU;

    var angle1 = (Math.atan(Slope1) / (Math.PI/180 ));

    var FinalDegrees1 = (angle1 );

    sDisplayPrice1 = Math.round(FinalDegrees1);

    sDisplayPrice1 = Math.round((Math.atan(((myStudy1.getValue(0)/myStudy1.getValue(-1))-1)* Multi) / (Math.PI/180 )));

    if ( vDegrees == true){
    drawTextRelative(vDegrTextOffset,vDegrTopOffset, " " + sDisplayPrice1 + " deg_%K" , Color.black, null, Text.RELATIVETOTOP|Text.ONTOP|Text.FRAME|Text.BOLD ,"Arial",vDegrFontSize,"Degrees");
    }

    return new Array( myVar1, myVar2 );

    }

    ///End of 1st Formula

    ///Start of 2d Formula

    function main(S1K, S1KSmooth, S1D, S1FastColor, S1SlowColor,vDegrees,vDegrFontSize,vDegrTextOffset ,vDegrTopOffset,BarsforSlope,Multi) {

    if ( bInit == false ) {

    myStudy1 = stochK( S1K, S1KSmooth, S1D );
    myStudy2 = stochD( S1K, S1KSmooth, S1D );

    bInit = true;

    }
    setBarFgColor(S1FastColor, 0); //(0,238,0), 0);//lime
    setBarFgColor(S1SlowColor, 1); //(0,238,0), 0);//lime
    myVar1 = myStudy1.getValue(0);
    myVar2 = myStudy2.getValue(0);
    Slope1 = CheckSlope(myStudy1,BarsforSlope); // sending the CheckSlope function a series
    angle1 = (Math.atan(Slope1)/(Math.PI/180 ));
    FinalDegrees1 = (angle1);

    sDisplayPrice1 = Math.round(FinalDegrees1*Multi);
    vCursorDeg = " " + sDisplayPrice1;
    vCursorSlope = " " + Math.round(Slope1*Multi);
    if ( vDegrees == true){
    drawTextRelative(vDegrTextOffset,vDegrTopOffset, " " + sDisplayPrice1 + " deg_%K", Color.black, null, Text.RELATIVETOTOP|Text.ONTOP|Text.FRAME|Text.BOLD ,"Arial",vDegrFontSize,"Degrees");
    }

    return new Array( myVar1, myVar2,vCursorDeg,vCursorSlope);
    }

    function CheckSlope(tmpX,NoOfBars){// CheckSlope function S. Hare 8 17 2006
    var tmp = tmpX.getValue(-NoOfBars);
    if (tmp == null || tmp == 0){
    return null;
    }
    var time = rawtime(-NoOfBars)-rawtime(0);
    if (time ==null || time == 0){ // if the check for zero is not made, there is a potential for over-run when dividing by this number
    return null;
    }
    var slope = (tmp - tmpX.getValue(0))/time; // time base seconds, therefore the slope is price change per second
    return slope;
    }

    ///End of 2d Formula
    Last edited by waynecd; 02-20-2008, 10:09 PM.

  • #2
    which version of esignal are you using??

    I'll have to look up a few things and try to get back to you. Have not worked with slopes and angles in a while :P

    In structure, your code appears correct. Your use of the functions/formulas that calculate the slopes/angles may be incorrect or something.

    Let me play with these examples over the next few days. Alex may also have some good examples of this.

    What types of defaults are you using for your main parameters?
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thanks for the reply Doji3333.

      I attached the EFS with some further modifications and it seems much closer to working.

      Apart from an accurate output for slope and degrees of slope, it causes eSignal to crash when I set the interval to tick such as 512T.

      Thank you very much.
      Attached Files

      Comment

      Working...
      X