Just downloaded NT and am trying to use it for Forex and Futures. Having lots of issues.
Problems:
1. I tried running my strategy and it complained about trying to set stop loss above current price or something. I cancelled all open orders and such. Now, when I try to rerun my strategy with some tweaks, it keeps thinking I have open positions even though I am using a simulated account against a real IB data feed. So, now, my strategy doesnt kick in at all because from the get go it thinks I am long instead of flat.
2. For whatever reason the Print statements at the top of my OnBarUpdate event keep getting printed twice each time the event is fired. So, I am beginning to feel, that event is fired once for the bar that just completed, and once for the new bar. Is there anyway to make it fire just once at the close of a bar?
3. I tried running the code with CalculateOnBarClose with True and False and not much difference. With False, the OnBarUpdate keeps firing a lot and with true, only at the end of bar update. But like I said in #2, it fires in pairs regardless of this setting.
My code is below just for reference:
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// 3 Bar Up or Down, go long/short
/// </summary>
[Description("3 Bar Up or Down, go long/short")]
public class RB3BarSetupV2 : Strategy
{
#region Variables
// Wizard generated variables
private int qty = 1; // Default setting for Qty
// 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( PeriodType.Minute, 1);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
//Long signal
if (CurrentBar > 3) {
Print("Close 1:"+Close[1].ToString());
Print("Close 2:"+Close[2].ToString());
Print("Close 3:"+Close[3].ToString());
Print("Market position:"+Position.MarketPosition.ToString());
if ((Close[1] > Close[2] && Close[2] > Close[3]) && Position.MarketPosition == MarketPosition.Flat) {
EnterLong(Qty);
Print("Stop:"+MIN(Low,3)[0]);
//SetStopLoss(CalculationMode.Price,MIN(Low,3)[0]);
ExitLongStop(MIN(Low,3)[0]);
} else if ((Close[1] < Close[2] && Close[2] < Close[3]) && Position.MarketPosition == MarketPosition.Flat) {
EnterShort(Qty);
Print("Current Price:"+Close[0]);
Print("Stop:"+MIN(High,3)[0]);
//SetStopLoss(CalculationMode.Price,MAX(High,3)[0]);
ExitShortStop(MAX(High,3)[0]);
} else if ((Close[1] > Close[2] && Close[2] > Close[3]) && Position.MarketPosition == MarketPosition.Short) {
ExitLong();
} else if ((Close[1] < Close[2] && Close[2] < Close[3]) && Position.MarketPosition == MarketPosition.Long) {
ExitShort();
}
}
}
#region Properties
[Description("")]
[Category("Parameters")]
public int Qty
{
get { return qty; }
set { qty = Math.Max(1, value); }
}
#endregion
}
}
Comment