Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Daily loss limit examples
Collapse
X
-
Originally posted by NinjaTrader_ChelseaB View Post
-
Hi tkaboris, thanks for writing in. Its best to override OnPositionUpdate because this event triggers when there is any change in the strategy position. It can be done in OnOrderUpdate but you would need some extra steps such as checking the current and last position held, also checking if the order is an exit order or an entry order, and so on. You can add OnPositionUpdate to your script.
Leave a comment:
-
in my strategy there is no ONPositionUpdate, only onORderupdate. Can this logic that is below be used in onOrderUdate instread?
I want to add daily stop loss limit
protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
{
if (Position.MarketPosition == MarketPosition.Flat && SystemPerformance.AllTrades.Count > 0)
{
// when a position is closed, add the last trade's Profit to the currentPnL
currentPnL += SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;
// print to output window if the daily limit is hit
if (currentPnL <= -LossLimit)
{
Print("daily limit hit, no new orders" + Time[0].ToString());
}
}
}
Leave a comment:
-
Hello grimes12 and Steve4616,
Thanks for your notes.
grimes12:
"what is the difference between the "Daily Loss Limit Example_NT8" and "Daily Loss Limit MultiTrade Example_NT8"?"
DailyLossLimitMultiTradeExample calls EnterLong() multiple times using separate signal names ("long1" and "long2"). DailyLossLimit_NT8 calls EnterLong() once using one signal name ("long1"). This could be seen by viewing and comparing each script's code and noting the differences between the two.
Steve4616:
" should it close the current position when it hits that target? Also, the default number is 100, is that ticks? Points? or Dollars?"
When the CrossAbove condition becomes true and CurrentBars is greater than 20 and DailyPNL is greater than DailyLoss, the strategy will call EnterLong() to place a long Entry order. When the CrossBelow condition becomes true and CurrentBars is greater than 20 and DailyPNL is greater than DailyLoss, the strategy will call EnterShort() to reverse positions so that you end up in a short position.
The DailyLoss default value refers to currency (Dollars).
"under set 4 it says "CurrentBars{Default input} >20". What is the purpose of this statement?"
This condition checks if the CurrentBars value is greater than 20 to ensure that at least 20 bars have been processed before trades are placed.
Let me know if I may further assist.
Leave a comment:
-
Originally posted by Steve4616 View Post
With the "DailyLossLimitBuilderExample_NT8" should it close the current position when it hits that target? Also, the default number is 100, is that ticks? Points? or Dollars? Thanks
Leave a comment:
-
Originally posted by NinjaTrader_ChelseaB View PostHello,
I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8.
These are often requested and I felt they are good examples to have for NT8.
DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241
DailyLossLimitMultiTradeExample_NT7 - http://ninjatrader.com/support/forum...367#post475367
Update Sep 4th, 2018:
- I realized the print in OnPositionUpdate should print when currentPnL is equal to less than the LossLimit, not just less than it.
Update July 13th, 2020:
- Added DailyLossLimitBuilderExample_NT8; NinjaTrader_PaulH was clever enough to realize the Strategy Builder custom series can be used with offsets to do math and subtract the total pnl from yesterdays pnl to get the current pnl and provided an example.
Leave a comment:
-
Originally posted by NinjaTrader_BrandonH View PostHello afisher1965 and grimes12,
Thanks for your notes.
afisher1965:
You could download and view the DailyLossLimit example scripts created by my colleague Chelsea attached in post # 1 on page 1 of this forum thread.
grimes12:
First, download the example script from post # 1 on page 1 of this forum thread. After downloading the file, open NinjaTrader and go to Tools > Import > NinjaScript Addon. To use the strategy, open a New > Chart window and enable the strategy on the chart. Note that this is a sample script demonstrating the concept of how to code a daily loss limit in a NinjaScript. This is not a fully functioning out-of-the-box strategy.
See this help guide page: https://ninjatrader.com/support/help...t_strategy.htm
Let me know if I may assist further.
But what is the difference between the "Daily Loss Limit Example_NT8" and "Daily Loss Limit MultiTrade Example_NT8"? When I load both strategies, I same no difference in terms of properties. Please help me understand.
Leave a comment:
-
Hello afisher1965 and grimes12,
Thanks for your notes.
afisher1965:
You could download and view the DailyLossLimit example scripts created by my colleague Chelsea attached in post # 1 on page 1 of this forum thread.
grimes12:
First, download the example script from post # 1 on page 1 of this forum thread. After downloading the file, open NinjaTrader and go to Tools > Import > NinjaScript Addon. To use the strategy, open a New > Chart window and enable the strategy on the chart. Note that this is a sample script demonstrating the concept of how to code a daily loss limit in a NinjaScript. This is not a fully functioning out-of-the-box strategy.
See this help guide page: https://ninjatrader.com/support/help...t_strategy.htm
Let me know if I may assist further.
Leave a comment:
-
Originally posted by NinjaTrader_ChelseaB View PostHello,
I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8.
These are often requested and I felt they are good examples to have for NT8.
DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241
DailyLossLimitMultiTradeExample_NT7 - http://ninjatrader.com/support/forum...367#post475367
Update Sep 4th, 2018:
- I realized the print in OnPositionUpdate should print when currentPnL is equal to less than the LossLimit, not just less than it.
Update July 13th, 2020:
- Added DailyLossLimitBuilderExample_NT8; NinjaTrader_PaulH was clever enough to realize the Strategy Builder custom series can be used with offsets to do math and subtract the total pnl from yesterdays pnl to get the current pnl and provided an example.
Leave a comment:
-
Does anybody has a working code that sets a Daily Max Loss?
Thank You
- Likes 2
Leave a comment:
-
Hello MatthewLesko,
Thanks for your note.
Unfortunately, we do not have a reference sample that demonstrates making a Daily Profit Limit.
That said, you could use the same concept as the Daily Loss Limit reference samples to create a Daily Profit Limit in your strategy.
Essentially, you would create a DailyProfit variable in your script similar to the DailyLoss variable in the DailyLossLimit script. Then, you would create a condition that compares DailyPNL to your DailyProfit variable.
Let me know if I may assist further.
Leave a comment:
-
Hi is there an option with this to stop trading if reached a profit as well?
Leave a comment:
-
Hello burmaz,
Thanks for your note.
I am not aware of anything in that example script that would need to occur at the close of a bar.
The DailyLossLimitBuilderExample script should work with either Calculate.OnPriceChange or Calculate.OnEachTick.
You would change the Calculate mode to OnPriceChange or OnEachTick when enabling the strategy.
Let me know if I may assist further.
Leave a comment:
-
Originally posted by NinjaTrader_ChelseaB View PostHello,
I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8.
These are often requested and I felt they are good examples to have for NT8.
DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241
DailyLossLimitMultiTradeExample_NT7 - http://ninjatrader.com/support/forum...367#post475367
Update Sep 4th, 2018:
- I realized the print in OnPositionUpdate should print when currentPnL is equal to less than the LossLimit, not just less than it.
Update July 13th, 2020:
- Added DailyLossLimitBuilderExample_NT8; NinjaTrader_PaulH was clever enough to realize the Strategy Builder custom series can be used with offsets to do math and subtract the total pnl from yesterdays pnl to get the current pnl and provided an example.
Hello,
What changes do I make in the strategy builder so that the "DailyLossLimitBuilderExample" attached file will work 'on price change' or on 'each tick' (intrabar)instead of on bar close? It works fine on bar close but I want it to operate with intrabar.
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by volIQ, 03-27-2024, 04:28 PM
|
3 responses
21 views
0 likes
|
Last Post
by RJay
Today, 05:41 AM
|
||
Started by Nickgiaco, 02-26-2024, 10:23 AM
|
2 responses
72 views
0 likes
|
Last Post Today, 05:12 AM | ||
Started by Johndc, Today, 04:39 AM
|
0 responses
4 views
0 likes
|
Last Post
by Johndc
Today, 04:39 AM
|
||
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
9 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
13 views
0 likes
|
Last Post Today, 02:00 AM |
Leave a comment: