Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Linear Regression CrossOver with Offset | Entry and Exit orders
Collapse
X
-
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!
Tags: None
-
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<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
- Likes 1
-
Originally posted by NinjaTrader_BrandonH View PostHello 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
-
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<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Thanks, this did help me get it to complie, but for some reason it's not plotting correctly nor executing any orders.Originally posted by NinjaTrader_BrandonH View PostHello 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
I'll have to dive deeper into this and come back with an update.
Comment
-
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.
<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|
Comment