Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compilation Error - this code:

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

    Compilation Error - this 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

    // 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 TestStrategy : Strategy
    {
    #region Variables
    private double highestHigh = 0;
    private double lowestLow = 0;
    private int barPeriod = 45;
    #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()
    {
    if (Bars.FirstBarOfSession && FirstTickOfBar)
    {
    highestHigh = High[0];
    lowestLow = Low[0];
    }
    // Stores the highest high from the first 30 bars
    if (Bars.BarsSinceSession < 30 && High[0] > highestHigh)
    {
    highestHigh = High[0];
    }
    // Stores the lowest low from the first 30 bars
    if (Bars.BarsSinceSession < 30 && Low[0] < lowestLow)
    {
    lowestLow = Low[0];
    }
    for (int i = 0; i < barPeriod; i++)
    if (Open[0][i] < Close[0][i] && Rising(Current[0]))
    {
    EnterLong();
    ExitShort();
    }
    else if (Currrent[0] >= highestHigh)
    {
    ExitLong();
    EnterShort();
    }
    }
    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hello,

    Thank you for the post.

    There are multiple items that are not correct here, I will list them below:

    First it seems you are trying to use the Single series Open price in a Multi-Series way:

    Code:
    Open[0][i]
    Did you instead mean to use Opens[0][i] ? Open would only support a BarsAgo or: Open[i]. This would also apply to your use of Close[0][i].

    You have used something called Current, but this does not exist in the script. Can you tell me, was this intended to be a series that you are storing data to? Additionally you have two spellings of Current and Currrent.

    Finally, the variable myInput0 was removed, so the public property would need removed as well, at the bottom of the file the whole region below would need removed:

    Code:
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    Please let me know if I may be of additional assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    57 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    143 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    161 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    97 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