Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy not working
Collapse
X
-
Strategy not working
I am attempint to write my first strategy in Ninjatrader 7 and nothing happens. I used a bunch of print statements to see if i could pin point the problem but what i found out was that none of my codes are working, I even wrote the simpliest one line code with a print statement and nothing gets printed to the output window, This is my first strategy in N7 but i have wrote a couple custom indicator in N7 without problem. Whats going on ?Tags: None
-
I had just started writing a couple lines when I notice this problem so I strip it down to a simple one line (below) and still nothing happens. This should be printing to the output window right ?
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Close[1] > High[2] )
{
got = 1;
PrintWithTimeStamp(" nmnm");
}
}
}
Comment
-
trader413, you are running into the issue where you're trying to check the price of a bar that doesn't exist.
Please try this instead:
Code:protected override void OnBarUpdate() { if (CurrentBar < 3) return; if (Close[1] > High[2] ) { PrintWithTimeStamp(" nmnm"); } }AustinNinjaTrader Customer Service
Comment
-
trader413, how exactly are you testing this strategy? Are you running it on a chart? From the strategy tab? In the Strategy Analyzer? Market Replay? What instrument are you using and what timeframe/session template? What data provider are you using?
If you could list out exactly what you're doing, I will try it out and see what is going wrong.AustinNinjaTrader Customer Service
Comment
-
Ok Its now fixed, the yellow highlighted box was set to disable. Thanks
Another problem
protected override void Initialize()
{
SetStopLoss("NSE1", CalculationMode.Ticks, 12, false);
SetProfitTarget("NSE1", CalculationMode.Price, TP);
CalculateOnBarClose = false;
TraceOrders = true ;
}
protected override void OnBarUpdate()
{
TP = targetprice - targetprice % TickSize + ((targetprice % TickSize < TickSize/ 2) ? 0.0 : TickSize);
Print(TP);
Why isn't my target getting hit ? "targetprice" is a variable being output by an indicator
Comment
-
trader413,
No worries. This should be a straightforward problem to address. You will not be able to dynamically change your profit target price by only changing the TP variable. If you want to change your profit target price you would need to call SetProfitTarget() again. This reference sample should be of value on doing just that: http://www.ninjatrader.com/support/f...ead.php?t=3222Josh P.NinjaTrader Customer Service
Comment
-
Are you sure ? I have a couple old strategy in version 6 in which I used this method to change my profit target. Did something changed in version 7 ?
And another thing, this profit target will be changing throughout the trading day. So I am looking to have a dynamic Target and stop.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
656 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
371 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment