NexusFi: Find Your Edge


Home Menu

 





How to get CumProfit of the day, not the whole chart?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one redratsal with 3 posts (6 thanks)
    2. looks_two gztanwei with 2 posts (0 thanks)
    3. looks_3 Big Mike with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,964 views
    2. thumb_up 6 thanks given
    3. group 1 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

How to get CumProfit of the day, not the whole chart?

  #1 (permalink)
 gztanwei 
toronto
 
Experience: Beginner
Platform: NinjaTrader
Posts: 33 since Sep 2009
Thanks Given: 3
Thanks Received: 11

Hi I am trying to set a daily profit and loss limit to my strategy. After the limit is hit, the strategy stops trading for the day.

Here I found this function to return cumulative realized profit.
Performance.AllTrades.TradesPerformance.Points.Cum Profit

But this function returns cumulated profit of all days on the chart, not daily profit...

I know I could work around it by setting the chart's data series to one day only. But I would really to have daily profit limit, so that I can eye on my strategy on a multiple-day chart.

Thank you!

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Increase in trading performance by 75%
The Elite Circle
How to apply profiles
Traders Hideout
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
36 thanks
Tao te Trade: way of the WLD
24 thanks
Spoo-nalysis ES e-mini futures S&P 500
19 thanks
Bigger Wins or Fewer Losses?
19 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #3 (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


try this: Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit

** if you stop your strategy and restart it the same day the daily cumprofit will restart from zero.

Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 gztanwei 
toronto
 
Experience: Beginner
Platform: NinjaTrader
Posts: 33 since Sep 2009
Thanks Given: 3
Thanks Received: 11


redratsal View Post
try this: Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit

** if you stop your strategy and restart it the same day the daily cumprofit will restart from zero.

thanks. but this method does not work when I want to back test my strategy... I hope the strategy to stop every day on my chart, and start again the next day.

Started this thread Reply With Quote
  #5 (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


gztanwei View Post
thanks. but this method does not work when I want to back test my strategy... I hope the strategy to stop every day on my chart, and start again the next day.

Ok you did not mention in your op it was for backtesting concern, if the data range is consistent what I do in this case is import the data into an excel file and filter the information separately (nt has some limits and sometimes you have to overcome manually).

Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,214
Thanks Received: 101,599

Been years, so I am rusty. But I have definitely done this for both real time and backtesting.

There is another method you can call that is not RealtimeTrades. Can't remember what it is called, sorry.

And then on each new session, you need to simply check the prior value, and then 'reset' it by putting forward a new value that starts at zero each day.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal 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

 
Code
 protected override void OnBarUpdate()
        
			// 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.CumProfit;
				
				/* 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 or if realized losses exceed $400.
			Also prevent trading if 10 trades have already been made in this session. */
			if (Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit >= 1000
				|| Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit <= -400
				|| Performance.AllTrades.Count - priorTradesCount > 10)
			{
				/* 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;
			}

Visit my NexusFi Trade Journal Reply With Quote




Last Updated on May 22, 2012


© 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