View Full Version : noob trying to make first MA & MACD strat
bleauhaus
11-05-2009, 12:44 PM
I am simply trying to setup an EMA cross entry (no prob there-video library)
and a MACD osc value 0 exit.
i am using the wizard and am willing to read and learn but I am so excited by this program I just want my first strat to "work" so i can fiddle with it from there and learn as I tinker
thanks
NinjaTrader_Josh
11-05-2009, 01:29 PM
Welcome to the NinjaTrader Support Forums.
In the Condition Builder, select MACD on the left from indicators. In the parameters, choose the correct Plot you want to use. On the right, select Misc > Numeric value and type in 0.
Hope that helps.
bleauhaus
11-05-2009, 01:40 PM
right i had that setup like that .... i think perhaps i have added or changed some stuff along the way which is causing the problem - is there a way to see an example of what im trying to do (or similar) which i can emulate?
NinjaTrader_Josh
11-05-2009, 01:45 PM
Sorry we do not have samples created for this. Please show us what you have so far and we can tell you what could be causing issues. Thank you.
bleauhaus
11-05-2009, 02:01 PM
Yeah im not much of a scriptor but here is a paste of the script
#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>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class MyCustomStrategy1 : Strategy
{
#region Variables
// Wizard generated variables
private int fast = 21; // Default setting for Fast
private int slow = 52; // Default setting for Slow
// 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()
{
Add(EMA(21));
Add(EMA(52));
Add(MACD(12, 26, 9));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(21), EMA(52), 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (CrossBelow(EMA(21), EMA(52), 1))
{
EnterShort(DefaultQuantity, "");
}
// Condition set 3
if (MACD(12, 26, 9).Diff[0] == 0)
{
ExitLong("", "");
ExitShort("", "");
}
}
#region Properties
[Description("Fast MA Period")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(20, value); }
}
[Description("Slow MA Period")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(20, value); }
}
#endregion
NinjaTrader_Josh
11-05-2009, 02:03 PM
You are likely using the wrong MACD plot. You are using the Difference plot instead of the actual MACD plot. Also your condition requires the plot to be exactly 0. This likely does not happen often. It usually crosses zero but never lands at exactly 0.
bleauhaus
11-05-2009, 02:12 PM
0 - my aim is when the MACD histo or diff is zero i want it to flatten if i understand you and what i am seeing in the advanced charting window the app is accurate to 7 (or more) places right of the decimal, so i need to look for a condition like <0 to close a long and >0 to close a short - right?
NinjaTrader_Josh
11-05-2009, 02:16 PM
You would want to open up a range of acceptable values since the value actually being exactly 0 is slim. What you decide the ultimate logic to be is up to you.
bleauhaus
11-05-2009, 02:26 PM
Absolutly! ok i got it to close out the trades now i have to figure out how to get it to use 20 min bars instead of 1 min bars...
NinjaTrader_Josh
11-05-2009, 02:33 PM
Open a 20min chart and add the strategy onto that chart. That will run it on 20 mins. If you open a 1 min chart, it runs on 1min, etc.