Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 junkone, 04-21-2024, 07:17 AM
      10 responses
      148 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by tsantospinto, 04-12-2024, 07:04 PM
      6 responses
      99 views
      0 likes
      Last Post tsantospinto  
      Started by rocketman7, Today, 02:12 AM
      5 responses
      26 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by ZenCortexReal, Today, 08:54 AM
      0 responses
      1 view
      0 likes
      Last Post ZenCortexReal  
      Started by ZenCortexReal, Today, 08:52 AM
      0 responses
      0 views
      0 likes
      Last Post ZenCortexReal  
      Working...
      X