I have written code that works, but when I try and increase the sample range to anything above 40 days, nothing loads. I have a very powerful PC(s) and have tested things on a tick by tick basis on long sessions for 4000 days. Even for 10 days it takes a very long time. I left it over night last night and nothing too.
This is the first time I have not used DefaultQuantity in SubmitOrder, and have tried the code by using Default quantity instead of the initial '1' (this is the only place possible). I believe you will understand what I am talking about when you read my code. I have also tried it on 2 different computers, and on a number of different products and on intervals from 10 seconds to 60 minutes. Finally, when I launch the strat on a small period upon starting the programme, I get a message saying: "External Data Feed. There is no market data available to drive the simulation engine. affected Order: Buy 2 Stop @ 12098". This is in the DAX, but in every market the affected order is buying 2 Stops @ a certain price.
Here is my code. I look forward to hearing from you greatly!
#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 Reversal60 : Strategy
{
#region Variables
// User defined variables (add any user defined variables below)
private IOrder longOrder = null;
private IOrder shortOrder = null;
#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 = false;
Unmanaged = true;
ExitOnClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(ToTime(Time[0]) > ToTime(8, 00, 00) && ToTime(Time[0]) < ToTime(8, 01, 01))
{
longOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, DefaultQuantity, First607amOHLC().CurrentHigh[0] + (2*TickSize), First607amOHLC().CurrentHigh[0] + (2*TickSize), "Long", "Long Order");
shortOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Stop, DefaultQuantity, First607amOHLC().CurrentLow[0] - (2*TickSize), First607amOHLC().CurrentLow[0] - (2*TickSize), "Short", "Short Order");
}
}
protected override void OnExecution(IExecution execution)
{
// If longOrder (1 lot) filled, cancel shortOrder and submit shortOrder again (2 lots)
if(execution.MarketPosition == MarketPosition.Long
&& execution.Order != null
&& execution.Order.Filled > 0 )
{
double stop = First607amOHLC().CurrentLow[0] - (2*TickSize);
if ( shortOrder != null )
CancelOrder(shortOrder);
shortOrder = null;
shortOrder = SubmitOrder(0, OrderAction.SellShort, OrderType.Stop, 2, First607amOHLC().CurrentLow[0] - (2*TickSize), First607amOHLC().CurrentLow[0] - (2*TickSize), "Short", "Short Order");
}
// If shortOrder1 (1 lot), filled, cancel longOrder1 and submit longOrder1 again (2 lots)
if(execution.MarketPosition == MarketPosition.Short
&& execution.Order != null
&& execution.Order.Filled > 0 )
{
double stop = First607amOHLC().CurrentHigh[0] + (2*TickSize);
if (longOrder != null )
CancelOrder(longOrder);
longOrder = null;
longOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, 2, First607amOHLC().CurrentHigh[0] + (2*TickSize), First607amOHLC().CurrentHigh[0] + (2*TickSize), "Long", "Long Order");
}
}
}
}
Thank again

Comment