Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

USD Value for Chart Bracket Orders

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

    USD Value for Chart Bracket Orders

    I'm trying to create an indicator or strategy that will display the dollar value of my risk and profit bracket orders based on my position size, so as I add to my position and I move my Stop Loss order, I can always see the actual USD risk amount. I tried using ChatGPT to generate the code but I keep getting error codes.

    Here's the code:

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

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class BracketValueStrategy : Strategy
    {
    private double stopDollarValue;
    private double profitDollarValue;

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name = "Stop Loss Ticks", Order = 1, GroupName = "Parameters")]
    public int StopLossTicks { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name = "Profit Target Ticks", Order = 2, GroupName = "Parameters")]
    public int ProfitTargetTicks { get; set; }

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Displays the dollar value of the bracket stop and profit levels.";
    Name = "BracketValueStrategy";
    Calculate = Calculate.OnEachTick;
    }
    }

    protected override void OnBarUpdate()
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    return;

    double entryPrice = Position.AveragePrice;
    double stopPrice = entryPrice - (StopLossTicks * TickSize);
    double profitPrice = entryPrice + (ProfitTargetTicks * TickSize);

    stopDollarValue = (entryPrice - stopPrice) * Instrument.MasterInstrument.PointValue;
    profitDollarValue = (profitPrice - entryPrice) * Instrument.MasterInstrument.PointValue;

    Print($"Stop Value: ${stopDollarValue:N2}");
    Print($"Profit Value: ${profitDollarValue:N2}");
    Print($"Stop Level: {stopPrice}, Profit Level: {profitPrice}");
    }

    // ✅ Fully Corrected OnOrderUpdate Method
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, OrderState orderState, DateTime time)
    {
    if (order == null) return;

    Print($"Order Update - ID: {order.OrderId}, State: {orderState}, Time: {time}");
    }

    // ✅ Fully Corrected OnExecutionUpdate Method
    protected override void OnExecutionUpdate(Execution execution, Order order)
    {
    if (execution == null || order == null) return;

    Print($"Execution Update - Order ID: {order.OrderId}, Price: {execution.Price}, Quantity: {execution.Quantity}");
    }
    }
    }


    This is the error codes I'm getting:

    NinjaScript File,Error,Code,Line,Column,
    BracketValueIndicator.cs,'BracketValueStrategy.OnO rderUpdate(Order double double OrderState)': no suitable method found to override,CS0115,56,33,
    BracketValueIndicator.cs,'BracketValueStrategy.OnE xecutionUpdate(Execution Order)': no suitable method found to override,CS0115,64,33,
    ​​

    #2
    Hello wbateman3,

    While we cannot help with AI generated code you can post specific questions about certain syntax or errors you are having. If you have a question about a specific line/error we can try to assist.

    From our experience at this time, ChatGpt and other AI models are not adequate at generating valid NinjaScript code that function as the user has intentioned. We often find that these tools generate code that will call non-existent properties and methods, use improper classes or inheritance, and may have incorrect logic. Using these tools for general NinjaScript learning information may also provide incorrect responses. We highly encourage that you create a new NinjaScript yourself using the NinjaScript Editor and avoid any AI based coding tools.

    While it would not be within our support model to assist with scripts generated or checked by ai tools, we would be happy to provide insight for any direct specific inquiries you may have if you would like to create this script yourself. Our support is able to assist with finding resources in our help guide as well as simple examples, and we are happy to provide guidance on how you can debug the script while running it on your machine. To start learning NinjaScript I would suggest the following link as a starting point.


    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.​

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    553 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
    100 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    543 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    546 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X