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

The type or namespace name 'Cbi' could not be found

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

    The type or namespace name 'Cbi' could not be found

    Hi, I am trying to create a strategy whereby 1) I place an MIT order, 2) I place a stoploss and the 3) automatically a take profit market order is placed at a 1:1 risk to reward.

    I don't have any coding experience so have been working with ChatGPT to generate the script.

    So far I have this:

    Code:
    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.NinjaScript.Strategies;
    
    public class MyCustomStrategy : Strategy
    {
    private double entryPrice = 0.0;
    private double stopLossPrice = 0.0;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Places a take profit order with a 1:1 risk-reward ratio upon order fill.";
    Name = "MyCustomStrategy";
    }
    else if (State == State.DataLoaded)
    {
    // Initialization code can go here
    }
    }
    
    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
    int quantity, int filled, double averageFillPrice,
    Cbi.OrderState orderState, DateTime time, ErrorCode error,
    string nativeError)
    {
    if (order.OrderState == OrderState.Filled)
    {
    if (order.OrderType == OrderType.StopMarket || order.OrderType == OrderType.StopLimit)
    {
    stopLossPrice = order.StopPrice;
    }
    else if (order.OrderType == OrderType.MIT)
    {
    entryPrice = order.AverageFillPrice;
    if (stopLossPrice != 0 && entryPrice != 0)
    {
    CalculateAndPlaceTakeProfitOrder();
    }
    }
    }
    }
    
    private void CalculateAndPlaceTakeProfitOrder()
    {
    double riskAmount = Math.Abs(entryPrice - stopLossPrice);
    double takeProfitPrice = entryPrice > stopLossPrice ? entryPrice + riskAmount : entryPrice - riskAmount;
    
    if (entryPrice > stopLossPrice)
    {
    EnterLongLimit(1, takeProfitPrice, "TakeProfitLong");
    }
    else
    {
    EnterShortLimit(1, takeProfitPrice, "TakeProfitShort");
    }
    }
    }
    ​
    But im getting this error on compiling it
    MyCustomStrategy.cs The type or namespace name 'Cbi' could not be found (are you missing a using directive or an assembly reference?) CS0246 23 43
    I cant find that dll anywhere on my PC and haven't been able to find anything on this forum. Please can somone help?

    Thanks
    Dan

    #2
    Hello Aurelius4114,

    Thanks for your post and welcome to the NinjaTrader Forums.

    OnOrderUpdate() is not being called properly in the code you shared.

    In your script you are calling:

    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, ErrorCode error, string nativeError)

    The script should be calling the supported code below seen in the OnOrderUpdate() help guide page linked below.

    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)

    OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm

    That said, from our experience at this time, ChatGPT is not quite adequate to generate valid compilable NinjaScripts that function as the user has intended. We often find that the generated code will call non-existent properties and methods, use improper classes or inheritance, and may have incorrect logic. We highly encourage that you create a new NinjaScript yourself using the NinjaScript Editor, and use the code generated by ChatGPT as more as suggestions and guide when coding the script yourself, than using the actual code generated.

    While It would not be within our support model to correct these scripts at user request, 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 can assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

    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.​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks so much for the quick and informative reply, Brandon. I will look into rewriting the code myself or failing that I may reach out to a NinjaScript consultant.
      Thanks again

      Dan

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      15 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      14 views
      0 likes
      Last Post strategist007  
      Working...
      X