Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Ema crossover
Collapse
X
-
Ema crossover
I have a strategy where let’s say it will go long or short when it crosses at 30 ema. But whenever I start the strategy is will automatically enter depending on where price is. So if it’s 4 bars below the ema it will go short even though the crossover already happened before I got on or vice versa. I would like for it to wait until a crossover happens not going in based on the crossover that happened before I got onTags: None
-
Hello Str8boominit,
Thank you for your post.
A Strategy Position is a virtual position that is created by the entry and exit executions generated by a strategy, which can calculate its position based on historical market data.
If you do not wish to have the strategy to calculate the position historically, you may use the following lines of code at the top of the OnBarUpdate() method:
Please let me know if I may be of any further assistance.Code:if(State == State.Historical) return;
-
I keep getting cs0103 the name return does not exist in the current context and cs0201 only assignment call increment decrement await and new object expressions can be used as a statment
Comment
-
Originally posted by NinjaTrader_Eduardo View PostHello Str8boominit,
Thank you for your post.
A Strategy Position is a virtual position that is created by the entry and exit executions generated by a strategy, which can calculate its position based on historical market data.
If you do not wish to have the strategy to calculate the position historically, you may use the following lines of code at the top of the OnBarUpdate() method:
Please let me know if I may be of any further assistance.Code:if(State == State.Historical) return;
I keep getting cs0103 the name return does not exist in the current context and cs0201 only assignment call increment decrement await and new object expressions can be used as a statment
Comment
-
Ok nevermind I got it to compile but it still enters when nowhere near a crossoverOriginally posted by NinjaTrader_Eduardo View PostHello Str8boominit,
Please post a screenshot of the compile errors along with the lines of code referenced in the errors.
I look forward to assisting you further.
Comment
-
-
Hello Str8boominit,
To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects 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 date time of the bar and all values compared in every condition that places an order.
The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.
The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.
Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).
Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.
I am happy to assist you with analyzing the output from the output window.
Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.
Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
111 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
59 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
38 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
42 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
78 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment