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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      52 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      142 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      160 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      96 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      276 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X