I don't understand how to apply this within the code.
Ultimately, what i would like to do is take the current candles close price and subtract it from the Open price of 4 candles ago, store the answer, then apply it as the profit target. As for working code examples i made a simply entry code below for examples to be displayed with. Again i would greatly appreciate your help if possible.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class DataHelp : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
private int ProfitTarget = 5; // Define Profit Target
private DataSeries myCalculation; // Define a DataSeries variable
#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;
myCalculation = new DataSeries(this, MaximumBarsLookBack.Infinite);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if( CrossAbove(DM(14).DiMinus, DM(14).DiPlus, 1))
{
myCalculation.Set(Open[4] - Close[0])= ProfitTarget; // Not sure how to place this
EnterShort(DefaultQuantity, "");
SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
public int ProfitTarget
{
get { return ProfitTarget; }
set { ProfitTarget = Math.Max(1, value); }
}
#endregion
}
}
Comment