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 t.kelly4149, Today, 05:36 PM
      1 response
      8 views
      0 likes
      Last Post bltdavid  
      Started by SilverSurfer1, Today, 06:29 PM
      0 responses
      16 views
      0 likes
      Last Post SilverSurfer1  
      Started by trader3000a, Today, 01:06 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by marcus2300, Today, 11:45 AM
      3 responses
      31 views
      0 likes
      Last Post marcus2300  
      Started by pel11, Today, 11:06 AM
      0 responses
      13 views
      0 likes
      Last Post pel11
      by pel11
       
      Working...
      X