Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
now NT runs a WRONG strategy
Collapse
X
-
now NT runs a WRONG strategy
I try to backtest my strategy: I compiled it, selected an instrument, right-click ->"backtest", selected my strategy from the list - it executes backtest of a different strategy! (one of the sample strategies). What's going on with NT??Tags: None
-
when I select strategies to run, in log "1/22/2013 12:20:07 PM,Strategy,Failed to call method 'Initialize' for strategy 'Strategy001/0b831389c6174f01aa8e73130ff14b4f': Object reference not set to an instance of an object.,
1/22/2013 12:16:44 PM,Strategy,Failed to call method 'Initialize' for strategy 'Strategy001/20b31bc63ee74e7c89deb707af190e79': Object reference not set to an instance of an object.,
"
Other then this there are no log messages during compile or run of strategy. Also, I notice that when I select my test strategy, "label" below and "parameters" above do not change from the previously selected strategy...i.e. it does not really "select it". then it runs NOT my strategy, but previously selected
Comment
-
Here is the whole strategy:
#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>
/// simple gap
/// </summary>
[Description("simple gap")]
public class Strategy001 : Strategy
{
#region Variables
// Wizard generated variables
private int profit = 20; // Default setting for Profit
private int loss = 8; // Default setting for Loss
// User defined variables (add any user defined variables below)
private bool isLowerOpen = false;
private bool isHigherOpen = false;
private double refPrice = 0.0;
private bool tradedToday = false;
#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()
{
SetProfitTarget("Stg001", CalculationMode.Ticks, Profit);
SetTrailStop("Stg001", CalculationMode.Ticks, Loss, false);
CalculateOnBarClose = true;
tradedToday = false;
isLowerOpen = CurrentDayOHL().CurrentOpen[0] < Bars.GetDayBar(1).Low;
isHigherOpen = CurrentDayOHL().CurrentOpen[0] > Bars.GetDayBar(1).High;
if (isLowerOpen)
refPrice = Bars.GetDayBar(1).Low;
else if (isHigherOpen)
refPrice = Bars.GetDayBar(1).High;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (tradedToday)
return;
if (isLowerOpen && Close[0] > refPrice) {
EnterLong(DefaultQuantity, "Stg001");
tradedToday = true;
}
else if (isHigherOpen && Close[0] < refPrice) {
EnterShort(DefaultQuantity, "Stg001");
tradedToday = true;
}
}
#region Properties
[Description("Profit")]
[GridCategory("Parameters")]
public int Profit
{
get { return profit; }
set { profit = Math.Max(1, value); }
}
[Description("Loss")]
[GridCategory("Parameters")]
public int Loss
{
get { return loss; }
set { loss = Math.Max(1, value); }
}
#endregion
}
}
Comment
-
Mark, please move this logic here to the OnBarUpdate() instead - Initialize() could be called multiple times and bars data would not be guaranteed to be available, so for those custom calcs not an ideal processing place.
isLowerOpen = CurrentDayOHL().CurrentOpen[0] < Bars.GetDayBar(1).Low;
isHigherOpen = CurrentDayOHL().CurrentOpen[0] > Bars.GetDayBar(1).High;
if (isLowerOpen)
refPrice = Bars.GetDayBar(1).Low;
else if (isHigherOpen)
refPrice = Bars.GetDayBar(1).High;BertrandNinjaTrader Customer Service
Comment
-
Ok, how do I insure that I calculate isLowerOpen and isHigherOpen only 1 time per day?
These simply compare today's open price with yesterday's low/high:
isLowerOpen = CurrentDayOHL().CurrentOpen[0] < Bars.GetDayBar(1).Low;
isHigherOpen = CurrentDayOHL().CurrentOpen[0] > Bars.GetDayBar(1).High;
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bortz, 11-06-2023, 08:04 AM
|
47 responses
1,606 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
8 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
4 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
13 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Comment