Announcement

Collapse
No announcement yet.

Trying to plot - Greater than 200 day sma

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

  • Trying to plot - Greater than 200 day sma

    I'm trying to set up a study in which one of the conditions is that the closing price is greater than the 200 day sma. I've added the "MASTUDY" and put 200 in the "length line but it still plots when price is above and below the 200 sma.

    Any help would be appreciated.

    Here's the code from the formula wizard -

    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vSMA200 = new MAStudy(200, 0, "Close", MAStudy.SIMPLE);
    var vSMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("3Day H-L");
    setCursorLabelName("tri", 0);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarFgColor(Color.cyan, 0);
    setDefaultBarThickness(3, 0);
    setPlotType(PLOTTYPE_SQUARE, 0);
    //}}EFSWizard_PreMain

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    close(0) >= vSMA200.getValue(MAStudy.MA) &&
    close() <= vSMA5.getValue(MAStudy.MA) &&
    high(-2) < high(-3) &&
    low(-2) < low(-3) &&
    high(-1) < high(-2) &&
    low(-1) < low(-2) &&
    high() < high(-1) &&
    low() < low(-1)
    ) onAction1();
    //}}EFSWizard_Expression_1

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return ;
    //}}EFSWizard_Return

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    drawShapeRelative(0, low(), Shape.SQUARE, "", Color.RGB(255,255,255), Shape.LEFT);
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //}}EFSWizard_Actions
    Attached Files

  • #2
    Re: Trying to plot - Greater than 200 day sma

    jphillips9
    I am not sure I understand what the issue is.
    On one hand you indicate that the script "still plots when price is above and below the 200 sma" however you are not returning any values from the script [ie the efs is not plotting anything on the chart]
    On the other hand you are drawing a shape when the condition is met and as far as I can tell that appears to be working correctly.
    Perhaps you may want to provide a specific example [preferably including an image] that illustrates the issue
    Alex


    Originally posted by jphillips9
    I'm trying to set up a study in which one of the conditions is that the closing price is greater than the 200 day sma. I've added the "MASTUDY" and put 200 in the "length line but it still plots when price is above and below the 200 sma.

    Any help would be appreciated.

    Here's the code from the formula wizard -

    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vSMA200 = new MAStudy(200, 0, "Close", MAStudy.SIMPLE);
    var vSMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("3Day H-L");
    setCursorLabelName("tri", 0);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarFgColor(Color.cyan, 0);
    setDefaultBarThickness(3, 0);
    setPlotType(PLOTTYPE_SQUARE, 0);
    //}}EFSWizard_PreMain

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    close(0) >= vSMA200.getValue(MAStudy.MA) &&
    close() <= vSMA5.getValue(MAStudy.MA) &&
    high(-2) < high(-3) &&
    low(-2) < low(-3) &&
    high(-1) < high(-2) &&
    low(-1) < low(-2) &&
    high() < high(-1) &&
    low() < low(-1)
    ) onAction1();
    //}}EFSWizard_Expression_1

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return ;
    //}}EFSWizard_Return

    }

    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    drawShapeRelative(0, low(), Shape.SQUARE, "", Color.RGB(255,255,255), Shape.LEFT);
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //}}EFSWizard_Actions

    Comment


    • #3
      Here's what the problem is. Because I'm using the 200 sma when the chart first pulls up it only display the 200 sma line for so long. Because of that it shows a signal when it happens above and below the 200 sma. when i drag the chart back so include more data the signals below the 200 sma go away.

      The photos below show what i'm talking about. The red line is the 200 sma
      Attached Files

      Comment


      • #4
        Here's what it looks like when i drag the chart back so the 200 sma line extends further in history. As you can see the signals (white squares) aren't shown on the left side of the chart because they're below the 200 sma. This is the way it's supposed to be.

        How do i get it to do this correctly without manually dragging the chart backwards?
        Attached Files

        Comment


        • #5
          One more thing - this is what I'm trying to get the formula to do -

          1 Today the ETF is above the 200-day moving average.
          2 Today the ETF closes below its 5-day moving average.
          3 Two days ago the high and low price of the day is below the previous day’s high and low.
          4 Yesterday the high and low price of the day is below the previous day’s.
          5 Today’s high and low price is below yesterday’s.

          I think i coded it correctly. Can someone verify?

          Thanks

          Comment


          • #6
            jphillips9
            To prevent that from happening you need to add a null check on the value of the 200 sma eg
            PHP Code:
            if(vSMA200.getValue(MAStudy.MA)==null) return; 
            which will interrupt the execution of the efs when that value is null [ie in the first nn bars while the average is being primed]
            That said you will not be able to add this using the Formula Wizard but you will have to use the EFS Editor. Copy the line of code shown above and paste it at the beginning of the main() function [ie before your conditions]
            Keep in mind though that once the efs has been edited you may not be able to use the Formula Wizard to modify it further as it may not recognize the manual additions however you can always use the EFS Editor
            Alex


            Originally posted by jphillips9
            Here's what the problem is. Because I'm using the 200 sma when the chart first pulls up it only display the 200 sma line for so long. Because of that it shows a signal when it happens above and below the 200 sma. when i drag the chart back so include more data the signals below the 200 sma go away.

            The photos below show what i'm talking about. The red line is the 200 sma

            Comment

            Working...
            X