Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Residual in strategy

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

    Residual in strategy

    Hallo,

    I want to use my residual indicator in a strategy. I want to do something if the indicator crossbelow 2. How should I do that?
    I tried somthing like:

    int Variable0 =2;
    ...
    // Condition set 1
    if (CrossBelow(SpreadPlot2(10, 1, 10, "").Upper, Variable0, 10))
    {
    PrintWithTimeStamp("works");
    }

    But there occurs nothing in the output window.
    Thank you in advance.
    Benjamin

    #2
    bascher,

    Can we see some code for the SpreadPlot2 indicator? Its possible that this would never cross below 2, for example if the tick size is small.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hallo Adam,

      thank you for your reply. I have got the following code:

      #region Variables
      // Wizard generated variables
      private int Variable0 = 1;
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      /// </summary>
      protected override void Initialize()
      {

      CalculateOnBarClose = true;
      // Add the second instrument
      Add("$USDCAD", PeriodType.Minute, 1);
      // Add the indicator with the values period=10, MyInput0=1, Frequency=10
      //and second instrument=$USDCAD
      Add(SpreadPlot2(10, 1, 10, "$USDCAD"));
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      // If SpreadPlot indicator cross below Variable0=1 print to outputwindow="works"
      if (CrossBelow(SpreadPlot2(10, 1, 10, "$USDCAD"), Variable0, 1))
      {
      PrintWithTimeStamp("works");
      }
      }

      But it happens nothing.
      What I have to change?
      Thank you in advance.
      Best regards
      Benjamin

      Comment


        #4
        Hello,

        I would suggest trying this :

        Variable0 = 2*TickSize;
        if (CrossBelow(SpreadPlot2(10, 1, 10, "$USDCAD"), Variable0, 1))
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          The condition variable is correct but I am not sure how to call the indicator and in which order this should be done.

          Comment


            #6
            bascher,

            I suspect that the following is the issue here :

            CrossAbove(SpreadPlot2(10, 1, 10, "$USDCAD"), Variable0, 1)

            This may never occur. The Variable0 = 2 will make the CrossAbove check to see if the spread calculation crosses above 2. Generally, spreads are Price1 - Price2 and will be something like 0.001 or something to that effect.

            Does your spread indicator convert to ticks? What values does the Spread indicator output?
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Attached is the output of my SpreadPlot indicator. There occurs nothing if cross below the value 1.I tried:
              protected override void OnBarUpdate()
              {
              // Condition set 1
              if (CrossBelow(SpreadPlot2(10, 1, 10, "").Plot0, Variable0, 1))
              {
              Print("funktioniert");
              }
              }
              because .Plot0 is the property of the indicator
              public DataSeries Plot0
              {
              get { return Values[0]; }
              }

              Values refered to:
              if(outputStarted)
              Value.Set(output);
              Print(output);
              ???
              and this is printed as:

              Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));

              But without any success.
              Attached Files

              Comment


                #8
                bascher,

                You tried using Variable0 = 1?

                In that example you showed me the value of spread doesn't seem like it ever reached 2.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  I have changed this value to 1.
                  Can I send you the indicator an you will take a look?

                  Comment


                    #10
                    bascher,

                    I can take a look, but I would need the spread indicator and your strategy. We don't typically offer full debugging assistance however if its simple we don't mind taking a peek and seeing if something is immediately obvious.

                    You can send it to support at ninjatrader dot com with ATTN : Adam in the message.
                    Adam P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    633 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    567 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X