#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// <summary> /// Code for first strategy /// </summary> [Description("Code for first strategy")] public class VWAP : Strategy { #region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 // User defined variables (add any user defined variables below) #endregion double[] typical_price = new double[3]; double[] vwap = new double[3]; private int vol_price = 0; private int total_volume = 0; private int total_vol_price = 0; private int i = 0; private bool increasing_vwap = true; private bool increasing_close = true; /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { // Trailing Stop SetTrailStop("", CalculationMode.Percent, 2, false); // Add a 5 minute Bars object: BarsInProgress index = 1 Add(PeriodType.Minute, 5); CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // VWAP total_volume = 0; total_vol_price = 0; increasing_vwap = true; increasing_close = true; for (i=0;i<=2;i++){ typical_price[i] = Math.Round((High[i]+Low[i]+Close[i])/3,2); total_volume += System.Convert.ToInt32(Math.Floor((Volume[i]))); vol_price = System.Convert.ToInt32(Math.Floor((Volume[i]*typical_price[i]))); total_vol_price += vol_price; vwap[i] = total_vol_price/total_volume; Print("vwap["+i+"] = "+vwap[i]+" with tick size "+Volume[i]); // check for increasing indicators in a cumulative fashion if (i>0 && vwap[i]<vwap[i-1]) {increasing_vwap = false;} if (i==2 && NBarsUp(i,false,true,true)[0] == 0) {increasing_close = false;} } // check for average volume as well? // Buy conditions met if (increasing_vwap && increasing_close){ EnterLong(this.StrategyData.Strategy.Name); } // Sell Conditions met (optional since we have trailing stop???) } #region Properties [Description("")] [GridCategory("Parameters")] public int MyInput0 { get { return myInput0; } set { myInput0 = Math.Max(1, value); } } #endregion } }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Sell Script and Auto Chart
Collapse
X
-
Sell Script and Auto Chart
I have a strategy below where my sell order is not picking up. I want a trailing stop. Also, is my statement about adding bars correct. I'd like to have a defaulted amount of time as well as a trailing stop to kick in. For the time, do I need to enclose it in BarsInProgress==1 as seen here:
Code:Last edited by math_celebrity; 04-17-2014, 11:12 AM. -
Hello math_celebrity,
Welcome to the NinjaTrader Support Forums!
Using SetTrailStop() and Percentage mode, it is going to be a double value so 2 = 200% and 0.2 = 20% so with 200% so this is going to put your Stop Loss order very far away.
As for your added time series, you added a 5 Minute series to your script but I am not sure what you are trying to do with it.
Are you trying to get to the typical values of the two time frames inside of your for loop?JCNinjaTrader Customer Service
-
Thanks for the trailing stop, I fixed that and it looks good.
For the time series, is it possible to add this to the strategy so that it is the default when we load a strategy?
Comment
-
Hello math_celebrity,
It will not load the added series as a default when you apply the strategy. It will only be used if you want to have your strategy set to 1 time series and use another time series for some calculations.
You may look at our SampleMultiTimeFrame strategy that comes loaded inside of NinjaTrader for an example of this. Tools -> Edit NinjaScript -> Strategy.JCNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by warreng86, 11-10-2020, 02:04 PM
|
4 responses
1,355 views
0 likes
|
Last Post
by mathewlo
Today, 09:18 PM
|
||
Started by Perr0Grande, Today, 08:16 PM
|
0 responses
3 views
0 likes
|
Last Post
by Perr0Grande
Today, 08:16 PM
|
||
Started by elderan, Today, 08:03 PM
|
0 responses
5 views
0 likes
|
Last Post
by elderan
Today, 08:03 PM
|
||
Started by algospoke, Today, 06:40 PM
|
0 responses
10 views
0 likes
|
Last Post
by algospoke
Today, 06:40 PM
|
||
Started by maybeimnotrader, Today, 05:46 PM
|
0 responses
12 views
0 likes
|
Last Post Today, 05:46 PM |
Comment