Daily Loss Limit - NinjaTrader Programming | futures io social day trading
futures io futures trading


Daily Loss Limit
Updated: Views / Replies:4,546 / 11
Created: by togier Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • 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.

-- Big Mike, Site Administrator

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, 109 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, 109 received


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,067 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 4 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: 10 since Nov 2011
Thanks: 3 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)
 

RandBots: AutoTrading Bots to diversify your trading

Oct 24
 

TopstepTrader: Profiting Without Risking Your Own Money

Oct 26

Building Open Source Indicators for NT8 w/Fat Tails @ Lizard Indicators

Elite only
     

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 Reviews of Brokers and Data Feeds 56 September 15th, 2015 09:01 AM
Daily Loss Limit sleepy Reviews of 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 10:56 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-10-21 in 0.23 seconds with 37 queries on phoenix via your IP 54.80.236.48