This is my second thread, and since my last post got such a prompt and effective reply from Support, I thought I'd try again!
I'm trying to run a basic strategy based on a custom indicator. When I add the strategy to a chart, the 'print' function in the initialize function is called, and output to the output window "Strategy initiating"
However, I would then expect to see the output message from the OnBarUpdate method being output to the output window i.e. "checking positions" however the window is just blank. This is confusing and tells me that the strategy is not running - but I don't understand why!
Please can you explain why OnBarUpdate is not being called? Thanks in advance Support, and keep up the great work!!!
#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>
/// 24/01/2014 - indicator now apparently working, so writing the strategy to wrap around it. Should be relatively straightforwrad
/// </summary>
[Description("24/01/2014 - indicator now apparently working, so writing the strategy to wrap around it. Should be relatively straightforwrad")]
public class FirstCustomNTStrategyFRES : Strategy
{
#region Variables
// Wizard generated variables
// 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;
Print("Custom Strategy initiating");
FirstNTCustomIndFRES().Plots[0].Pen.Color = Color.Orange;
Add(FirstNTCustomIndFRES());
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(CurrentBar < 100)
{
Print("Not enough bars to calculate, returning");
return;
}
//THIS SECTION CHECKS WHETHER CURRENT ORDER EXISTS, THEN HAS COMBINATION
//OF STATEMENTS FOR EACH INDICATOR OUTPUT
Print("checking positions");
if (Position.MarketPosition == MarketPosition.Flat)//CHECK IF FLAT
{
if (FirstNTCustomIndFRES().Plot0[0] == 1)//BUY
{
EnterLong(DefaultQuantity,"");
Print("No position open, buy signal received - entering long position");
}
if (FirstNTCustomIndFRES().Plot0[0] == 2)//DO NOTHING
{
Print("No position open, sell signal received, no action");
}
if (FirstNTCustomIndFRES().Plot0[0] == 3)//DO NOTHING
{
Print("Hold signal received, no action");
}
if (FirstNTCustomIndFRES().Plot0[0] == 4)//BUY
{
EnterLong(DefaultQuantity,"");
Print("No position open, mixed signal received - entering long position");
}
}
if (Position.MarketPosition == MarketPosition.Long)//CHECK IF POSITION ALREADY EXISTS
{
if (FirstNTCustomIndFRES().Plot0[0] == 1)//DO NOTHING
{
Print("No position open, buy signal received, no action");
}
if (FirstNTCustomIndFRES().Plot0[0] == 2)//SELL
{
ExitLong(DefaultQuantity);
Print("Position open, sell signal received - exiting long position");
}
if (FirstNTCustomIndFRES().Plot0[0] == 3)//DO NOTHING
{
Print("Hold signal received, no action");
}
if (FirstNTCustomIndFRES().Plot0[0] == 4)//SELL
{
ExitLong(DefaultQuantity);
Print("Position open, mixed signal received - exiting long position");
}
}
}
#region Properties
#endregion
}
}
Comment