Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Position Sizing During Backtest
Collapse
X
-
Originally posted by NinjaTrader_Bertrand View Postsburtt, sorry do not recall any specifics now after those 2 yrs.
. In my strategy I need to create a DataSeries object to store values. I’ve defined a variable “lastProfit” to hold the DataSeries object and created a new DataSeries in the Initialize() method. Finally in the OnBarUpdate() method I’ve defined how to define the value to be stored in the DataSeries (please see code below).
What I would need to know is what function to use to obtain the cumulative sum of the values stored in the DataSeries, basically I want my strategy to return the cumulative sum of the lastProfit DataSeries. Please help
Code:{ [Description("")] public class ABC : Strategy { #region Variables private DataSeries lastProfit; #endregion protected override void Initialize() { lastProfit = new DataSeries(this, MaximumBarsLookBack.Infinite); } protected override void OnBarUpdate() { if (...) { lastProfit.Set(lastTrade.ProfitCurrency * lastTrade.Quantity / lastTrade.Exit); else lastProfit.Set(0); } } }
Comment
-
Originally posted by NinjaTrader_Bertrand View PostThere's a summation method available that takes a series as input, however before doing that - why not use the CumProfit from the PerformanceClass directly? You have AllTraders and Realtimetrades here as choice as well to further differentiate.
http://www.ninjatrader.com/support/h.../cumprofit.htm
Comment
-
Sure, this would be documented in our helpguide - http://www.ninjatrader.com/support/h...mation_sum.htm
However then you would need to specify over how many bars you would want the SUM to be taken.
An alternative way using C# collections was discussed for example here -
Howdy-- I have created an indicator that assigns each bar a unique 0, 1 or 2 "score" based on a series of logic conditions. This piece is working fine. I then wanted to create a running "score" of the unique bar "scores" over the previous n bars. To do this, I figured that creating an array to hold each bar's score would be best, as the size of the array could be limited with a parameter (ie, 10 bars, 50 bars, 100 bars, etc). I then wanted to sum this array values to create …BertrandNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Bertrand View PostSure, this would be documented in our helpguide - http://www.ninjatrader.com/support/h...mation_sum.htm
However then you would need to specify over how many bars you would want the SUM to be taken.
An alternative way using C# collections was discussed for example here -
https://www.bigmiketrading.com/ninja...-question.html
Comment
-
Originally posted by NinjaTrader_Bertrand View PostYou would need to keep track of the start bar / DateTime, so you would have a reference for the SUM to work with. If you want to know a bar number for a DateTime object, use GetBar.
http://www.ninjatrader.com/support/h...ightsub=GetBar
Now my final doubt is the following, please have a look at the code below. What I need is these DataSeries: LastProfit and CumulativeLastProfit to be calculated only at the end of a trade/ or beginning of a new trade, NOT OnBarUpdate(), do you think my code below does this properly? Thanks for your help!
Code:namespace NinjaTrader.Strategy { [Description("")] public class ABC : Strategy { #region Variables private double AccbalNewIR = 0; private double AccountSize = 100000; //In US$ Terms private double Riskf = 1; //Percent of Account Size to Risk on each Trade private double Psize = 0; private DataSeries lastProfit; private DataSeries CumulativeLastProfit; #endregion protected override void Initialize() { lastProfit = new DataSeries(this, MaximumBarsLookBack.Infinite); CumulativeLastProfit = new DataSeries(this, MaximumBarsLookBack.Infinite); SetTrailingStop(...); } protected override void OnBarUpdate() { if (Close[0] > Close[1]) { GoLong(); EnterLong((int)Psize,""); } } void GoLong() { lastProfit.Set(lastTrade.ProfitCurrency * lastTrade.Quantity / lastTrade.Exit); CumulativeLastProfit.Set(CumulativeLastProfit[1] + lastProfit[0]); AccbalNewIR = AccountSize + CumulativeLastProfit; Psize = Math.Round(...); } } }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by r68cervera, Today, 05:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by r68cervera
Today, 05:29 AM
|
||
Started by geddyisodin, Today, 05:20 AM
|
0 responses
3 views
0 likes
|
Last Post
by geddyisodin
Today, 05:20 AM
|
||
Started by JonesJoker, 04-22-2024, 12:23 PM
|
6 responses
35 views
0 likes
|
Last Post
by JonesJoker
Today, 05:14 AM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
12 responses
3,239 views
0 likes
|
Last Post
by Leafcutter
Today, 05:08 AM
|
||
Hi
by AveryFlynn
Started by AveryFlynn, Today, 04:57 AM
|
0 responses
6 views
0 likes
|
Last Post
by AveryFlynn
Today, 04:57 AM
|
Comment