Announcement

Collapse
No announcement yet.

How to add the # of bars to trigger a signal?

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

  • How to add the # of bars to trigger a signal?

    Hello

    Attached is a simple 9 wma of the High and the Low.
    Basically candle turns green when close is above the 9 wma high and turns red when the close is below the 9wma low.

    Question is how can I filter the trigger further by saying to change colors only after the close is 3 bars higher than the high or low?

    Any suggestions would be appreciated.

    Thanks in Advance.

    Pogman
    Attached Files

  • #2
    Pogman

    Question is how can I filter the trigger further by saying to change colors only after the close is 3 bars higher than the high or low?
    From your description it is not clear what you are trying to accomplish.
    If the condition to color the bar requires the Close of the current bar to be higher/lower than the High/Low average three bars back then you can do that in the conditional statements by retrieveing the value of the average three bars back using the Offset parameter in the .getValue() method eg
    if (close() >= vMA9_of_High.getValue(MAStudy.MA,-3))
    If instead the condition requires a certain number of bars to have passed from an event then you may want to see the example provided in this post in reply to a similar request. Note you will not be able to implement this solution using the Formula Wizard alone as it requires declaring global variables which cannot be done in the Formula Wizard
    Alex

    Comment


    • #3
      Pogman
      Another solution could be to just check that each Close for the current and prior bars is higher/lower than the High/Low average at the corresponding bar eg
      if (close() >= vMA9_of_High.getValue(MAStudy.MA,0) &&
      close(-1) >= vMA9_of_High.getValue(MAStudy.MA,-1) &&
      close(-2) >= vMA9_of_High.getValue(MAStudy.MA,-2) &&
      close(-3) >= vMA9_of_High.getValue(MAStudy.MA,-3))

      This solution can be easily implemented through the Formula Wizard
      Alex

      Comment


      • #4
        background does not change color?

        Hi Alex

        Sorry for not being clear and thanks for your suggestions. I have worked on the example you provided and it works fine for changing the background grey or light grey. I have added and modified the efs to change colors after 3 bars but it does not seem to work and always stays white.

        Let me try again and hopefully I am clear. I would like this condition,

        If the CLOSING price is 3 bars above the 9 wma then color the background green and if the CLOSING price is 3 bars below the 9 wma color the background darkgreen.

        I hope this is clear and thanks again for your suggestions.

        Pogman
        Attached Files

        Comment


        • #5
          Hi Alex

          I just your 2nd post and will try as it seems easy.

          Thanks for your helpful thoughts.

          Pogman

          Comment

          Working...
          X