Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Market Analyzer Watermark High & Low Columns

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

    Market Analyzer Watermark High & Low Columns

    I am trying to add columns to indicate Hight & Low Watermarks for each instrument as well as the total of all. While testing strategies, I would like to see the lowest of lows and the highest of highs; not just the end result. I actually got the script to compile but cant seem to actually get it to print the numbers in Market Analyzer. Not sure if this is the right section but this is more of an indicator to me so here goes. I have uploaded my script and would appreciate any help or direction. FYI, the attached is modified to run using Playback101 account information since the practical attack is during Strat Testing. I will have to modify the script to work in real time.

    Click image for larger version

Name:	image.png
Views:	40
Size:	26.6 KB
ID:	1334090

    Thanks!

    Bob
    Last edited by 6bobclose5; 02-09-2025, 08:36 AM.

    #2
    Hello Bob,

    The script would need to be a MarketAnalyzerColumn script or an indicator with a plot added and the Value[0] assigned a value on each bar update.
    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.



    Note, the script you have provided is a strategy which cannot be used in the Market Analyer.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      It is nested under MarketAnalyzerColumns. Guess I screwed up. I will work on it some more. Thanks for the direction.

      Click image for larger version

Name:	image.png
Views:	27
Size:	418.6 KB
ID:	1334190

      Comment


        #4
        Hello 6bobclose5,

        Moving files in the filesystem can break NinjaTrader.

        Create a new MarketAnalyzerColumn script by right-clicking the MarketAnalyzerColumns folder in the NinjaScript Editor Explorer pane and select New Market Analyzer Column.

        The script you have is a strategy. This is in the NinjaTrader.NinjaScript.Strategies namespace and inherits from Strategy. This is not a market analyzer column script.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks ChelseaB. I have revised based on your comments above. The script did compile but and has bee added to the Market Analyzer but still not printing. Below is my revised script and the act MA:

          region Using declarations
          using System;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript.MarketAnalyzerColumns;
          #endregion

          namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
          {
          public class TradeWatermarksColumn : MarketAnalyzerColumn
          {
          private double highWatermark = double.MinValue;
          private double lowWatermark = double.MaxValue;
          private Account myAccount;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Name = "Trade Watermarks";
          Description = "Tracks the highest and lowest unrealized P&L during a trade.";
          }
          else if (State == State.Configure)
          {
          // Find the correct account manually
          foreach (Account acc in Account.All)
          {
          if (acc.Name == "Sim LunchBot") // Updated to use "Sim LunchBot"
          {
          myAccount = acc;
          break;
          }
          }
          }
          }

          protected override void OnMarketData(MarketDataEventArgs e)
          {
          if (myAccount == null || myAccount.Positions == null)
          return;

          double totalUnrealized = 0;

          foreach (var position in myAccount.Positions)
          {
          if (position.Instrument.FullName == Instrument.FullName && position.MarketPosition != MarketPosition.Flat)
          {
          totalUnrealized += position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, e.Price);
          }
          }

          if (totalUnrealized > highWatermark)
          highWatermark = totalUnrealized;
          if (totalUnrealized < lowWatermark)
          lowWatermark = totalUnrealized;

          // Update the Market Analyzer column with separate high and low watermarks per instrument
          Value[0] = highWatermark - lowWatermark;
          }
          }
          }

          Click image for larger version

Name:	image.png
Views:	35
Size:	21.5 KB
ID:	1334208

          Comment


            #6
            Hello 6bobclose5,

            A print called with the Print() method will appear in the NinjaScript Output window.


            A MarketAnalyzerColumn must have the CurrentValue set to show the set value.

            Please be sure you have read through the documentation for a MarketAnalyzerColumn.
            Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by MatthewLesko, Today, 07:38 AM
            0 responses
            3 views
            0 likes
            Last Post MatthewLesko  
            Started by several, 03-18-2025, 03:53 AM
            13 responses
            198 views
            1 like
            Last Post timko
            by timko
             
            Started by IDumpedCinderella, 03-12-2025, 11:34 PM
            3 responses
            59 views
            0 likes
            Last Post WaleeTheRobot  
            Started by fersanmito, Today, 03:45 AM
            0 responses
            10 views
            0 likes
            Last Post fersanmito  
            Started by kevinenergy, 11-28-2023, 11:04 AM
            3 responses
            78 views
            0 likes
            Last Post NinjaTrader_Jason  
            Working...
            X