Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

compile Error: 'myOrder' conflicts with the declaration 'NinjaTrader.NinjaScript.Stra

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

    compile Error: 'myOrder' conflicts with the declaration 'NinjaTrader.NinjaScript.Stra

    A) Been trying to use this to identify the entry order name as multiple exits may be used based on the entry code with no luck. Any thoughts?

    Code:
    private Order myOrder = null;
    
    protected override void OnBarUpdate()
    {
        if (Position.Quantity < 1 && buyPatternCode1)
        {
            Order myOrder = EnterLong(sharesToBuy, "Code1");
        }
        if (Position.Quantity < 1 && buyPatternCode2)
        {
            Order myOrder = EnterLong(sharesToBuy, "Code2");
        }
    
        if (Position.Quantity >= 1 && myOrder.Name == "Code1" && sellPatternCode1)
        {
            ExitLong();
        }
        if (Position.Quantity >= 1 && myOrder.Name == "Code2" && sellPatternCode2)
        {
            ExitLong();
        }
    }
    Compile Error: 'myOrder' conflicts with the declaration 'NinjaTrader.NinjaScript.Strategies.TestStrategy.m yOrder'

    B) I've been doing this by writing to a file 'symbolName.code1.txt' and then looking to see if the file exists on the sell side however in backtesting this is causing for some reason inconsistent backtests. I'll run a backtest note the results then click Run again not changing anything and the new results are different than the first. So i'm trying to get away from written file usage BUT need to be able to buy say in January and sell say in February so I need to know the entry name/code used over multiple days and even NinjaTrader restarts. SO, does myOrder.Name persist across NinjaTrader restarts or is it lost?
    Last edited by NinjaTrader_ChelseaB; 01-06-2019, 03:49 PM.

    #2
    Hello antrux,

    You are attempting to declare myOrder multiple times in the same scope (and in different scopes). Each time you use the Order type keyword here you are trying to create a new object.

    In C#, you cannot declare multiple objects with the same name in the same scope.

    myOrder has already been declared as a private Order within the scope of the class. I do not think you mean to be declaring it again. (Meaning remove the Order keyword from within OnBarUpdate()).

    Below is a public link with helpful information about getting started with NinjaScript and C#.
    https://ninjatrader.com/support/foru...040#post786040


    Further, do not assign Order objects to variables in OnBarUpdate(). this must be done in OnOrderUpdate().
    Below is a public link to the help guide on OnOrderUpdate that provides an example.
    https://ninjatrader.com/support/help...rderupdate.htm
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    72 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X