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 f.saeidi, Today, 10:19 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by kujista, Today, 06:23 AM
          5 responses
          15 views
          0 likes
          Last Post kujista
          by kujista
           
          Started by traderqz, Yesterday, 09:06 AM
          2 responses
          18 views
          0 likes
          Last Post traderqz  
          Started by traderqz, Today, 12:06 AM
          3 responses
          6 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by RideMe, 04-07-2024, 04:54 PM
          5 responses
          28 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X