Daily Loss Limit - NinjaTrader Programming | futures.io
futures io futures trading


Daily Loss Limit
Started: by togier Views / Replies:3,976 / 11
Last Reply: Attachments:0

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

Daily Loss Limit

  #1 (permalink)
Elite Member
Boston, MA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: EUR/USD
 
Posts: 42 since Apr 2010
Thanks: 1 given, 3 received

Daily Loss Limit

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.

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Alesia E.U.
 
Futures Experience: Intermediate
Platform: Sierra chart
Favorite Futures: Futures
 
Posts: 166 since Feb 2011
Thanks: 139 given, 108 received



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)
Elite Member
Boston, MA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: EUR/USD
 
Posts: 42 since Apr 2010
Thanks: 1 given, 3 received


crazybears View Post
Hi Togier

what kind of platform do you use ?

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

Reply With Quote
 
  #5 (permalink)
Elite Member
Alesia E.U.
 
Futures Experience: Intermediate
Platform: Sierra chart
Favorite Futures: Futures
 
Posts: 166 since Feb 2011
Thanks: 139 given, 108 received

Futures Edge on FIO

What value do you place on the webinars on FIO?

 

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)
Elite Member
Boston, MA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: EUR/USD
 
Posts: 42 since Apr 2010
Thanks: 1 given, 3 received


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

Its C#

Reply With Quote
 
  #7 (permalink)
Elite Member
Milan (I)
 
Futures Experience: Advanced
Platform: Ninjatrader
Broker/Data: Kinetick
Favorite Futures: FDAX,6E,CL,YM,NQ,ES
 
redratsal's Avatar
 
Posts: 1,653 since Oct 2010
Thanks: 1,217 given, 2,059 received

Answer
This post has been selected as an answer to the original posters question Answer

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)


Reply With Quote
The following 3 users say Thank You to redratsal for this post:
 
  #8 (permalink)
Elite Member
Boston, MA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: EUR/USD
 
Posts: 42 since Apr 2010
Thanks: 1 given, 3 received


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.

Reply With Quote
The following user says Thank You to togier for this post:
 
  #9 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: TradeLink, OpenQuant, considering anything that works...
Favorite Futures: if it trades...
 
Posts: 94 since Oct 2010
Thanks: 24 given, 38 received

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
The following 3 users say Thank You to drolles for this post:
 
  #10 (permalink)
Tick Trader
Totonto,Ontario, Canada
 
Futures Experience: Beginner
Platform: Ninja Trader
Favorite Futures: oil, russel 2000
 
Posts: 8 since Nov 2011
Thanks: 1 given, 4 received

Hello Friends


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

Reply With Quote

Reply



futures io > > > > > Daily Loss Limit

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Spring Grains Outlook w/Sean Lusk @ Walsh Trading

Elite only

FIO Video Journal Challenge featuring NinjaTrader ($2,000+ of prizes)

April

Process above all else w/Anthony Crudele @ Futures Radio Show

Elite only

Machine Learning - Quantitative Trading w/Martin Froehler @ Quantiacs

Elite only

Market Dynamics w/Peter Davies @ Jigsaw Trading

Elite only

Ask Me Anything w/Patrick Rooney @ Trading Technologies

Apr 18

Ask Me Anything w/FuturesTrader71

Apr 19

Machine Learning w/Kris Longmore

Elite only

Market Analysis w/Dave Forss

Apr 25

Introducing iSystems with Stage 5 Trading

Apr 27
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
EasyLanguage Daily Profit and Daily Loss limit in strategy Big Mike EasyLanguage Programming 11 May 12th, 2016 01:50 PM
When a stop loss order is filled beyond limit price Big Mike Brokers and Data Feeds 56 September 15th, 2015 09:01 AM
Daily Loss Limit sleepy Brokers and Data Feeds 18 August 20th, 2014 02:53 PM
How to set up a Stop (Limit) Loss order - Ninja Trader jdumanic NinjaTrader 2 June 7th, 2011 05:40 PM
The First Loss is the Best Loss ZTR Psychology and Money Management 21 May 28th, 2010 05:18 PM


All times are GMT -4. The time now is 07:46 PM.

no new posts
Page generated 2017-03-28 in 0.24 seconds with 37 queries on phoenix via your IP 54.204.253.227