protected override void OnBarUpdate()
{
/* Checks to see if the time is during the busier hours (format is HHMMSS or HMMSS). Only allow trading if current time is during a busy period.
The timezone used here is (GMT-05:00) EST. */
if ((ToTime(Time[0]) >= 093000 && ToTime(Time[0]) < 161400))
{
// Condition set 1
if (CrossBelow(ZLEMA(myInput0), SMA(myInput1), 1))
{
EnterShort(DefaultQuantity, "");
}
// Condition set 2
if (CrossAbove(ZLEMA(myInput0), SMA(myInput1), 1))
{
ExitShort("", "");
}
// At the start of a new session
if (Bars.FirstBarOfSession)
{
// Store the strategy's prior number of trades
priorTradesCount = Performance.AllTrades.Count;
/* NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
If you want to only count profits from real-time trades please use .RealtimeTrades. */
}
/* prevent trading if 1 trades have already been made in this session. */
if (Performance.AllTrades.Count - priorTradesCount > 1)
{
/* TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well. */
// Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
return;
}
}
}
Comment