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

MarketPosition.Flat and multiple charts

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

    MarketPosition.Flat and multiple charts

    I created a strategy and am trying to backtest on GC CL RTY YM AND NQ at the same time. If my code uses market position == flat to AtmStrategyCreate() wil it only activate 1 chart at a time until the trade is over or is it entries per postition.Or do I have to modify OrderHandling?

    I want the user to be allowed to use the strategy on multiple charts at the same time.

    #2
    Hello ballboy11,

    Thanks for your post.

    I should first note that backtesting Atm strategy methods will only work in the Playback Connection since those methods only work when the NinjaScript State is State.Realtime.

    NinjaScript strategies also run independently of each other. Even if you add multiple instances of a strategy to the same chart, those strategies will be separate instances and will have a separate strategy positions.

    Atm strategies will also have a separate position from the NinjaScript strategy position, so I would not recommend checking if the NinjaScript strategy position is flat before having it enter an Atm strategy.

    If we look at the SampleAtmStrategy source code, we can see that the Atm strategy position is fetched with GetAtmStrategyMarketPosition() and a unique Atm strategy Id is created with GetAtmStrategyUniqueId() when the Atm Strategy is created. Since this is a unique ID whenever an Atm strategy is created, separate NinjaScript strategies that will effectively have their own Atm strategies that are unique to each calling NinjaScript.

    The SampleAtmStrategy example can be used for further reference when using Atm strategies within NinjaScript. Additional documentation reference can be found below.

    Using Atm Strategies in NinjaScript - https://ninjatrader.com/support/help...strategies.htm
    Atm Strategy Methods - https://ninjatrader.com/support/help...gy_methods.htm

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      I am connected to my datafeed and am testing the trade live. I created a SIM accounts on GC CL NQ RTY and YM. My Strategy are all enabled and pointed to the according accounts. So if Position.MarketPosition == MarketPosition.Flat will not affect the other charts. It will only look if flat for the given chart? Or do I have to say if market position is flat for the given chart?

      Example if Market position is not flat check to see what chart has a trade in. If your instrument is flat then set up a trade.

      So is there a way to see if an Instrument is flat not the MarketPositon?

      Comment


        #4
        Hello ballboy11,

        So if Position.MarketPosition == MarketPosition.Flat will not affect the other charts. It will only look if flat for the given chart? Or do I have to say if market position is flat for the given chart?
        Strategy positions are separate from Account positions and Strategy positions are unique to each instance of a strategy. Every time you add a new strategy anywhere in the platform, it is a new instance.

        Position represents that strategy's position for the iterating instrument. If you are trying to reference that strategy's position on another instrument in a multi series NinjaScript you should use Positions.

        Atm strategy positions are separate from NinjaScript strategy positions. Atm Strategy methods do not create positions owned by the NinjaScript strategy. As such, Position will not show a position from an Atm strategy. GetAtmStrategyMarketPosition() should be used to get that Atm strategy's position.

        Position - https://ninjatrader.com/support/help...s/position.htm
        Positions - https://ninjatrader.com/support/help.../positions.htm
        Strategy vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm

        So is there a way to see if an Instrument is flat not the MarketPositon?
        If you would like to check if an account position is flat for a given instrument, you could check the Account.Positions collection.

        Account.Positions - https://ninjatrader.com/support/help...ns_account.htm

        Please let us know if we can be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          AtmStrategy within a Strategy

          I know my strategy is working but I am not sure if my strategy parameters are set properly.
          The image below are my parameters for my strategy.

          I am not sure if i am setting the parameters correctly for 5 different charts.



          I am using Strategy create. It works well on backtesting and even live but I am not sure if I have 5 charts running it will run seperate from each other.

          AtmStrategyCreate(OrderAction.Buy,OrderType.Market ,0,0,TimeInForce.Day,orderId,AtmStrategy,atmStrate gyId, (atmCallbackErrorCode, atmCallBackId) =>
          {
          //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
          if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
          {
          isAtmStrategyCreated = true;
          // bTrade1Entered = true;
          }
          });
          Attached Files

          Comment


            #6
            Hello ballboy11,

            I am using Strategy create. It works well on backtesting and even live but I am not sure if I have 5 charts running it will run seperate from each other.
            If you are using GetAtmStrategyUniqueId() to generate unique Atm strategy id's, each Atm strategy created will be unique and separate.

            GetAtmStrategyUniqueId() - https://ninjatrader.com/support/help...gyuniqueid.htm

            I would recommend testing the bundled SampleAtmStrategy NinjaScript included with the platform in a similar context to what you are trying to accomplish on multiple charts, and then to apply the same behavior to your custom strategy.

            Please let us know if you have any further questions.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by fwendolynlpxz, Today, 05:19 AM
            0 responses
            1 view
            0 likes
            Last Post fwendolynlpxz  
            Started by traderqz, Yesterday, 12:06 AM
            11 responses
            27 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by PaulMohn, Today, 03:49 AM
            0 responses
            8 views
            0 likes
            Last Post PaulMohn  
            Started by inanazsocial, Today, 01:15 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by rocketman7, Today, 02:12 AM
            0 responses
            11 views
            0 likes
            Last Post rocketman7  
            Working...
            X