1. I want it to not place an order if there has been a sell within the last 1.5 hours
2. I want to sell long position if it crosses below the indicator that I required for its purchase within 25 minutes of its order
I thought the code looked correct to execute these two conditions but when I looked back through the charts there are order executions within 1.5 hours of each other and sometimes the price crosses back below the SMA(400) within 25 minutes of purchasing it and it doesn't sell!
Basically my strategy is trying to buy long positions if the prices crosses the SMA(400) when the SMA(400)>SMA(100) [works] and sell when it crosses the SMA(50) [works]. But if I can get the two conditions listed above to work, my strategy will get me out of losing positions faster and prevent series of buy/sell orders when the SMA(400) and SMA(100) are very close
/// <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(SMA(400));
Add(SMA(100));
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if ((BarsSinceExit() > 90 || BarsSinceExit() == -1)
&& Close[0] > SMA(400)[0]
&& SMA(400)[0] > SMA(100)[0])
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (Close[0] < SMA(100)[0])
{
ExitLong("", "");
}
// Condition set 3
if (Close[0] < SMA(400)[0]
&& BarsSinceEntry() < 25)
{
ExitLong("", "");
}
}
#region Properties
#endregion
}
}
Thank you!
Comment