• 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

pnl

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

    pnl

    I want in my strategy is to set PNL for the trading session if it drops below a certain point close the strategy and vice versa is there a way to do this?

    #2
    Hello ballboy11,

    Thanks for your post.

    If I understand correctly, you are trying to:
    1. Collect strategy PnL from the trading session
    2. Check if this PnL is within a certain point
    3. Close the strategy depending on this condition.


    Collecting PnL can be done from a TradeCollection. I would like to point out the following thread where this has been addressed recently for your reference. Sample code, explanations and documentation reference are included therein. Please leave a reply in our thread here if you have any specific questions that are not clear after testing.

    Collecting PnL by creating your own TradeCollection - https://ninjatrader.com/support/foru...d.php?t=111702

    This information could be used in your own condition to compare PnL with a certain level, and then the strategy can call the CloseStrategy() method to close the strategy.

    CloseStrategy - https://ninjatrader.com/support/help...sestrategy.htm

    I look forward to being of any further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Will this work on playback. I am not getting any information. I am also using CreateATMStrategy as well instead of enter exit long etc.

      Comment


        #4
        Hello ballboy11,

        The code in the linked thread references SystemPerformance.AllTrades which is a collection of all trades made by the NinjaScript strategy including trades made with historical data and with realtime data. Keep in mind, NinjaScript strategies that submit Atm strategies do not track the Atm strategy's trades/performance and the Atm strategy methods will have to be used to obtain this information.

        Custom code will have to be added to your strategy to keep track of the Atm strategy ID's and then you can accumulate the realized PnL using GetAtmStrategyRealizedProfitLoss when the Atm strategy is no longer active.

        Unrealized PnL can be calculated with GetAtmStrategyUnrealizedProfitLoss.

        The SampleAtmStrategy NinjaScript strategy that comes bundled with NinjaTrader shows an example for how GetAtmStrategyUnrealizedProfitLoss can be used. You may wish to place a call to GetAtmStrategyRealizedProfitLoss at the beginning of OnBarUpdate() in a duplicate strategy so you can observe the strategy print the realized PnL of the AtmStrategy before a new AtmStrategyID is created for a new instance of an ATM strategy.

        I've included a demo as well reviewing how the SampleAtmStrategy NinjaScript strategy uses these methods.

        Demo - https://drive.google.com/file/d/1-hp...w?usp=drivesdk

        I'll include our documented Atm Strategy in NinjaScript resources for the thread's reference:

        Atm Strategy Methods - https://ninjatrader.com/support/help...gy_methods.htm

        Using Atm Strategies with NinjaScript Strategies - https://ninjatrader.com/support/help...strategies.htm

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by MarthaClines, Today, 06:20 PM
        0 responses
        7 views
        0 likes
        Last Post MarthaClines  
        Started by Irukandji, 05-09-2019, 04:28 AM
        38 responses
        298 views
        0 likes
        Last Post nkhoi
        by nkhoi
         
        Started by manugarc, Today, 01:15 PM
        0 responses
        11 views
        0 likes
        Last Post manugarc  
        Started by JMont1, Today, 11:42 AM
        0 responses
        9 views
        0 likes
        Last Post JMont1
        by JMont1
         
        Started by Steve L, Yesterday, 10:04 PM
        0 responses
        4 views
        0 likes
        Last Post Steve L
        by Steve L
         
        Working...
        X