Announcement

Collapse
No announcement yet.

Using a for loop to plot non-continuous study lines?

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

  • Using a for loop to plot non-continuous study lines?

    To display a moving average or other price study line which intermittently starts and ends per formula conditions (not a continuous line), how is a for loop used to display the line on a chart?

    The problem I'm finding with the display of an intermttently appearing study line is that when a line end point is reached (<LineCondition> == false) and then later a new start point is reached (<LineCondition>==true), and both points are in the visible chart area, an extraneous straight line appears that connects the last visible line end point with the new line start point. When either one or the other end or start points scroll off the visible chart area, the extraneous connecting line disappears, leaving the desired gap between last end point and new start point.

    How to keep those unwanted connecting lines from appearing? Is a for loop the answer; used with drawLineRelative? How is that code written? Are there alternate solutions?

  • #2
    Lancer:

    One easy option would be to set the plot type for that return value to PLOTTYPE_FLATLINES. This would usually be done in the preMain() function.

    setPlotType( PLOTTYPE_FLATLINES, 0 );

    By default, all values returned in your script are set to a PLOTTYPE_LINE which will always connect all points.

    Chris

    Comment


    • #3
      Thanks Chris. That change eliminates the extraneous connecting lines, but then the chart lines are not continuous, and all lines need to be continuous except where no line at all is to be displayed per formula conditions.

      Comment


      • #4
        Then your only choice, I believe, would be to use the drawLineRelative() function to plot the lines yourself within the script. The downside is the overhead created by generating so many line objects on your chart. An example script is attached on how to plot a line using drawLineRelative().

        Chris
        Attached Files

        Comment


        • #5
          I see what you mean about overhead... just scrolling that EFS pins the CPU at 100%, and that's for just one line during post-market. I'm very sure I couldn't run that for multiple lines during regular market hours.

          What about the for loop solution suggested here by Steve:


          How could a for loop be used to eliminate those unwanted connecting lines? Would a for loop be less resource intensive?

          It seems odd that there isn't a simple, efficient standard solution already. Anyone wanting to turn a line on and off per conditions would have this problem.
          Last edited by Lancer; 12-15-2004, 03:38 PM.

          Comment


          • #6
            Try your original script but instead of PLOTTYPE_FLATLINES, try PLOTTYPE_SQUAREWAVE. I never noticed this before but the SQUAREWAVE type does not draw the ghost lines to fill in the gaps. Not perfect but it is much closer to what you are looking for.

            Chris

            Comment


            • #7
              Using PLOTTYPE_ LINE (original script) the ghost lines go straight across the chart to connect end point to start point. For PLOTTYPE_ SQUAREWAVE, at a line start point, the ghost lines are still there, but they go vertical to the price level of the last end point of that line. As with PLOTTYPE_LINE, when one or the other end or start points scroll outside the visible chart area, the ghost line disappears. That squarewave isn't going to work either. How about PLOTTYPE_NOGHOSTLINE? lol

              The for loop?

              Comment


              • #8
                I believe the FOR loop that Steve is talking about is the same principle as extending the line, using drawLineRelative(), as each new bar comes in. Another approach that would reduce the overhead would be to limit the number of bars back over which the line is drawn. Try the attached script. Same as the original but the line will only be drawn for the last 100 bars. Reduces overhead substantially.

                Chris
                Attached Files

                Comment


                • #9
                  Thanks Chris,

                  I will give that a try. For an array of lines, how would multiple drawLineRelative statements be referenced in the array? (return new Array(<what>). I'm using an Array and the ".toFixed(2)" element name suffix to keep line color etc. (defined in preMain; 0, 1, 2...) associated with the proper line while lines display on or off per conditions. (Described here: http://forum.esignalcentral.com/show...8086#post58086 )
                  Last edited by Lancer; 12-15-2004, 06:21 PM.

                  Comment

                  Working...
                  X