If Macd daily fast period value is below 0 it only take short position.
If Macd daily fast period value is above 0 it only take long position.
I try the estrategy on charts and it makes trades during a period but suddenly it doesn't works for the rest of the chart
I try it on AIG chart from january the first, and the mistake appears on may the nineth, is the first day daily macd falls below 0, and appears an stoplongentry order on the chart that coincide with 16:00bar max of the nineth.
Here I let you the code, do you see what is going wrong?
// 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")]
publicclass RotRangH : Strategy
{
#region Variables
// Wizard generated variables
privatedouble stoploss = 0.030; // Default setting for Stoploss
// 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>
protectedoverridevoid Initialize()
{
Add (PeriodType.Day, 1);
SetStopLoss("", CalculationMode.Percent, Stoploss, false);
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
if (BarsInProgress != 0)
return;
// Checks if the macd daily fast period is above 0 and time in 30min bars is 16:00,
//then gives variable0 value= high 16:00(30minbar) and enter a stop longposition at value0
if (MACD(BarsArray[1], 12, 26, 9)[0] > 0 && ToTime(Time[0]) == 160000)
Variable0 = High[0] + 1*TickSize;
EnterLongStop(DefaultQuantity, Variable0, "");
// Checks if the macd daily fast period is below 0 and time in 30min bars is 16:00,
//then gives variable1 value= Low 16:00(30minbar) and enter a stop shortposition at value1
if (MACD(BarsArray[1], 12, 26, 9)[0] < 0 && ToTime(Time[0]) == 160000)
Variable1 = Low[0] - 1*TickSize;
EnterShortStop(DefaultQuantity, Variable1, "");
}

Comment