Your interactive trading laboratory!
 • 
5 users online

Backtester - Conditional Checks for open positions

I wonder if the backtester makes a difference between the two conditional checks below for open positions? The first is the one which is created by the model designer, the second is a more realistic one, since I only would jump into the sell condition block if i definitely have an open position. Are these conditions treated different by the backtester engine?

Model Based Condition:

if (HasOpenPosition(bars, PositionType.Long) == false)
{
  PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx] + ((bars.Close[idx] / 100) * 0.5), 0);
}
else
{
  Position longPosition = FindOpenPosition(0);
  ClosePosition(longPosition, OrderType.Limit, (longPosition.EntryPrice + ((longPosition.EntryPrice / 100) * pctgProfitTaker)));
}

Explicitly Condition:

if (HasOpenPosition(bars, PositionType.Long) == false)
{
  PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx] + ((bars.Close[idx] / 100) * 0.5), 0);
}

if (HasOpenPosition(bars, PositionType.Long) == true)
{
  Position longPosition = FindOpenPosition(0);
  ClosePosition(longPosition, OrderType.Limit, (longPosition.EntryPrice + ((longPosition.EntryPrice / 100) * pctgProfitTaker)));
}
Attachment

Cancel

Responses

I think that if you have a long and short system, the model-based code will fall into the else, and it looks like it will execute some extraneous ClosePosition calls. This won't have any impact, they'll just be ignored, but will consume some cycles. Your revision makes more sense and I'll work on changing the generated code to something like that!

I think that if you have a long and short system, the model-based code will fall into the else, and it looks like it will execute some extraneous **ClosePosition** calls. This won't have any impact, they'll just be ignored, but will consume some cycles. Your revision makes more sense and I'll work on changing the generated code to something like that!
Forum Tips

Please sign in if you want to participate in our forum.

Our forum uses Markdown syntax to format posts.

To embed code snippets, enclose them in [CODE][/CODE] tags.