Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss Failure

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

    SetStopLoss Failure

    Hallo, I would like to use the SetStopLoss function and implemented it with a signal name as follows:

    ---
    private string longEnter;
    ----
    EnterLong("longEnter");

    SetStopLoss(longEnter,CalculationMode.Percent, 1, false);

    Now I get an error, if I apply this strategy in a backtest. The message says "Object reference not set to an instance of an object".

    I do not understand why I need an instanz. Does anyone can give me a hint.

    Thanks

    #2
    Hello,

    Thank you for the question.

    It looks like you have not assigned the string a value.

    Code:
    private string longEnter
    this would need to instead be

    Code:
    private string longEnter = "EnterLong";

    Or better yet you do not need this variable at all as you could use:

    Code:
    EnterLong("SignalNameCanBeAnything");

    a string is defined simply by being inside " "

    any method that asks for a string you would just need "text inside quotes"


    Please try this and let me know if you are still getting errors.

    I look forward to being of further assistance.

    Comment


      #3
      Thanks Jesse, that solved my backtesting failurem but the SetStopLoss still does not work. I integrated the SetStopLoss as follows:

      protected override void Initialize()
      {
      SetStopLoss(CalculationMode.Ticks, 20);
      CalculateOnBarClose = true;
      }
      But the strategy stops a trade at the moment I enter the trade, no matter hwy ticks I enter. Where is my mistake?

      Thanks

      Comment


        #4
        Hello,

        Thank you for the question,

        I would like to ask is this happening in the back test or on a chart?

        Also have you tried this with live data or in the simulation or market replay connections ?

        It may be helpful to see a screenshot as well to see where this is happening in your NinjaTrader.

        I look forward to being of further assistance.

        Comment


          #5
          Jesse, I just wrote a simple strategy that I use for some backtesting. Please see the enclosed screenshot. Thanks
          Attached Files

          Comment


            #6
            Originally posted by phadreus View Post
            Jesse, I just wrote a simple strategy that I use for some backtesting. Please see the enclosed screenshot. Thanks
            Entry: 9536,38
            StopExit: 9534,38

            Difference: 2,00

            Is that not 20 ticks for the instrument that you have on the chart?

            Comment


              #7
              phadreus, I think koganam is right here, the Dax index chart used has a ticksize of 0.01 so 20 ticks is 2 pts which your backtest correctly shows. This is not the FDAX here, where 20 ticks would be 10 pts.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by charlesugo_1, 05-26-2026, 05:03 PM
              0 responses
              65 views
              0 likes
              Last Post charlesugo_1  
              Started by DannyP96, 05-18-2026, 02:38 PM
              1 response
              149 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by CarlTrading, 05-11-2026, 05:56 AM
              0 responses
              162 views
              0 likes
              Last Post CarlTrading  
              Started by CarlTrading, 05-10-2026, 08:12 PM
              0 responses
              99 views
              0 likes
              Last Post CarlTrading  
              Started by Hwop38, 05-04-2026, 07:02 PM
              0 responses
              286 views
              0 likes
              Last Post Hwop38
              by Hwop38
               
              Working...
              X