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

Indicator that plots unrealized PnL in Backtesting history

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

    Indicator that plots unrealized PnL in Backtesting history

    I would like to write an Indicator that plots unrealized PnL in Backtesting history. I thought the 'Position Display Indicator' ( https://ninjatraderecosystem.com/use...lay-indicator/ ) would help as an example of how to access the PnL info in an indicator. But it seems not to work with historical or simulated data? (See attached screenshot upper left corner.)
    How can I access the unrealized PnL of an Account (Sim101) in an Indicator (not strategy) to have it plotted?
    I would not like to pass 'Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0])' from the strategy to the indicator because I like to use the strategy builder for the strategy (with keeping code locked) and it seems that the builder cannot pass this argument to an indicator.



    #2
    Hello Trino,

    The Account position cannot be accessed historically. This is something that only updates in real-time.

    The Strategy Position, however can be accessed historically if the strategy is placing historical orders. As you suspected, the Strategy Builder is limited to very simple comparisons. To accomplish this the strategy will need to be unlocked and this complex code will need to be coded by hand.


    You can assign public variables from a strategy. Below is a link to a reference sample that demonstrates.


    If the value being set requires any bar related information, its best to call Update() in the get / set.


    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.


    However, if you are just wanting to draw a drawing object like Draw.TextFixed() on the chart, this could be called directly from the strategy without using an indicator at all.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea B.,
      thank you, your second link seems to deal with plotting from strategies and not assigning public variables. Was that intended or is there another link about assigning public variables?

      Comment


        #4
        Hello Trino,

        In the example SampleStrategyPlot there is a line where a public Strategy property is being set to the instance of the strategy.

        sampleOverlayPlot.Strategy = this;

        In the indicator the public property definition is on lines 59 to 64.

        Other public properties can be set this way. If it involves data, its best to call Update() first.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        19 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        179 views
        0 likes
        Last Post jeronymite  
        Started by ghoul, Today, 06:02 PM
        0 responses
        9 views
        0 likes
        Last Post ghoul
        by ghoul
         
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        13 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Working...
        X