{
private double StopPrice;
private CDSwing CDSwing1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
StopPrice = 1;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
else if (State == State.DataLoaded)
{
ATR1 = ATR(Close, 14);
EMA1 = EMA(Close, 10);
CDSwing1 = CDSwing(Close, 5);
SetProfitTarget("", CalculationMode.Currency, 800);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 2
if (Position.MarketPosition == MarketPosition.Long)
{
StopPrice = CDSwing1.SwingLow[0];
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), StopPrice, "", "");
}
// Set 3
if (Position.MarketPosition == MarketPosition.Short)
{
StopPrice = CDSwing1.SwingHigh[1];
ExitShortStopMarket(Convert.ToInt32(DefaultQuantit y), StopPrice, "", "");
}
}