I have the following strategy, which uses CCI & SMA for buy & sell signals, and it also calls an ATM to move the stop:
protected override void OnBarUpdate()
{
if(Historical)
return;
//Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, Stop);
}
// Condition set 1
if (ToTime(Time[0]) >= ToTime(8, 30, 0)
&& ToTime(Time[0]) <= ToTime(9, 30, 0)
&& CCICustom(CCIPeriod).Buy[0] > 50
&& CCICustom(CCIPeriod).Buy[1] < 50
&& SMA(Fast)[0] > SMA(Fast)[1]
&& SMA(Slow)[0] > SMA(Slow)[1]
&& SMA(Fast)[0] > SMA(Slow)[0])
{
AtmStrategyCreate(Action.Buy, OrderType.Market,0,0,
TimeInForce.Day, GetAtmStrategyUniqueId(),"TestStrategy",
GetAtmStrategyUniqueId());
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.LimeGreen);
Print("Went Long - Close:"+Close[0]);
}
// Condition set 2
if (ToTime(Time[0]) >= ToTime(8, 30, 0)
&& ToTime(Time[0]) <= ToTime(9, 30, 0)
&& CCICustom(CCIPeriod).Sell[0] < -50
&& CCICustom(CCIPeriod).Sell[1] > -50
&& SMA(Fast)[0] < SMA(Fast)[1]
&& SMA(Slow)[0] < SMA(Slow)[1]
&& SMA(Fast)[0] < SMA(Slow)[0])
{
AtmStrategyCreate(Action.Sell, OrderType.Market,0,0,
TimeInForce.Day, GetAtmStrategyUniqueId(),"TestStrategy",
GetAtmStrategyUniqueId());
DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Fuchsia);
Print("Went Short - Close:"+Close[0]);
}
Currently, the way this is written, the strategy will trigger a trade if the conditions are met, whether or not it is already in a trade.
How would I change the code, so that if the strategy triggers a trade, it won't trigger another trade until the current trade is over?

Comment