Announcement

Collapse
No announcement yet.

Color-coded stochastic study not aaplying to new bars

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

  • Color-coded stochastic study not aaplying to new bars

    Hi,

    I wrote the EFS code displayed below. Basically, I'm plotting %D and %K inside a study window, and I'm drawing %D in red when it's sloping down, and in green when it's sloping up. When I load the study, it color-codes all the previous bars exactly as expected. However, when new bars are received, they're drawn in red regardless of the slope direction. I just can't figure out what I'm doing wrong. Help!!!

    Peter

    ***********************

    //Global constants
    const PERCENT_D = 3;
    const K_SMOOTHING = 2;
    const PERCENT_K = 5;
    const PERCENT_D_UPPER = 55;
    const PERCENT_D_LOWER = 45;
    const PERCENT_K_UPPER = 80;
    const PERCENT_K_LOWER = 20;

    // Global variables
    var g_nStochD1 = 0;

    function preMain() {
    // Default settings
    setPriceStudy(false);
    setComputeOnClose(true);
    setStudyTitle("ZT Stochastics");
    setStudyMax(100);
    setStudyMin(0);
    setShowTitleParameters(false);
    setCursorLabelName("ZT %D", 0);
    setCursorLabelName("ZT %K", 1);
    setShowCursorLabel(true);
    setDefaultBarThickness(3, 0);
    setDefaultBarThickness(2, 1);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.black, 1);
    // Add horizontal lines on stochastics study.
    addBand(20, PS_SOLID, 1, Color.RGB(0,0,0));
    addBand(45, PS_SOLID, 1, Color.RGB(0,0,0));
    addBand(55, PS_SOLID, 1, Color.RGB(0,0,0));
    addBand(80, PS_SOLID, 1, Color.RGB(0,0,0));
    }

    function main() {
    var aStochs = ZT_Stochastics();

    // Draw PERCENT_D and PERCENT_K onto the study window.
    return aStochs;
    }

    function ZT_Stochastics() {
    var nStochK0 = stochK(PERCENT_K, K_SMOOTHING, PERCENT_D, 0);
    var nStochD0 = stochD(PERCENT_K, K_SMOOTHING, PERCENT_D, 0);

    if (g_nStochD1 < nStochD0) setBar(Bar.FgColor, -1, Color.green);

    g_nStochD1 = nStochD0;

    return new Array(nStochD0, nStochK0);
    Attached Files

  • #2
    Nevermind, I found my bug!!!

    Comment

    Working...
    X