Announcement

Collapse
No announcement yet.

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.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X