• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 TrendFollowingCapital, Today, 04:29 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by Conall, Today, 06:11 AM
    0 responses
    3 views
    0 likes
    Last Post Conall
    by Conall
     
    Started by Vincere, Yesterday, 11:20 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by uday12, Yesterday, 10:07 PM
    1 response
    4 views
    0 likes
    Last Post bltdavid  
    Started by cnecorp, Today, 03:04 AM
    3 responses
    18 views
    0 likes
    Last Post cnecorp
    by cnecorp
     
    Working...
    X