Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Darvas box bug?

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

    Darvas box bug?

    I'm trying to code a simple darvas box strategy where the close exceeds the upper or lower darvas box of the previous bar and go long/short respectively. The backtest and market replay show entries that almost appear to be random, with orders placed without these conditions being met. Not sure why it isn't working as it is a very basic strategy to test out the darvas box. I see a few other threads with darvas box issues and am wondering if they are resolved. Thanks.


    #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

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class DarvasBox : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)



    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    // Condition set 1
    if (Close[0] > Darvas().Upper[1])
    {
    EnterLong(DefaultQuantity, "");
    }


    // Condition set 2
    if (Close[0] < Darvas().Lower[1])
    {
    EnterShort(DefaultQuantity, "");
    }


    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    I played around with this some. It does appear to be a mess.

    Didn't have time to go into trying to figure it all out,but it is definitely not behaving as your would expect referencing with a value of [1].

    Comment


      #3
      Hello,

      Can you provide details on the timeframe this is running on? What is the DataSeries, Amount of days loaded and Instrument you are using?

      I tested this on the ES 150 Tick and compared that to backtest results and they were very similar. Could you provide the specifics of your tests?

      I look forward to being of further assistance.

      Comment


        #4
        I ran this strategy on primarily the EURUSD. 60 minute bars from 1/1/15 to now. Also ran on 12 range bars same instrument from 1/1/2010 to now. Same results over different time periods and bar types on the EURUSD. The orders don't appear to be executing where they should be executing. I'll take some screenshots and upload shortly.

        Comment


          #5
          Attached are some screenshots with notes.
          Attached Files

          Comment


            #6
            Any Ninja support people have any thoughts on this?

            Comment


              #7
              Hello,

              It seems that the way the Darvas indicator works is causing this.

              The Darvas uses Update() in its code and by calling the previous bar instead of the Current Bar it is not being updated correctly.

              I added the following line to the top of OnBarUpdate and your logic then seems to now work.

              Code:
              Darvas().Update();
              I no longer see orders being submitted outside of the conditions you have set when using this.

              Please let me know if I may be of additional assistance.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              574 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              332 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
              553 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X