Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Grok3 tried to help but not working :-(

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

    Grok3 tried to help but not working :-(

    Below is a code that I'm trying to covert from ThinkorSwim.
    It's anchored VWAP with manual input of anchoring location (date and time).
    Grok3 converted this for NT8 but I can't compile.
    Can someone make it error free?

    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    // This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    [NinjaScriptType]
    public class MyCustomIndicator : Indicator // Changed class name to match file
    {
    private double cumulativeValue; // Sum of (price * volume)
    private double cumulativeVolume; // Sum of volume

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Calculates an Anchored VWAP starting from a specific date and time.";
    Name = "MyCustomIndicator"; // Updated to match class name
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    PaintPriceMarkers = true;

    // Initialize default anchor date and time (July 1, 2019, 9:30 AM)
    AnchorDate = new DateTime(2019, 7, 1);
    AnchorTime = new TimeSpan(9, 30, 0);

    AddPlot(new Stroke(Brushes.Cyan, 3), PlotStyle.Line, "VWAP");
    }
    else if (State == State.DataLoaded)
    {
    cumulativeValue = 0;
    cumulativeVolume = 0;
    }
    }

    protected override void OnBarUpdate()
    {
    // Combine date and time of the current bar into a single DateTime
    DateTime barDateTime = Time[0];

    // Combine anchor date and time into a single DateTime
    DateTime anchorDateTime = AnchorDate.Date.Add(AnchorTime);

    // Check if the current bar is on or after the anchor date and time
    if (barDateTime >= anchorDateTime)
    {
    // Calculate typical price as (high + low + close) / 3
    double typicalPrice = (High[0] + Low[0] + Close[0]) / 3.0;

    // Add to cumulative sums
    cumulativeValue += typicalPrice * Volume[0];
    cumulativeVolume += Volume[0];
    }

    // Calculate and plot VWAP if there's volume, otherwise set to double.NaN
    if (cumulativeVolume > 0)
    {
    Values[0][0] = cumulativeValue / cumulativeVolume;
    }
    else
    {
    Values[0][0] = double.NaN;
    }
    }

    region Properties
    [NinjaScriptProperty]
    [Display(Name = "Anchor Date", Description = "Date to start VWAP calculation", Order = 1, GroupName = "Parameters")]
    [PropertyEditor("NinjaTrader.Gui.Tools.DateEditor")]
    public DateTime AnchorDate { get; set; }

    [NinjaScriptProperty]
    [Display(Name = "Anchor Time", Description = "Time to start VWAP calculation", Order = 2, GroupName = "Parameters")]
    [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditor")]
    public TimeSpan AnchorTime { get; set; }
    #endregion
    }
    }​​

    #2
    Hello kalalex,

    If you would like assistance with a compile error, provide the full error message (or a screenshot of the full error message).


    This thread will remain open for any community members that would like to debug your code as a convenience to you.

    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 a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks.
      I found another solution.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X