Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
End Strategy on Realized Profit
Collapse
X
-
lvaduva,
This can be done through custom programming. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=4084Josh P.NinjaTrader Customer Service
-
I tried
if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit >= 130 || Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit <= 500)
{
return;
}
I tried the above code in simulation trading and it does not stop strategy upon 130 profit....is there anything wrong in the code. I followed the example put in the link
Comment
-
Code
The code is doing what it is suppose to but the strategy does not stop it keeps trading. Can you see if you can find bug?Attached Files
Comment
-
lvaduva, try placing the code snippet to stop trading before all the other parts of the strategy, not after.
Code:protected override void OnBarUpdate() { if(Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit > 130 || Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit < -500) return; // the rest of your code goes here }AustinNinjaTrader Customer Service
Comment
-
Thanks Ausitn that works great. Now one last question, if I wanted to run this in backtest, do I need to change .RealtimeTrades. to something else?
I was also curious, in backtest if I choose to trade only between 9am and 4pm are the ema averages affected by this versus if I choose 12am to 12am?
Comment
-
In backtest, you could try .AllTrades.
Depends how you decide to limit the time. If you limit it by Start/End times of the sessions then the EMAs will only be calculated based on that time range. If you limit trading through code but leave start/end as 12am-12am then the EMAs will not be limited.Josh P.NinjaTrader Customer Service
Comment
-
I have a problem in backtesting. While in back testbacktest I would like to have the strategy evaluated such that once a price target is hit or a stop loss target is hit daily in the back test, the strategy would stop trading untill the next day and then begin again. Here is what I coded, but this makes the strategy take only one trade and then stops in the backtest. How can I modify so that it continues as outlined above for the whole time period, about a month?
protectedoverridevoid OnBarUpdate()
{
// At the start of a new session
if ((ToTime(Time[0]) >= 90000 && ToTime(Time[0]) < 160000))
{
if(Performance.AllTrades.TradesPerformance.Currency. CumProfit > 200 || Performance.AllTrades.TradesPerformance.Currency.C umProfit < -1350)
{
return;
}
// Condition set 1
if (CrossAbove(EMA(Median, 4), SMA(Median, 21), 1) && Position.MarketPosition == MarketPosition.Flat)
{
EnterLong(DefaultQuantity, "");
}
}
}
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment