In this example we will listen for one alert that has a "type" field which tells us "green" or "red". Each time we hear a "green" signal we stay in the green state until we hear the red signal. If we hear a buy or sell alert we check which state we are in, green or red.

The catch is that we want to check the color that happened 2 bars in the past.
So how do we do that?

First lets make sure you know here things are. If you builder screen doesnt look like the one below then click on the blue bar at the top and it will take you to the new builder

The three things we need to access:
1) Alerts panel - located on right sidebar
2) Variables panel - located on right sidebar
3) Rules menu - located in top 


Inventory:

  • 2-3 alerts
    • 1-2 alerts for normal entry and exits, use a template to get started
      • Use either the Simple Buy & Sell template
      • Or the TradingView Strategy Template
    • Alerts for color changes
      Two options (select one):
      • 1 alert for hearing color changes
        • type: colorChange
        • color: green/red (sent from TV plot or can be split into two alerts)
      • 2 alerts for hearing color changes
        • 1st alert: type: green
        • 2nd alert: type red
  • 3 variables
    • 1 variable to keep track of the color state
      • Name: Color
      • Type: Alphanumeric
    • 2 variables to keep track of the last two bars
      • Remember the color of the previous bar
        • Name: 1barAgo
        • Type: Alphanumeric
      • Remember the color from two bars ago
        • Name: 2barAgo
        • Type: Alphanumeric
  • 3 entry rules
    • 2 generic long and short place order rules - you get these with your template
    • 1 rule to listen for the color change alert and set the color state variable
      • Option 1:
        • Conditions
          • Custom Alerts type == colorChange
        • Actions
          • Set Strategy Variables Color = Custom Alerts color
      • Option 2 (two rules):
        • Rule 1
          • Conditions
            • Custom Alerts type == green
          • Actions
            • Set Strategy Variables Color = Custom Alerts type
        • Rule 2
          • Conditions
            • Custom Alerts type == red
          • Actions
            • Set Strategy Variables Color = Custom Alerts type
  • 1 utility rule
    • 1 rule that has no conditions and sets the color of the current bar via the color variable
      • Name: Bar Update
      • Actions
        • Set Strategy Variables 2barAgo = Strategy Variables 1barAgo
        • Set Strategy Variables 1barAgo = Strategy Variables Color
        • Rule Timer Bar Update in 00:15:00 << change this to match your time frame hours:minutes:seconds


Steps:

  1. Open the builder and choose a template to start with
    1. If you are using a backtestable tradingview strategy select "TradingView Strategy"
    2. If you are using a tradingview indicator or some other system, select "Simple buy and sell"
  2. Open the alerts tab on the right sidebar. Hit the + button. Create Alert for color change as listed in inventory
  3. Open the variables tab on the right sidebar. Hit the + button. Create the Variables listed in the inventory
  4. At the top menu select Rules > Create Rule > Entry Rule. Create one entry rule to fill the color variable with what the alert sent
  5. At the top menu select Rules > Create Rule > Utility Rule. Create one utility rule using the options in the inventory


For another example on how to setup variables and hook up alerts check out this video