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

Strategy doesn't execute all entries

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

    #46
    Hello Jim,
    I'm working a strategy in strategy analyzer. I get the trades list where I can find entry/exit time, entry/exit price, quantity,... but I cannot get stop loss and profit target prices. I'd like to export all this data to an excel to make some calculations, including stop loss and take profit.

    So I'm trying to code something that list me entry, stop loss and take profit prices.
    In OnExecutionUpdate, I've added this code either for long and short entries:
    Code:
    if (longEntry != null && execution.Order == longEntry)
    {
              Print(string.Format("{0} / longEntry = {1} / stopLossLong = {2}", Time[0], Position.AveragePrice, Position.ToString()));
              stoploss = SubmitOrderUnmanaged(...)
              takeprofit = SubmitOrderUnmanaged(...)
    }
    But here I cannot access to stoploss and takeprofit prices.
    So in OnOrderUpdate() I've added this code:
    Code:
    Print(Time[0] + "stopLossLong = " + stopPrice);
    But I get something like
    26/12/2016 18:00:00stopLoss = 0
    27/12/2016 4:00:00stopLoss = 143,995
    27/12/2016 4:00:00stopLoss = 143,995
    27/12/2016 4:00:00stopLoss = 143,995
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 143,995
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 0
    27/12/2016 4:00:00stopLoss = 0
    27/12/2016 4:00:00stopLoss = 0
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 4:00:00stopLoss = 143,82
    27/12/2016 5:00:00stopLoss = 143,82
    I cannot attach this output with the trade list that I have exported to excel in an easy way

    Could you guide me the way to get a list with entry/exit time and price, stop loss and take profit prices? Is there a way to do this on strategy analyzer?

    Comment


      #47
      Hello esborsa,

      I would recommend using the Executions grid in the Strategy Analyzer to view this information. It can be exported as an Excel spreadsheet by right clicking on the grid and selecting Export.

      If you are trying to keep record of a stop loss when an order closed from a profit target, for example, you could use OnOrderUpdate() to assign the current values for the Order objects to variables that you print later in OnExecutionUpdate() when one of the orders gets filled. That way you can print the most current value of Profit Target and Stop Loss (if they are dynamic) when one of them gets filled.

      OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

      Please let me know if I can be of further help.
      JimNinjaTrader Customer Service

      Comment


        #48
        Hello Jim,
        I'm still trying to plot a 200 period daily SMA in a 60 minute chart in Strategy Analizer. I've attached a simple strategy that opens a long position if daily SMA[0] > daily SMA[10] && Close[0] > Close[1] and opens a short position if daily SMA[0] < daily SMA[10] && Close[0] < Close[1].
        It enters correctly but it plots the daily SMA considering that 1 60 min bar = 1 daily bar. (Image corresponds to january 2008 to march 2008 60 min chart and the SMA you can see is the daily SMA)
        Would you tell me how to correct this?
        Attached Files

        Comment


          #49
          Hello esborsa,

          There are some implications to consider when adding an indicator with AddChartIndicator() that relies on a separate data series.

          From the help guide:
          An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same Add series call included as well)
          o If a secondary or null Bars series is specified by the calling strategy (not the indicator itself), the strategy's primary series will be substituted instead.
          https://ninjatrader.com/support/help...tindicator.htm

          To workaround this, I would recommend to create a shell indicator that adds the necessary data series and creates its plots based off of an SMA of daily data.

          Keep in mind that as the daily data series gets updated less often then the 60 minute bars, a value has to exist for each 60 minute bar so it can be plotted. This results in a jagged SMA since the previous value is used to fill in the gap.

          I have attached example scripts for demonstration.
          Attached Files
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by lightsun47, Today, 03:51 PM
          0 responses
          5 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          10 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          46 views
          0 likes
          Last Post futtrader  
          Started by Option Whisperer, Today, 09:55 AM
          1 response
          14 views
          0 likes
          Last Post bltdavid  
          Started by port119, Today, 02:43 PM
          0 responses
          10 views
          0 likes
          Last Post port119
          by port119
           
          Working...
          X