Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

error in private IOrder stopOrder . can't implicitly convert the void type

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

    error in private IOrder stopOrder . can't implicitly convert the void type

    Oh, hello. Thank you for your time. Excuse my English.
    I have this code that works correctly

    SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[0]- 2*TickSize), false);

    But if I make this modification.

    private IOrder stopOrder = null;

    if (entryOrder != null && entryOrder == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    {

    stopOrder = SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low[0]- 2*TickSize), false);

    }
    }

    gives this error: you can not implicitly convert the void type.
    Would you be so kind as to point me in the right direction? Thank you.




    #2
    Hello julifro,

    Thanks for your post.

    SetStopLoss is a method of type void and does not return an IOrder object. If you would like to have an IOrder object returned, I suggest using one of the Exit methods of the Managed Approach and to follow the SampleOnOrderUpdate strategy for using Exit methods to control your profit target and stop loss instead of using the Set methods.

    Publicly available resources are linked below.

    Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    Please let us know if you have any additional questions.

    Comment


      #3
      Thank you for your quick response.
      Before asking the question I was reading the help on
      SetStopLoss and I didn't read that it was a void method.

      I have written some indicators with easy code but the progression in ninjatrader strategies is very frustrating for me. There is always something that escapes me.

      Do you know of any book or orderly method to master ninjatrader programming? thank you.

      Comment


        #4
        Hello julifro,

        NinjaTrader does not offer any books on NinjaScript. We keep all supported NinjaScript documented in the Help Guide and include some educational resources there as well.

        Educational Resources - https://ninjatrader.com/support/help..._resources.htm

        Language Reference - https://ninjatrader.com/support/help...erence_wip.htm

        If you have any additional ideas on materials that we could include, I'll be happy to track your feedback in a feature request.

        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 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
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X