Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Assigning indicator values

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

    Assigning indicator values

    Hello, I have the snippet of code where the following conditions paint the bar red or green:

    Code:
    protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
    			
    			if (MACD(12,26,9).Diff[0] > 0 && MACD(12,26,9)[0] > 0)
          			BarColor = Color.Green;
    		
    			else if (MACD(12,26,9).Diff[0] < 0 && MACD(12,26,9)[0] < 0)
          			BarColor = Color.Red;
    			
            }
    Now, I plan on using the indicator in a strategy and was wondering how to set something like: if the bar is red, then value of the indicator == 0, and if the bar if green, then set the value of the indicator == 1 .. or something like this. I just want to be able to call out a 0, or 1 (for red or green bars) when building the strategy..thx

    #2
    Create an indicator plot and set it to 0 or 1 depending on what you want. Please see the Help Guide tutorials on building custom indicators.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    62 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    33 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    44 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    58 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    47 views
    0 likes
    Last Post CarlTrading  
    Working...
    X