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

Using AddDataSeries with Enter and SetStopLoss.

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

    Using AddDataSeries with Enter and SetStopLoss.

    Hey everyone,

    I feel like I'm missing something obvious. I made a strategy that trades based on ES but then places the actual trades on MES. With all the settings set with no commissions, no slippage, etc I would expect the results to be 1/10th of the results from when it's trading the same strategy on ES. I know in practice in live trading this won't be the case for various reasons but the fact I'm seeing a large discrepancy in the results in a perfect environment running a backtest makes me think I'm doing something wrong in the code.

    My current approach is this:
    - Primary series is set to ES 6/20 15 minute chart.
    - During State.Configure I AddDataSeries with MES 6/20 contract.
    - In OnBarUpdate if BarsInProgress > 0 then I return because I'm not interested in signals from MES.
    - When a long or short signal is generated I use EnterLong/EnterShort with the bars in progress parameter set to 1, and I give it a signal name.
    - I immediately SetStopLoss on that signal name.
    - I periodically update the stop loss again using the signal name.

    And yet, ES generates 7 trades and when I set the second series to MES it generates 25 trades. My best guess is the stop losses are not functioning the way I think they are. Alternatively I thought the indicators I'm using could be getting a second bar series update so I modified their OnBarUpdate functions to also return if BarsInProgress is > 0.

    What am I missing or doing wrong? Setting the second data series to ES makes it all function as expected, but whenever I put it on MES as second series I get completely different results.

    Thanks in advance,
    Andrew.

    #2
    Hello Andrew,

    Thanks for your post.

    If the strategy is entering X contracts for ES or MES, it will still be attributed to how the logic is entering.

    Is the logic allowing the Enter methods to be called more than once?

    Are you submitting an order for multiple contracts but receiving a partial fill?

    You can add debugging prints to observe if the strategy is calling your enter method multiple times. Checking the quantity submitted in the order methods can tell if an order is submitted for X contracts.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    I have attached an example that can demonstrate processing logic on ES and submitting orders to MES. I am not getting multiple entries when taking this approach. The script adds a check for if (State == State.Historical) return; so the logic can quickly be tested with realtime data once it is enabled.

    If you are still having issues, please modify this example to demonstrate what you are doing.

    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Hey,

      Thanks for the reply. Looking at your code made me immediately realize what I was doing wrong. I had the following code:

      Code:
      if (Position.MarketPosition != MarketPosition.Flat)
      {
          UpdateStoploss();
      }
      I figured Position would always reference the active position if there was one. I'm guessing instead it just returns Positions[0]? Changing the code to check for Positions[1].MarketPosition instead has made the results match what I would expect.

      Thanks again,
      Andrew.

      Comment


        #4
        Hello Andrew,

        I'm glad that helped.

        Positions[0] will return the position of the primary data series while Position will return the position for the data series in which it is called. If we check Position on BarsInProgress 0, we will be checking Positions[0].

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        28 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Mindset, 05-06-2023, 09:03 PM
        10 responses
        262 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by michi08, 10-05-2018, 09:31 AM
        5 responses
        741 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by The_Sec, Today, 02:29 PM
        0 responses
        2 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by tsantospinto, 04-12-2024, 07:04 PM
        4 responses
        62 views
        0 likes
        Last Post aligator  
        Working...
        X