I have two separate Strategies that are made to work together. Because they are separate I have learned that I cannot test them in the strategy optimizer together, therefore I am testing them in the playback connection feed.
I have both strategies calculate OnEachTick. One Strategy (strat name = LS) places a long order 4 ticks above the open of bar[0] and the other (strat name = SS) places it 4 ticks below the open. Sometimes, either strategy may be in a position when a new bar appears. To prevent one strategy from placing new orders while the other strategy is till in a position, I inserted a CancelOrder logic. Below are some snippets of my codes.
Strategy : LS (Calculate = Calculate.OnEachTick)
{
public static bool IsLong;
private static Order LongOrder;
Benchmark = Open[0]
OnBarUpdate()
{
if GetCurrentBid||Ask == Benchmark
EnterLongStopMarket(...."LSEntry")
if (Position.MarketPosition == MarketPosition.Long)
IsLong = true
if (SS.IsShort == true)
CancelOrder(LongOrder)
}
}
protected override void OnOrderUpdate ()
{
if (order.Name == "LSEntry")
LongOrder = order;
}
Strategy : SS (Calculate = Calculate.OnEachTick)
{
public static bool IsShort;
private static Order ShortOrder;
Benchmark = Open[0]
if GetCurrentBid||Ask == Benchmark
EnterLongStopMarket(...."SSEntry")
if (Position.MarketPosition == MarketPosition.Short)
IsShort = true
if (LS.IsLong == true)
CancelOrder(ShortOrder)
}
protected override void OnOrderUpdate ()
{
if (order.Name == "SSEntry")
ShortOrder = order;
}
After inserting the CancelOrder Logic and I run the strategy on any day in the playback connection, the playback will tend to glitch and stall, sometimes staying frozen in time from anywhere between a few seconds to just crashing my PC at times when the strategy cancels orders upon the open of a new bar, making backtesting quite unbearable. This also happens when the market reaches a stoploss. I assume that because of Calculate OnEachTick, there is so much data coming in that will hinder the performance of my computer. Is is possible to have the CancelOrder method calculate on something else so that the backtesting process may be smoother?
Comment