Announcement

Collapse
No announcement yet.

Indicator not plotting properly

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

  • Indicator not plotting properly

    I am trying to get this indicator to plot in real time but it only plot from the current time forward . What I am doing wrong to make this plot as any other indicator on a chart ? It is can not plotting any historical views only from current bar forward .
    Thanks

    //sorry this is so crude, but it does the job of
    // plotting (75 LSMA), and the (21 LSMA on close, 21 LSMA on typical price,shifted 3 bars to the right).

    // Quite a hack to get this to work in eSignal, trick is to
    // use the linear regression basis line and plot the single point on each tick.
    // 2nd trick: store the calculated 2nd 21 and print the value from 3 minutes ago.
    //
    // WL and 21s are drawn starting when formula starts - don't be put off
    // by the flatness of the lines to start with. By next bar, the lines are
    // tracing out their proper path.
    //
    // I cannot work out how to make this wotk for historical charts %^(
    // so I take screenshots with Snagit at end of day for my personal reviews...

    var studyA = new LinearRegressionStudy("Close", 75, 2.0);
    var studyB = new LinearRegressionStudy("Close", 21, 2.0);
    var studyC = new LinearRegressionStudy("OHLC/4", 21, 2.0);

    var basisA_Arr = new Array();
    var basisB_Arr = new Array();
    var basisC_Arr = new Array();

    var nCount = -1; // index for above arrays

    var prev_high = 0;
    var curr_high = 0;
    var prev_low = 0;
    var curr_low = 0;

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("TR WL and 21s");
    setCursorLabelName("75LSMA",0);
    setCursorLabelName("21LSMA",1);
    setCursorLabelName("21LSMAS3",2);

    //setDefaultBarFgColor(Color.blue, 0); // upper
    setDefaultBarFgColor(Color.blue, 0); // basis
    //setDefaultBarFgColor(Color.blue, 2); // lower

    setDefaultBarFgColor(Color.blue, 1); // basis 21 LSMA
    setDefaultBarThickness(2,1);

    setDefaultBarFgColor(Color.magenta, 2); // basis 21 LSMA, shifted 3 bars forward
    setDefaultBarThickness(2,2);

    // show 75 LSMA as dotted line (VERY clear)
    setPlotType(PLOTTYPE_DOT,0);

    }

    function main() {
    //var vUpper = study.getValue(LinearRegressionStudy.UPPER);
    var BasisA = studyA.getValue(LinearRegressionStudy.BASIS);
    //var vLower = study.getValue(LinearRegressionStudy.LOWER);
    var BasisB = studyB.getValue(LinearRegressionStudy.BASIS);
    var BasisC = studyC.getValue(LinearRegressionStudy.BASIS);

    curr_high = high(0);
    curr_low = low(0);
    curr_price = close(0);

    var nBarState = getBarState();
    if (nBarState == BARSTATE_NEWBAR) // start of new bar
    {
    nCount++;
    }
    else
    {
    // update throughout minute to catch very last update!
    basisA_Arr[nCount] = BasisA;
    basisB_Arr[nCount] = BasisB;
    basisC_Arr[nCount+2] = BasisC;
    }

    return new Array(BasisA, BasisB, basisC_Arr[nCount]);
    }

  • #2
    Without going through the code too much, one question leaps to mind...you are doing a 75 period SMA. How many bars are on your chart? If you only have 80 bars then only the last 5 or so bars may get plotted.

    You don't do a great deal of checking for bad returns, might I suggest a few more check for null returns for the price and LR returns.

    var nIndex = getCurrentBarIndex();
    var BasisA = studyA.getValue(LinearRegressionStudy.BASIS);

    if (BasisA == null){
    debugPrintln("BasisA null - Index = " + nIndex);
    return;
    }


    If you do the above checks for each of the returns, I think you MIGHT figure out what is going on.
    Garth

    Comment

    Working...
    X