Announcement

Collapse
No announcement yet.

Alert with BG color change

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

  • Alert with BG color change

    The temporary chart background color change alert feature in Alex's 'Stos Alert popup,color change.efs' (in the Alerts folder) is very effective, I find.

    I tried adding it my Tick Crossing Zero Alert efs (from an earlier thread today), but unlike the Stos efs where the background color change ends when the alert condition has passed, the background color change in my efs never reverts back to the default after the alert condition is over.

    Is there a conflict maybe with the multi-color default background in my efs?

    I tried adding the var fp1 from Alex's efs, but kept getting the error "Background is not defined" so I added //'s to bypass that in the attached efs, but don't know what else to try.

    Any assistance would be appreciated

    Regards
    shaeffer
    Attached Files

  • #2
    shaeffer

    I tried adding the var fp1 from Alex's efs, but kept getting the error "Background is not defined"

    That is because you did not add the function parameter name ie "Background" in function main(Background). If you look at the Stochastic formula you are referencing you will see that all the names of the function parameters are listed in function main(here).

    With regards to the chart background you also need to add a command in the else conditions ie
    setChartBG(Color.yourdefaultcolor);
    Note however that background colors applied with the setBarBgColor() command are persistent which means that if you want to remove them you have to use setBar() to repaint the background of each historical bar.
    Alex

    Comment


    • #3
      Hi Alex,

      Adding 'Background' to function main worked, but it gave me the same permanent Bg color spikes as without it, so I've removed (with //'s) the commands related to 'Background' (I guess they just allowed the Yes/No choice from Edit Studies).

      Without the 'Background' commands, could I move lines 45 and 48 up to 33 and 39 respectively?

      I see in your Stos efs how setChartBgColor in the final else condition returns the default Bg color. But as I don't want a single Bg color, do I really need that command? Rather once the condition (crossing zero) is over, I want the temporay Bg color to disappear, and the whole chart to appear in the colors defined in the SetBarBgColor commands.

      I want the series of setBarBgColors to be persistent once the alert condition is over. Do I need to somehow insert all those command into a setBar() command (or maybe 5 separate setBar() commands)?

      While on the subject of the $tickq chart, I view it and the $trinq charts in single line mode (vs candles or OHLC bars). Often in the morning, they open with a long wick candle, which when viewed in single line mode compresses the chart. I guess the AutoScale chart data tool has no option to use just Closes (and ignore highs/lows)?

      Thanks
      shaeffer
      Attached Files

      Comment


      • #4
        shaeffer

        Without the 'Background' commands, could I move lines 45 and 48 up to 33 and 39 respectively?

        Yes you can.

        I see in your Stos efs how setChartBgColor in the final else condition returns the default Bg color. But as I don't want a single Bg color, do I really need that command?

        If you do not want a single BG color then I do not understand why you are using setChartBG() at all.
        Irrespective if you want to restore the default BG you will need that else condition.

        I want the series of setBarBgColors to be persistent once the alert condition is over

        Which condition? You have three of them.
        Anyhow if you want to have setBarBgColor() on all the time just don't make it relative to a condition OR apply it to all the conditions (the first solution is the better one)

        Do I need to somehow insert all those command into a setBar() command (or maybe 5 separate setBar() commands)?

        You would use setBar() only to adjust the value or property of a study at a prior bar. Note that with setBar() you cannot use the optional [series index],[lowval],[highval] parameters available in setBarBgColor().
        Alex

        Comment


        • #5
          Hi Alex,

          I did not understand your previous reply - and thought I needed to add a setChartBG color command. But that is removed now, as well as the background commands.

          But I'm back to the previous problem, that when a tick crossing 0 occurs, the background color changes, but stays changed instead of reverting back to the setBarBgColors.

          In your Stochastic (Stos) crossing efs, when Stos crosses down thru 80 the background color changes, say to red. But on the very next chart bar, when Stos moves from 78 to 75, the entire chart Bg color reverts to the default. The red Bg color does not stay visible.

          That's what I want in this tick efs. When tick is straddling zero (ID'd as conditions #1 or#2 in the efs), I want the corresponding
          background alert color to appear, but if tick is not presently straddling zero, I want the entire chart colors to appear as in Condition #3, my 'default' Bg colors.

          But because this efs uses setBarBgColor to get multiple background colors as the 'default' (whereas your Stos efs just uses setChartBgColor) is that why the Bg alert color stays changed? And is that why I need to somehow use the setBar command to change the alert Bg color back to my default?

          Regards
          shaeffer
          Attached Files

          Comment


          • #6
            shaeffer
            First thing that needs to be done is to separate the two topics ie that of setBarBgColor() and of setChartBG() as they are not necessarily related.
            With regards to setChartBG() ie the chart background color:

            In your Stochastic (Stos) crossing efs, when Stos crosses down thru 80 the background color changes, say to red. But on the very next chart bar, when Stos moves from 78 to 75, the entire chart Bg color reverts to the default. The red Bg color does not stay visible.

            That is because in that efs there are three conditions which are mutually exclusive. If the Stochastic is above A then the chart bacground is painted in color A. If instead the Stochastic is below B then the chart is painted in color B. When neither of these two conditions is met the chart is then painted in white (because that is the background color I normally use as the default).

            That's what I want in this tick efs. When tick is straddling zero (ID'd as conditions #1 or#2 in the efs)...

            You need to define "straddling zero". To me that means that the low of a bar is below 0 and the high is above 0. If that is also what you mean then the conditions #1 and #2 do not verify that. What they do instead is check that at the prior bar the close was below (or above) 0 and that on the current bar it is above or equal (or below or equal) to 0.
            Furthermore in the commands to be executed when either condition returns true is the following line
            nLastRawTime = getValue("rawtime",0);
            which will limit the execution of all the commands to once per bar only. This is to avoid having multiple alerts (audio or popup) on the same bar.
            At the next bar the original condition is no longer true and since you have no command that reverts the background of the chart to white (for example) the chart remains painted in red or green.

            As to setBarBgColor() ie the bar background color when is it that you want these colors to be applied?
            If always then simply take them out from under any condition. If only at certain times then define those conditions and apply the appropriate commands.

            My suggestion is that you create three distint blocks of code/conditions each one handling a different task. The alerts remain in the block of conditions in which they currently are. Then in a second block of conditions you color the bar background using setBarBgColor() and in a third block of conditions you color the chart background using setChartBG().
            Hope this helps
            Alex

            Comment


            • #7
              Hi Alex,

              You are right - I was being loose in using the word "straddling". I think I have the three conditions I want correct in the efs:

              Condition 1
              Previous $tickq negative
              Current $tickq touches or crosses above 0

              Condition 2
              Previous $tickq positive
              Current $tickq touches or crosses below 0

              Condition 3
              neither of the above.

              Thanks for the explanation. I wasn't sure exactly what the nLastRawTime command did, but that is what I want - only one alert per bar, so that's ok. Hmm, does that mean I don't need "Close" in the getValue commands? It would actually be better if the first time $tickq ticks up (or down) to zero, that the alert triggers (and not again within that bar). I don't need to wait until the Close.

              You asked "As to setBarBgColor() ie the bar background color when is it that you want these colors to be applied?"
              I want these colors applied throughout the whole chart, whenever neither condition 1 nor condition 2 applies, i.e. when condition 3 applies.

              Maybe my conditional statements are not correct, but I see these as 3 mutually exclusive conditions, already set up in three distinct blocks. The logic I am trying to achieve is:

              If condition 1 met, then green background. If not, test condition 2.
              If condition 2 met, then red background. If not, go to condition 3.
              Condition 3 (= neither of the above) = use the setBarBgColors.

              I tried changing the "If" in condition 2 to "Else if" but that didn't work.

              I am trying to duplicate the exact logic flow and efs structure you used beneath the If(Background=="On") command in your Stos efs, except that under the final condition, I want the multi colors achieved with setBarBgColors vs the single color from the setChartBg command you used.

              As you suggested, I could try to take the setBarBgColors out of the condition flow (i.e. remove condition 3 which is a non event), but that did not seem necessary in your Stos efs. I just don't know what I am missing?????

              I appreciate your patience in working thru this with me.

              Cheers
              shaeffer

              Comment


              • #8
                shaeffer

                If condition 1 met, then green background. If not, test condition 2.
                If condition 2 met, then red background. If not, go to condition 3.
                Condition 3 (= neither of the above) = use the setBarBgColors


                I think you may be misunderstanding how setChartBG() ie the chart background color and setBarBgColor() ie the bar background color actually work.
                setChartBG() colors the background of the whole chart so when you issue a command to use a different color the new color is applied to the entire chart. That is the method I used in the Stochastic efs you reference.
                setBarBgColor() instead paints the background of the current bar only and that color remains tied to that bar as it shifts back in time. So when either your condition 1 or 2 are met again painting the background of the chart using setChartBG() does not remove the bar background colors you applied to the individual bars while condition 3 was true.
                To "remove" those colors you would need to use setBar() to repaint the background of each historical bar in the same color used with setChartBG(). Then when condition 3 is met again you need to go through the same process to color each historical bar background again. Note however that while setBar() will alow you to repaint the background of an historical bar it does not include the optional [seriesindex],[lowvalue],[highvalue] parameters that are available with setBarBgColor()
                In light of all the above you may need to review how you actually want to color your chart
                Alex

                Comment


                • #9
                  Alex, Thanks for the clarification on how the two different coloring schemes work. I was mistakenly thinking that SetBarBgColor on a bar following an alert condition bar would paint all bars (but as you said, that command only addresses the current bar).

                  But I did stumble on a good solution (at least it worked using bar replay). I placed the setBarBgColor commands ahead of the alert conditions. These colors always govern, but when the alert conditions occurs, the background behind the y-axis changes color accordingly. There's the visual chart alert I wanted, and right next to the bar meeting the condition! (Actually, I don't view the y-axis, but even the narrow band on the right side of the chart is wide enough to give the visual indication). Hopefully it will work the same in real time.

                  Thanks again for all your assistance Alex.

                  Regards
                  shaeffer
                  (next challenge: to get similar alerts when when new intraday highs and lows are being hit)
                  Attached Files

                  Comment

                  Working...
                  X