For various reasons (mainly since I eventually plan to send Stop Loss orders to different BarsArrays) I have been trying to build a way to do Stop Loss orders without using your SetStopLoss() method.
Using your Strategy Wizard, I built a strategy that is supposed to exit a Long trade once it has a loss of 10 ticks.
For some reason, when I test it out in the Strategy Analyzer, it immediately exits a trade after the order is filled, rather then waiting for a 10 tick loss.
Any idea why this is?
The relevant part of the strategy's code is below. The attached ExitExample.zip contains the full strategy.
Thanks!
public class ExitExample : Strategy
{
#region Variables
// Wizard generated variables
private int stopLoss1 = -10; // Default setting for StopLoss1
// 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(MACD(12, 26, 9));
Add(MACD(12, 26, 9));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Position.MarketPosition == MarketPosition.Flat
&& CrossAbove(MACD(12, 26, 9).Avg, MACD(12, 26, 9), 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (Position.MarketPosition == MarketPosition.Long
&& Open[0] + StopLoss1 * TickSize <= Position.AvgPrice)
{
ExitLong("", "");
}
]

It is doing exactly what you told it to do that you are describing above. The Open is more than 10 ticks lower than the entry, so it exits. You are entering on the Close of the bar (COBC = true), so if the Open to Close range of the bar equals or exceeds 10 ticks, voila.
and say that on a 1-tick BarSeries, a 10-tick Stop Loss will not be rejected. 
Comment