NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > Application Technical Support > Market Analyzer

Market Analyzer Support for the NinjaTrader Market Analyzer.

Reply
 
Thread Tools Display Modes
Old 06-13-2012, 03:56 AM   #1
Beng986
Junior Member
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default MA help

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
}
}
Beng986 is offline  
Reply With Quote
Old 06-13-2012, 05:23 AM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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
to
Code:
namespace NinjaTrader.Indicator
Code:
public class SectorTAA : Indicator
The code for which you are getting the error should be
Code:
CalculateOnBarClose =true; // not True and remove the ()
Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-13-2012, 06:09 AM   #3
Beng986
Junior Member
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default

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
Beng986 is offline  
Reply With Quote
Old 06-13-2012, 06:17 AM   #4
Beng986
Junior Member
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default

sorry line 22 colum 18

public class SectorTAA : Indicator
Beng986 is offline  
Reply With Quote
Old 06-13-2012, 06:21 AM   #5
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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
Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-13-2012, 07:02 AM   #6
Beng986
Junior Member
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
Beng986 is offline  
Reply With Quote
Old 06-13-2012, 07:36 AM   #7
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 06-13-2012, 08:11 AM   #8
Beng986
Junior Member
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
Beng986 is offline  
Reply With Quote
Old 06-13-2012, 08:29 AM   #9
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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:
  • Right click on the grid
  • In the context menu click on Grid>Properties
  • In the Properties dialog uncheck all boxes except for message.


Please let me know if I can assist you any further.
Attached Images
File Type: png Pic.png (68.3 KB, 3 views)
NinjaTrader_Joydeep is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 10:20 PM.