Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    21 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post cre8able  
    Working...
    X