Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Am pulling my hair out (what little is left)

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

    Am pulling my hair out (what little is left)

    Here is my custom strategy:
    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    namespace NinjaTrader.Strategy
    {
        public class Whasapp : Strategy
        {
            protected override void Initialize()
            {
    			Add(this.WhasappIndicator());
                CalculateOnBarClose = true;
            }
    		
            protected override void OnBarUpdate()
            {
    			bool signal = ToTime(Time[0]) > 100000 && ToTime(Time[0]) < 110000;
    			
    			if (signal) this.WhasappIndicator().Signal.Set(0, true);
    			else this.WhasappIndicator().Signal.Set(0, false);
            }
        }
    }
    Here is my custom indicator:
    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion
    
    namespace NinjaTrader.Indicator
    {
        public class WhasappIndicator : Indicator
        {
            #region Variables
    		private BoolSeries signal;
            #endregion
    
            protected override void Initialize()
            {
                Overlay				= false;
    			this.signal 		= new BoolSeries(this);
            }
    
            protected override void OnBarUpdate()
            {
    			if (this.signal.ContainsValue(0) && this.signal[0]) this.BackColor = Color.Lime;
    			else this.BackColor = Color.Crimson;
            }
    
            #region Properties
            [Browsable(false)]
            [XmlIgnore()]	
            public BoolSeries Signal
            {
                get { return this.signal; }
                set { this.signal = value; }
            }
            #endregion
        }
    }
    ... + NT generated code
    When I run this (through Strategy Analyzer, or on a chart), why do I get a result like the attached image?

    I was expecting to see crimson everywhere except where the time was between 10h00 and 11h00, where I expected to see lime ...

    What's up?
    Attached Files
    Last edited by AnotherTrader; 05-19-2014, 01:22 PM.

    #2
    Hi AnotherTrader,

    I gave your code a run here and I was able to plot the lime backcolor when the condition was true (see the attachments)

    This falls in line between 10am and 11am as you have coded.

    I do not see anything conceptually wrong with the code you have provided. I'd suggest adding some "Print" statements from the strategy and make sure your values are evaluated as you expect them.
    Attached Files
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by AnotherTrader View Post
      Here is my custom strategy:
      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Strategy;
      #endregion
      
      namespace NinjaTrader.Strategy
      {
          public class Whasapp : Strategy
          {
              protected override void Initialize()
              {
                  Add(this.WhasappIndicator());
                  CalculateOnBarClose = true;
              }
              
              protected override void OnBarUpdate()
              {
                  bool signal = ToTime(Time[0]) > 100000 && ToTime(Time[0]) < 110000;
                  
                  if (signal) this.WhasappIndicator().Signal.Set(0, true);
                  else this.WhasappIndicator().Signal.Set(0, false);
              }
          }
      }
      Here is my custom indicator:
      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Diagnostics;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Gui.Chart;
      #endregion
      
      namespace NinjaTrader.Indicator
      {
          public class WhasappIndicator : Indicator
          {
              #region Variables
              private BoolSeries signal;
              #endregion
      
              protected override void Initialize()
              {
                  Overlay                = false;
                  this.signal         = new BoolSeries(this);
              }
      
              protected override void OnBarUpdate()
              {
                  if (this.signal.ContainsValue(0) && this.signal[0]) this.BackColor = Color.Lime;
                  else this.BackColor = Color.Crimson;
              }
      
              #region Properties
              [Browsable(false)]
              [XmlIgnore()]    
              public BoolSeries Signal
              {
                  get { return this.signal; }
                  set { this.signal = value; }
              }
              #endregion
          }
      }
      ... + NT generated code
      When I run this (through Strategy Analyzer, or on a chart), why do I get a result like the attached image?

      I was expecting to see crimson everywhere except where the time was between 10h00 and 11h00, where I expected to see lime ...

      What's up?
      Try direct assignment, instead of Set().
      Code:
      ...
                  if (signal) this.WhasappIndicator().Signal.[0] = true;
                  else this.WhasappIndicator().Signal[0] = false;

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X