protected override void Initialize() { Add(PeriodType.Minute, 1); Add(PeriodType.Day, 1); Add(SMA(Fast)); Add(SMA(Slow)); CalculateOnBarClose = false; } protected override void OnBarUpdate() { {avgdailyvolume = SMA(Volumes[2],20)[0];} if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[2] < BarsRequired) return; // Condition set 1 Long Entry, fast MA cross above slow MA & current price > high of bar at cross. if (BarsInProgress == 1) //OnBarUpdate called for 1min bars if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend) if (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2] && SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] + distance ) if ((avgdailyvolume > 100000) && (Closes[2][1] >= 10 && Closes[2][1] <= 200)) { EnterLong(200, ""); }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Added Time series question..
Collapse
X
-
Added Time series question..
I added a 2nd time series or the Day time series and added a condition for avgdailyvolume based on this series. It has altered my backtest net profit results and should not have any effect(im just testing the SPY symbol). When I remove Add(PeriodType.Day, 1); the results go back to what they should be. Do I have something out of order or out of place below? Should I have a BIP == 2 above the avgdailyvolume condition?
Code:Tags: None
-
Hello zachj,
Thank you for your post.
You are including the avgdailyvolume calculated of the Daily bars in your condition to EnterLong(), this will change the way your strategy performs versus if you remove the Daily bars and the avgdailyvolume from the strategy.
How are you calculating avgdailyvolume when you remove the Daily bars? Or do remove both the Daily bars and the avgdailyvolume? Either way the calculations are going to be different for the strategy and thus the results of testing this strategy will be different.
Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - unfortunately we cannot offer such debug or code modification services here, but please see the provided resources below to help you proceed productively :
First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.
For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders
It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.
If you would prefer the debug assist of a professional NinjaScript consultant, please check into the following listings - Click here for a list of certified NinjaScript Consultants
-
I wasn't looking at the volume at all before, so the volume and daily series were added in together. All I'm currently testing is SPY just to confirm the new code is not effecting the net profit. I have the volume set to >100k which shouldn't change the net profit seeing SPY volume is always way over this. The reason for adding the volume requirement is for when I'm backtesting a whole index to eliminate stocks with low volume.
This added code is changing the net profit when backtesting SPY so something is off? Specifically it looks like the added series in the initialize section is what's causing it.
Otherwise the other code is just for a simple sma crossover with a condition for price moving above the high of a previous bar at the crossover.
Comment
-
Hello zachj,
Thank you for your response.
Please try printing the values to the Output window using Print when the Daily bars are included in your strategy. Debugging your strategy is going to be the best method to discover why the results are different.
For information on Print() please visit the following link: http://www.ninjatrader.com/support/h.../nt7/print.htm
Comment
-
Hello zachj,
Thank you for your response.
Print() will Output to the Output window (Tools > Output) when running the strategy. You will want to Print() the avgdailyvolume when your conditions is true:
Code:if ((avgdailyvolume > 100000) && (Closes[2][1] >= 10 && Closes[2][1] <= 200)) { EnterLong(200, ""); Print(avgdailyvolume); }
Comment
-
Hello zachj,
Thank you for your response.
If 20 day Moving Average volume is less than 1 million than you can expect to see drastically different results.
You are correct, the data series are loaded based on the order they are added to the Initialize() method.
Please let me know if you have any questions.
Comment
-
Im not sure what you mean by under 1million, all the readings are over 100 million. I'm just backttesting spy for now. But having a condition in there to Not include stocks under 500k shouldn't have any effect but its changing the net. It doesn't even matter, I can take out the volume condition and it still changes the net. Its the line Add(PeriodType.Day, 1); that is having the effect. The other code is being effected by this added series even though it's not using it. It's not making sense.
Comment
-
Not sure if you needed everything but here is the variables and the whole entire thing. All I'm doing is //commenting and uncommenting the 3 lines below in blue and it comes up with a different Net Profit. Using SPY. Primary series 5min.
Code:namespace NinjaTrader.Strategy { [Description("")] public class Test : Strategy { #region Variables private int fast = 3; private int slow = 50; private int timestart = 94500; private int timeend = 140000; private double distance = .01; private double avgdailyvolume = 0; #endregion protected override void Initialize() { Add(PeriodType.Minute, 1); [COLOR="Blue"]Add(PeriodType.Day, 1);[/COLOR] Add(SMA(Fast)); Add(SMA(Slow)); CalculateOnBarClose = false; } protected override void OnBarUpdate() { [COLOR="Blue"]avgdailyvolume = SMA(Volumes[2],20)[0]; if ((avgdailyvolume > 100000) && (Closes[2][1] >= 10 && Closes[2][1] <= 200))[/COLOR] if (ToTime(Time[0]) >= timestart && ToTime(Time[0]) < timeend) // Condition set 1 Long Entry, fast MA cross above slow MA & current price > high of bar at cross. if ((BarsInProgress == 1) //OnBarUpdate called for 1min bars && (SMA(BarsArray[0],Fast)[2] > SMA(BarsArray[0],Slow)[2] && SMA(BarsArray[0],Fast)[3] < SMA(BarsArray[0],Slow)[3] && Close[0] > Highs[0][2] + distance )) { EnterLong(200, ""); } } #region Properties [Description("Fast MA Period")] [GridCategory("Parameters")] public int Fast { get { return fast; } set { fast = Math.Max(1, value); } } [Description("Slow MA Period")] [GridCategory("Parameters")] public int Slow { get { return slow; } set { slow = Math.Max(1, value); } } [Description("")] [Category("Parameters")] public int TimeStart { get { return timestart; } set { timestart = Math.Max(0, value); } } [Description("")] [Category("Parameters")] public int TimeEnd { get { return timeend; } set { timeend = Math.Max(0, value); } } [Description("")] [Category("Parameters")] public double Distance { get { return distance; } set { distance = Math.Max(0, value); } } #endregion } }
Last edited by zachj; 06-19-2013, 05:00 PM.
Comment
-
Files attached. As you can see the Net drops by 500 with the Volume code in there. I expect to see from my code that they would be exactly the same, as the volume code is simply a measure to eliminate stocks that are under 100k average daily volume. Im just running this backtest on SPY which is always over 100 million in daily volume. Either way this should not change the Net one penny. There has to be a bug in ninjatrader and its reading of volume or some bug with adding a 3rd price series. I even tried simply adding if VOLMA(14) > 100k and it still does not work properly. Screening out stocks under 100k in volume should be a very simple task to accomplish yet this has turned into a complicated time consuming task. This is simple code. There must be a NT bug.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by carnitron, Today, 08:42 PM
|
0 responses
5 views
0 likes
|
Last Post
by carnitron
Today, 08:42 PM
|
||
Started by strategist007, Today, 07:51 PM
|
0 responses
6 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,973 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
8 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
58 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
Comment