Thanks. I will continue to search in the help section to see if its in there.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to stop a strategy after a daily profit target is reached.
Collapse
X
-
How to stop a strategy after a daily profit target is reached.
Is there a way to stop a trading strategy after a daily profit target is reached. For instance after 4 ticks/$$$/%. I know there is one for each individual trade, but what about for a daily limits?
Thanks. I will continue to search in the help section to see if its in there.Tags: None
-
Hello olingerc,
For this you can work with Trade Performance class and reset values for each day.
This sample is pretty close to what you're looking for:
Ryan M.NinjaTrader Customer Service
-
You should be able to import that sample in either version. It sounds like you are missing the variable declaration.
#region Variables
private int priorTradesCount = 0;
private double priorTradesCumProfit = 0;
#endregion
You can custom code MFE if you want it calculated while you're in a trade:
Understanding Average MFE
Where MFE (max. favorable excursion) is defined as (best price trade reached – entry price), quantity is defined as the number of contracts traded, and point value is defined as the monetary conversion of each point (e.g. 100 for currency pairs).
Example with long position:
if (Position.MarketPosition == MarketPosition.Long)
myDouble = High[BarsSinceEntry()] - Position.AvgPrice;Ryan M.NinjaTrader Customer Service
Comment
-
Ryan I am having trouble with this till. I believe I have the correct code in the correct location but during a back test it does not calculate. I can set the profit target to lets say 10,000 and during a back test it will only test up to 10,000 and nothing after. or if its 1000 it would test until a profit of 1,000 is met and nothing after. Why is this so? If I set it to RealtimeTrades would it only calculate the current day's live account information?
How do I get my strategy to exit during the intraday after lets say a profit of 1,000 is reached.
This is what I have so far
// At the start of a new session
if (Bars.FirstBarOfSession)
{
// Store the strategy's prior cumulated realized profit and number of trades
priorTradesCount = Performance.AllTrades.Count;
priorTradesCumProfit Performance.AllTrades.TradesPerformance.Currency.C umProfit;
// NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
//If you want to only count profits from real-time trades please use .RealtimeTrades.
}
//Prevents further trading if the current session's realized profit exceeds $1000
if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit >= 1000)
{
//TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well.
// Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
return;
}Last edited by olingerc; 05-06-2011, 03:03 PM.
Comment
-
Code looks OK and I don't see where you are deviating from the sample at all. just ran the sample here and it's working as expected. You have more than one session, right?
In a backtest there are no real time trades so that won't work for you. Attach the script (exported zip file) you're using and screenshots of your backtest setup and will give it a run here.Ryan M.NinjaTrader Customer Service
Comment
-
Yes I was having issues with the back testing. No changes were showing up during a back test. Assuming I change it to RealtimeTrades it would actually work live during a intraday cession. But unfortunately if I cant back test this then I am not willing to spend months of playing around with a live account only to realize that I would of made more money if I just hadn't done it to begin with.
Comment
-
I know this is an old thread, but in case anyone else comes along...
IncludeTradeHistoryInBacktest = true;
That should fix the issue OP was experiencing.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ZenCortexCLICK, Today, 04:58 AM
|
0 responses
1 view
0 likes
|
Last Post Today, 04:58 AM | ||
Started by sidlercom80, 10-28-2023, 08:49 AM
|
172 responses
2,279 views
0 likes
|
Last Post
by sidlercom80
Today, 04:40 AM
|
||
Started by Irukandji, Yesterday, 02:53 AM
|
2 responses
17 views
0 likes
|
Last Post
by Irukandji
Today, 03:55 AM
|
||
Started by adeelshahzad, Today, 03:54 AM
|
0 responses
4 views
0 likes
|
Last Post
by adeelshahzad
Today, 03:54 AM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
3 responses
13 views
0 likes
|
Last Post Yesterday, 11:58 PM |
Comment