NexusFi: Find Your Edge


Home Menu

 





Daily Loss Limit


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one togier with 4 posts (1 thanks)
    2. looks_two crazybears with 2 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 redratsal with 1 posts (4 thanks)
    1. trending_up 12,152 views
    2. thumb_up 9 thanks given
    3. group 9 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread

Daily Loss Limit

  #1 (permalink)
 togier 
Boston, MA
 
Experience: Advanced
Platform: NinjaTrader
Broker: IB
Trading: EUR/USD
Posts: 42 since Apr 2010
Thanks Given: 1
Thanks Received: 3

I'm trying to insert a piece of code in an automated strategy to limit my daily loss. Can someone share the code snippet that I can use for something like that? Thanks for your help.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 crazybears 
Alesia E.U.
 
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115



togier View Post
I'm trying to insert a piece of code in an automated strategy to limit my daily loss. Can someone share the code snippet that I can use for something like that? Thanks for your help.

Hi Togier

what kind of platform do you use ?

Reply With Quote
  #4 (permalink)
 togier 
Boston, MA
 
Experience: Advanced
Platform: NinjaTrader
Broker: IB
Trading: EUR/USD
Posts: 42 since Apr 2010
Thanks Given: 1
Thanks Received: 3


crazybears View Post
Hi Togier

what kind of platform do you use ?

Sorry, I guess I should have specified that. It's NT7.

Started this thread Reply With Quote
  #5 (permalink)
 crazybears 
Alesia E.U.
 
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115


togier View Post
Sorry, I guess I should have specified that. It's NT7.


sorry but i don't know NT language

Reply With Quote
  #6 (permalink)
 togier 
Boston, MA
 
Experience: Advanced
Platform: NinjaTrader
Broker: IB
Trading: EUR/USD
Posts: 42 since Apr 2010
Thanks Given: 1
Thanks Received: 3


crazybears View Post
sorry but i don't know NT language

Its C#

Started this thread Reply With Quote
  #7 (permalink)
 
redratsal's Avatar
 redratsal 
Milan (I)
 
Experience: Advanced
Platform: Ninjatrader
Broker: Kinetick
Trading: FDAX,6E,CL,YM,NQ,ES
Posts: 1,648 since Oct 2010
Thanks Given: 1,215
Thanks Received: 2,090

Hi,

Find below stop and profit variables as requested (just took the interesting parts)

#region Variables

privateint maxprofit = 1000; // Max profit before halt strategy
privateint maxloss = 1500; // Max loss before halt strategy


protectedoverridevoid OnBarUpdate()
{

// Only run on real-time data
if (Historical)
return;

if (Performance.AllTrades.TradesPerformance.Currency.CumProfit<-maxloss ||
Performance.AllTrades.TradesPerformance.Currency.CumProfit>maxprofit)

#region Properties

[Description("Maximum profit.")]
[Category(
"Parameters")]
[Gui.Design.DisplayName(
"\t\t\tMax Profit")]
publicint MaxProfit
{
get { return maxprofit; }
set { maxprofit = Math.Max(1, value); }
}

[Description(
"Maximum loss (enter positive value!).")]
[Category(
"Parameters")]
[Gui.Design.DisplayName(
"\t\t\tMax Loss")]
publicint MaxLoss
{
get { return maxloss; }
set { maxloss = Math.Max(1, value); }
}

Beware that Historical will set your cumulated profit n loss just for the day (no good for backtesting),If you want both to be customized on strategy setup, you will have to set a bool variable on historical.

correct function is Performance.AllTrades.TradesPerformance.Currency.CumProfit without spacing (can't correct it)


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
 togier 
Boston, MA
 
Experience: Advanced
Platform: NinjaTrader
Broker: IB
Trading: EUR/USD
Posts: 42 since Apr 2010
Thanks Given: 1
Thanks Received: 3


redratsal View Post
Hi,

Find below stop and profit variables as requested (just took the interesting parts)

#region Variables

privateint maxprofit = 1000; // Max profit before halt strategy
privateint maxloss = 1500; // Max loss before halt strategy


protectedoverridevoid OnBarUpdate()
{

// Only run on real-time data
if (Historical)
return;

if (Performance.AllTrades.TradesPerformance.Currency.CumProfit<-maxloss ||
Performance.AllTrades.TradesPerformance.Currency.CumProfit>maxprofit)

#region Properties

[Description("Maximum profit.")]
[Category(
"Parameters")]
[Gui.Design.DisplayName(
"\t\t\tMax Profit")]
publicint MaxProfit
{
get { return maxprofit; }
set { maxprofit = Math.Max(1, value); }
}

[Description(
"Maximum loss (enter positive value!).")]
[Category(
"Parameters")]
[Gui.Design.DisplayName(
"\t\t\tMax Loss")]
publicint MaxLoss
{
get { return maxloss; }
set { maxloss = Math.Max(1, value); }
}

Beware that Historical will set your cumulated profit n loss just for the day (no good for backtesting),If you want both to be customized on strategy setup, you will have to set a bool variable on historical.

correct function is Performance.AllTrades.TradesPerformance.Currency.CumProfit without spacing (can't correct it)



Thank you very much for the help. This is great.

Started this thread Reply With Quote
Thanked by:
  #9 (permalink)
 drolles 
London, UK
 
Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Trading: if it trades...
Posts: 94 since Oct 2010
Thanks Given: 24
Thanks Received: 39

Would a solution be to search the trade collection for trades that occurred that day, then add the current PnL?

 
Code
if (dailyPnL > -(maxLoss))
                    {

                        if (Performance.AllTrades.Count != tradeCount)
                        {
                            tradeCount = Performance.AllTrades.Count;

                            foreach (Trade x in Performance.AllTrades)
                            {
                                if (x.Exit.Time.Date.CompareTo(Time[0].Date) == 0)
                                {
                                    dailyPnL += x.ProfitCurrency;

                                }

                            }

                        }

                        if (Position.MarketPosition != MarketPosition.Flat)
                        {

                            dailyPnL += Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);

                        }

                    }
You would obviously need to reset the dailyPnL each day.

 
Code
if (Bars.FirstBarOfSession && FirstTickOfBar)
                    {

                        dailyPnL = 0;}
It when then work regardless if you are in backtest or live trading. You would always be searching the trade collection based on the current day. Of course, please feel to poke holes in my logic

Reply With Quote
  #10 (permalink)
 GeeBee 
Totonto,Ontario, Canada
 
Experience: Beginner
Platform: Ninja Trader, Meta Trader
Trading: Crude Oil, Forex
Frequency: Daily
Duration: Minutes
Posts: 31 since Nov 2011
Thanks Given: 5
Thanks Received: 9


Is there any indicator for Daily Loss and Profit limit. I don't know how to make one. Thanks

Reply With Quote




Last Updated on February 4, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts