Announcement

Collapse
No announcement yet.

Moving Average with stop line, help?

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

  • Moving Average with stop line, help?

    Hello, I'm wondering if anyone would know how to add a stop line to a moving average, so it looks like what I have drawn in the chart? Thanks!

    Attached Files

  • #2
    Re: Moving Average with stop line, help?

    bugscoe
    Add the following line of code above your return statement
    Alex

    PHP Code:
     drawLineRelative(0vMA.getValue(MAStudy.MA),10vMA.getValue(MAStudy.MA), PS_SOLID2Color.blue,"line"); 
    Originally posted by bugscoe
    Hello, I'm wondering if anyone would know how to add a stop line to a moving average, so it looks like what I have drawn in the chart? Thanks!

    Comment


    • #3
      Thank you Alex!

      Could you please advise on what code I need to add so that the line changes to BLUE when price closes above and RED when price closes below?

      Comment


      • #4
        bugscoe
        You need to do the following. In your conditions instead of setting the color of the plot you assign a color to a variable which you then you use to color both the plot and the stop line eg
        if(myFirstCondition)
        var myColor = Color.name_of_color (eg Color.black)
        if(mySecondCondition)
        var myColor = Color.name_of_color

        then following that you set the color of the plot using the setBarFgColor() function eg
        setBarFgColor(myColor);
        and then use myColor also as the color parameter of the drawLineRelative() function
        Alex


        Originally posted by bugscoe
        Thank you Alex!

        Could you please advise on what code I need to add so that the line changes to BLUE when price closes above and RED when price closes below?

        Comment


        • #5
          Thanks again! I'll give it a shot.

          Comment


          • #6
            bugscoe
            You are most welcome
            Alex


            Originally posted by bugscoe
            Thanks again! I'll give it a shot.

            Comment


            • #7
              EMA w/Stop changes color

              Looking for some programming help.

              I have this EMA which changes color as price is above or below. I then added a stop, a horizontal line extending off of the EMA and would also like that to change color when price is above or below.

              I've not been able to figure this out. Anyone know how to do it?

              Thanks!
              Attached Files

              Comment


              • #8
                if (vMA.getValue(MAStudy.MA) > close(0))
                setBarFgColor(Color.red);
                if (vMA.getValue(MAStudy.MA) < close(0))
                setBarFgColor(Color.blue);

                if (vMA.getValue(MAStudy.MA) > close(0))
                drawLineRelative(0, vMA.getValue(MAStudy.MA),13, vMA.getValue(MAStudy.MA), PS_SOLID, 2, Color.red,"line");

                if (vMA.getValue(MAStudy.MA) < close(0))
                drawLineRelative(0, vMA.getValue(MAStudy.MA),13, vMA.getValue(MAStudy.MA), PS_SOLID, 2, Color.blue,"line");
                return vMA.getValue(MAStudy.MA);

                Comment


                • #9
                  Perfect.

                  David, thank you very much!

                  Comment

                  Working...
                  X