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 argusthome, Yesterday, 10:06 AM
              0 responses
              17 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              16 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              14 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              9 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              38 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X