The desired trigger is:
close[1] < EntryPrice * StopPrice. I've attached code. What am I doing wrong here? Bear in mind I'm not a programmer. I can get by in thinkscript, but C# is well beyond my skill set. Most of the code was generated by the wizard. Thanks in advance!
region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class RSI2PerLongCrossover : Strategy
{
private RSI RSI1;
private double entryPrice;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"2 Period RSI Crossover Trade";
Name = "RSI2PerLongCrossover";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
RSI_OS = 10;
RSI_OB = 85;
RSI_Len = 2;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
RSI1 = RSI(Close, Convert.ToInt32(RSI_Len), 3);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if (CrossBelow(RSI1.Default, RSI_OS, 1))
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"RSICrossoverLongEntry");
}
// Set 2
if ((CrossAbove(RSI1.Default, RSI_OB, 1)))
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"RSICrossoverLongExit", "");
}
//Set 3
if (Close[0] <= entryPrice * 0.999)
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"RSICrossoverLongStop", "");
}
}
region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="RSI_OS", Order=1, GroupName="Parameters")]
public int RSI_OS
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="RSI_OB", Order=2, GroupName="Parameters")]
public int RSI_OB
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="RSI_Len", Order=3, GroupName="Parameters")]
public int RSI_Len
{ get; set; }
#endregion
}
}
Edit: Figured it out. EntryPrice isn't a valid function, or variable, or method, or call, or God knows whatever it is, but Position.AveragePrice is!

Comment