Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Linear Regression CrossOver with Offset | Entry and Exit orders

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

    Linear Regression CrossOver with Offset | Entry and Exit orders

    I cant for the life of me figure out how to create and entry and exit order using LinReg CrossAbove and LinReg CrossBelow with an offset. Please HELP!

    #2
    Hello osmanigarces,

    Thanks for your post and welcome to the NinjaTrader Forums!

    So we may accurately assist, could you please provide us with an example of the CrossAbove and CrossBelow condition you are trying to create in your strategy?

    For information about creating crossover condition and offsetting values, you could view the help guide documentation below.

    Strategy Builder Condition Builder: https://ninjatrader.com/support/help...on_builder.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello osmanigarces,

      Thanks for your post and welcome to the NinjaTrader Forums!

      So we may accurately assist, could you please provide us with an example of the CrossAbove and CrossBelow condition you are trying to create in your strategy?

      For information about creating crossover condition and offsetting values, you could view the help guide documentation below.

      Strategy Builder Condition Builder: https://ninjatrader.com/support/help...on_builder.htm

      Hi Brandon,

      Here is the example of the script I'm using. Im am trying to place the entry and exit order of a linregintercept and lingreg cross over. However the cross over works best for me with an offset and I am unable to figure how to offset them.

      When building the indicators on the chart you are able to offset both very easily from the UI but when using the building and choosing any crossover it disables the offet option.

      IsInstantiatedOnEachOptimizationIteration = true;
      Period_1 = 28;
      Period_2 = 25;
      }
      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Second, 30);
      }
      else if (State == State.DataLoaded)
      {
      LinRegIntercept1 = LinRegIntercept(Open, Convert.ToInt32(Period_1));
      LinReg1 = LinReg(Open, Convert.ToInt32(Period_2));
      LinRegIntercept1.Plots[0].Brush = Brushes.Navy;
      LinReg1.Plots[0].Brush = Brushes.Crimson;
      AddChartIndicator(LinRegIntercept1);
      AddChartIndicator(LinReg1);
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;

      // Set 1
      if ((CrossAbove(LinRegIntercept1, LinReg1, 1)) // Here I'm trying to offset the LinRegIntercept by -1 and the LinReg by +1

      {
      EnterLong(1, @"long");
      }

      // Set 2
      if ((CrossBelow(LinRegIntercept1, LinReg1, 1)) // Here I'm trying to offset the LinRegIntercept by -1 and the LinReg by +1

      {
      ExitLong(1, @"close long", "");
      }

      }​​

      Comment


        #4
        Hello osmanigarces,

        Thanks for your notes.

        To accomplish this you would need to create a custom Series variable called something like "LinRegIntercept1Offset" and assign the LinRegIntercept1 + the offset to the custom Series variable.

        A custom Series variable would also be needed to offset LinReg.

        Then, you could use those custom Series in your CrossAbove condition.

        You would need to also create a custom Series variable for the CrossBelow condition. Assign the LinRegIntercept1 - 1 offset to the custom Series, then use that custom Series for your CrossBelow condition.

        On this forum thread you could find an example script demonstrating this concept:
        Sorry if this has been addressed but I searched and could not find the answer. I'm sure I'm missing something simple. I'm trying to set an offset to a EMA crossover. So for example I would like to place a buy order when the 3EMA crosses above the 10EMA + 1.00. The wizzard does not seem to add the offset to the code, and NT8


        Series<T> Help Guide: https://ninjatrader.com/support/help...t8/seriest.htm
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello osmanigarces,

          Thanks for your notes.

          To accomplish this you would need to create a custom Series variable called something like "LinRegIntercept1Offset" and assign the LinRegIntercept1 + the offset to the custom Series variable.

          A custom Series variable would also be needed to offset LinReg.

          Then, you could use those custom Series in your CrossAbove condition.

          You would need to also create a custom Series variable for the CrossBelow condition. Assign the LinRegIntercept1 - 1 offset to the custom Series, then use that custom Series for your CrossBelow condition.

          On this forum thread you could find an example script demonstrating this concept:
          Sorry if this has been addressed but I searched and could not find the answer. I'm sure I'm missing something simple. I'm trying to set an offset to a EMA crossover. So for example I would like to place a buy order when the 3EMA crosses above the 10EMA + 1.00. The wizzard does not seem to add the offset to the code, and NT8


          Series<T> Help Guide: https://ninjatrader.com/support/help...t8/seriest.htm
          Thanks, this did help me get it to complie, but for some reason it's not plotting correctly nor executing any orders.

          I'll have to dive deeper into this and come back with an update.

          Comment


            #6
            Hello osmanigarces,

            Thanks for your notes.

            To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

            In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Also, add prints that print out the value being assigned to the plot and print out the plot value after assigning a value to it to see how it is evaluating.

            Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

            ​Below is a link to a forum post that demonstrates how to use prints to understand behavior.


            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            17 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            5 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,786 views
            0 likes
            Last Post Leafcutter  
            Started by poplagelu, Today, 05:00 AM
            0 responses
            3 views
            0 likes
            Last Post poplagelu  
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,408 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Working...
            X