![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Market Analyzer Support for the NinjaTrader Market Analyzer. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
|
Morning,
I hope someone can help with my two questions. First off (i guess i'll be the millionth person to ask) - I have tried to create an indicator for market analyser. However was unable to write the script as a indicator instead had to use a strategy. Is it possible to change a strategy to an indciator or copy and paste the script into the indicator editor. Secondly, I put together the below script. i am, however, coming up with an error message. it says line 39, column 13 "only assignment, call, increment, decrement and new object expressions can be used. Can someone help? I have highlighted the bit read. #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> /// Sector asset Allocation /// </summary> [Description("Sector asset Allocation")] public class SectorTAA : Strategy { #region Variables // Wizard generated variables private int price = 1; // Default setting for Price private int mA20 = 1; // Default setting for MA20 private int mA50 = 1; // Default setting for MA50 private int mA200 = 1; // Default setting for MA200 // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { (CalculateOnBarClose = True); } /// <summary>; /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 if (Close[0] > SMA(200)[0]&&(SMA(20)[0] > SMA(50)[0])) { Alert("MyAlert0", Priority.High, "Buy", "", 0, Color.White, Color.Black); Log("Buy", LogLevel.Information); } else if (Close[0] > SMA(200)[0]&&(SMA(20)[0] < SMA(50)[0])) { Alert("MyAlert1", Priority.High, "Reduce", "", 0, Color.White, Color.Black); Log("Reduce", LogLevel.Information); } else if (Close[0] < SMA(200)[0]&&SMA(20)[0] < SMA(50)[0]) { Alert("MyAlert2", Priority.High, "Sell", "", 0, Color.White, Color.Black); Log("Sell", LogLevel.Information); } else if (Close[0] < SMA(200)[0]&&SMA(20)[0] > SMA(50)[0]) { Alert("MyAlert3", Priority.High, "Add", "", 0, Color.White, Color.Black); Log("Add", LogLevel.Information); } else if (Close[0] > SMA(200)[0]&&SMA(20)[0] > SMA(50)[0]) { Alert("MyAlert4", Priority.High, "Buy", "", 0, Color.White, Color.Black); Log("Buy", LogLevel.Information); } } #region Properties [Description("Price of Instrument")] [GridCategory("Parameters")] public int Price { get { return price; } set { price = Math.Max(1, value); } } [Description("MA20 of Instrument")] [GridCategory("Parameters")] public int MA20 { get { return mA20; } set { mA20 = Math.Max(1, value); } } [Description("MA50 of Instrument")] [GridCategory("Parameters")] public int MA50 { get { return mA50; } set { mA50 = Math.Max(1, value); } } [Description("MA200 of Instrument")] [GridCategory("Parameters")] public int MA200 { get { return mA200; } set { mA200 = Math.Max(1, value); } } #endregion } } |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Beng986,
Yes, you can do it. However you have to make the following modifications: Change Code:
namespace NinjaTrader.Strategy Code:
public class SectorTAA : Strategy Code:
namespace NinjaTrader.Indicator Code:
public class SectorTAA : Indicator Code:
CalculateOnBarClose =true; // not True and remove the ()
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
|
thanks
now it is saying "the namespace 'NinjaTrader.Indicator' already contains a definition for 'SectorTAA' any ideas #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.Indicator { /// <summary> /// Sector asset Allocation /// </summary> [Description("Sector asset Allocation")] public class SectorTAA : Indicator { #region Variables // Wizard generated variables private int price = 1; // Default setting for Price private int mA20 = 1; // Default setting for MA20 private int mA50 = 1; // Default setting for MA50 private int mA200 = 1; // Default setting for MA200 // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { (CalculateOnBarClose =true);// } /// <summary>; /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 if (Close[0] > SMA(200)[0]&&(SMA(20)[0] > SMA(50)[0])) { Alert("MyAlert0", Priority.High, "Buy", "", 0, Color.White, Color.Black); Log("Buy", LogLevel.Information); } else if (Close[0] > SMA(200)[0]&&(SMA(20)[0] < SMA(50)[0])) { Alert("MyAlert1", Priority.High, "Reduce", "", 0, Color.White, Color.Black); Log("Reduce", LogLevel.Information); } else if (Close[0] < SMA(200)[0]&&SMA(20)[0] < SMA(50)[0]) { Alert("MyAlert2", Priority.High, "Sell", "", 0, Color.White, Color.Black); Log("Sell", LogLevel.Information); } else if (Close[0] < SMA(200)[0]&&SMA(20)[0] > SMA(50)[0]) { Alert("MyAlert3", Priority.High, "Add", "", 0, Color.White, Color.Black); Log("Add", LogLevel.Information); } else if (Close[0] > SMA(200)[0]&&SMA(20)[0] > SMA(50)[0]) { Alert("MyAlert4", Priority.High, "Buy", "", 0, Color.White, Color.Black); Log("Buy", LogLevel.Information); } } #region Properties [Description("Price of Instrument")] [GridCategory("Parameters")] public int Price { get { return price; } set { price = Math.Max(1, value); } } [Description("MA20 of Instrument")] [GridCategory("Parameters")] public int MA20 { get { return mA20; } set { mA20 = Math.Max(1, value); } } [Description("MA50 of Instrument")] [GridCategory("Parameters")] public int MA50 { get { return mA50; } set { mA50 = Math.Max(1, value); } } [Description("MA200 of Instrument")] [GridCategory("Parameters")] public int MA200 { get { return mA200; } set { mA200 = Math.Max(1, value); } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private SectorTAA[] cacheSectorTAA = null; private static SectorTAA checkSectorTAA = new SectorTAA(); /// <summary> /// Sector asset Allocation /// </summary> /// <returns></returns> public SectorTAA SectorTAA(int mA20, int mA200, int mA50, int price) { return SectorTAA(Input, mA20, mA200, mA50, price); } /// <summary> /// Sector asset Allocation /// </summary> /// <returns></returns> public SectorTAA SectorTAA(Data.IDataSeries input, int mA20, int mA200, int mA50, int price) { if (cacheSectorTAA != null) for (int idx = 0; idx < cacheSectorTAA.Length; idx++) if (cacheSectorTAA[idx].MA20 == mA20 && cacheSectorTAA[idx].MA200 == mA200 && cacheSectorTAA[idx].MA50 == mA50 && cacheSectorTAA[idx].Price == price && cacheSectorTAA[idx].EqualsInput(input)) return cacheSectorTAA[idx]; lock (checkSectorTAA) { checkSectorTAA.MA20 = mA20; mA20 = checkSectorTAA.MA20; checkSectorTAA.MA200 = mA200; mA200 = checkSectorTAA.MA200; checkSectorTAA.MA50 = mA50; mA50 = checkSectorTAA.MA50; checkSectorTAA.Price = price; price = checkSectorTAA.Price; if (cacheSectorTAA != null) for (int idx = 0; idx < cacheSectorTAA.Length; idx++) if (cacheSectorTAA[idx].MA20 == mA20 && cacheSectorTAA[idx].MA200 == mA200 && cacheSectorTAA[idx].MA50 == mA50 && cacheSectorTAA[idx].Price == price && cacheSectorTAA[idx].EqualsInput(input)) return cacheSectorTAA[idx]; SectorTAA indicator = new SectorTAA(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.MA20 = mA20; indicator.MA200 = mA200; indicator.MA50 = mA50; indicator.Price = price; Indicators.Add(indicator); indicator.SetUp(); SectorTAA[] tmp = new SectorTAA[cacheSectorTAA == null ? 1 : cacheSectorTAA.Length + 1]; if (cacheSectorTAA != null) cacheSectorTAA.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheSectorTAA = tmp; return indicator; } } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// <summary> /// Sector asset Allocation /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.SectorTAA SectorTAA(int mA20, int mA200, int mA50, int price) { return _indicator.SectorTAA(Input, mA20, mA200, mA50, price); } /// <summary> /// Sector asset Allocation /// </summary> /// <returns></returns> public Indicator.SectorTAA SectorTAA(Data.IDataSeries input, int mA20, int mA200, int mA50, int price) { return _indicator.SectorTAA(input, mA20, mA200, mA50, price); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// Sector asset Allocation /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.SectorTAA SectorTAA(int mA20, int mA200, int mA50, int price) { return _indicator.SectorTAA(Input, mA20, mA200, mA50, price); } /// <summary> /// Sector asset Allocation /// </summary> /// <returns></returns> public Indicator.SectorTAA SectorTAA(Data.IDataSeries input, int mA20, int mA200, int mA50, int price) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.SectorTAA(input, mA20, mA200, mA50, price); } } } #endregion |
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
|
sorry line 22 colum 18
public class SectorTAA : Indicator |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Beng986,
The message indicates that you already have an indicator with the same name. Please change the name of the indicator to any other name.such as below. Code:
public class SectorTAANew : Indicator
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
|
thanks for your help so far. It is now working however
In the script i set it to give an output as a as a message - it however only gives it as a number. is it possible to set the the indicator to give the messages i wanted it to in the code. |
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Beng986,
The code rightly printing out the values in the log tab in Control Center (and the Alert in the Alert window). Can you send a screenshot describing the exact scenario. To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment. For detailed instructions please visit the following link http://take-a-screenshot.org/ I look forward to assisting you further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
|
thanks.
yer is it doing what i say but not (my mistake) what i want. can i get it to say buy, sell, add, reduce instead of displaying the number? |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Beng986,
The log tab is displaying the Buy/Sell etc messages and not any number. This is true for the Alert box also. If you want to show the message only and remove any other colume then please follow the below steps:
Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Fast MA reversing/failing at slow MA | Zigman | Indicator Development | 3 | 03-20-2012 12:58 PM |
| Double MA | dmod1 | Indicator Development | 0 | 09-23-2010 03:27 PM |
| MA | ninoo | Indicator Development | 4 | 07-18-2009 06:10 AM |
| Quick MA an alternative to Juirk MA | Ninja B | Indicator Development | 5 | 01-09-2009 07:14 AM |
| Above MA bar is green, below MA bar is red? | BottomShark77 | NinjaScript File Sharing Discussion | 1 | 12-01-2008 05:24 AM |