Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rangecounter Problem

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

    Rangecounter Problem

    Hi guys,
    I am working on a strategy that enters an order as the rangecounter goes below a certain value before the next bar. I created this in strategyCreation Wizard, but no orders are placed. I have it set to work intrabar,and that still does not solve the problem. I then tried using a current high minus the current bar low, but still no trades where triggered. I am attaching a copy of both codes for review. Thanks for any help in fixing this in advance.

    Code with Range counter

    " CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (RangeCounter(true)[0] < RangeThreshold)
    {
    EnterLong(DefaultQuantity, "");
    }

    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int RangeThreshold
    {
    get { return rangeThreshold; }
    set { rangeThreshold = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int Profit
    {
    get { return profit; }
    set { profit = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int Loss
    {
    get { return loss; }
    set { loss = Math.Max(1, value); }
    }
    #endregion
    }
    }"


    Code using High minus Low
    "
    protected override void Initialize()
    {

    SetProfitTarget("", CalculationMode.Ticks, Profit);
    SetStopLoss("", CalculationMode.Ticks, Loss, false);

    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if ((High[0] - Low[0])> rangeThreshold)

    {
    EnterLong(DefaultQuantity, "");
    }

    }

    #region Properties
    [Description("")]
    [Category("Parameters")]
    public int RangeThreshold
    {
    get { return rangeThreshold; }
    set { rangeThreshold = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int Profit
    {
    get { return profit; }
    set { profit = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int Loss
    {
    get { return loss; }
    set { loss = Math.Max(1, value); }
    }
    #endregion
    }
    }"
    Last edited by a1982yusuf; 12-21-2009, 05:59 AM.

    #2
    For the first one, it won't work because RangeCounter is a visualization indicator only with no real value you can compare it to.

    The second example will work provided High-Low actually yields something greater than 1. Not likely depending on the instrument you are testing on. What I suggest you do is to test the calculations by hand so you know when it should and when it should not work. Print the values of your highs and lows so you can evaluate the code one step at a time.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh, I figured it out. I changed my variable from an integer to double...and that gave me 3 decimal places. Problem fixed

      Comment

      Latest Posts

      Collapse

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