static void AnalyseEntry(int bar)
{
// Do not send entry order when we are not on time
if (openTimeExec == ExecutionTime.AtBarOpening && Strategy.Slot[Strategy.OpenSlot].Component[0].Value[bar] < 0.5)
return;
// Determining of the buy/sell entry price
double openLongPrice = 0;
double openShortPrice = 0;
for (int comp = 0; comp < Strategy.Slot[Strategy.OpenSlot].Component.Length; comp++)
{
IndComponentType compType = Strategy.Slot[Strategy.OpenSlot].Component[comp].DataType;
if (compType == IndComponentType.OpenLongPrice)
openLongPrice = Strategy.Slot[Strategy.OpenSlot].Component[comp].Value[bar];
else if (compType == IndComponentType.OpenShortPrice)
openShortPrice = Strategy.Slot[Strategy.OpenSlot].Component[comp].Value[bar];
else if (compType == IndComponentType.OpenPrice || compType == IndComponentType.OpenClosePrice)
openLongPrice = openShortPrice = Strategy.Slot[Strategy.OpenSlot].Component[comp].Value[bar];
}
// Decide whether to open
bool canOpenLong = openLongPrice > InstrProperties.Point;
bool canOpenShort = openShortPrice > InstrProperties.Point;
if (Configs.UseLogicalGroups)
{
foreach (string group in openingLogicGroups)
{
bool groupOpenLong = canOpenLong;
bool groupOpenShort = canOpenShort;
EntryLogicConditions(bar, group, openLongPrice, openShortPrice, ref groupOpenLong, ref groupOpenShort);
groupsAllowLong[group] = groupOpenLong;
groupsAllowShort[group] = groupOpenShort;
}
bool groupLongEntry = false;
foreach (KeyValuePair<string, bool> groupLong in groupsAllowLong)
if ((groupsAllowLong.Count > 1 && groupLong.Key != "All") || groupsAllowLong.Count == 1)
groupLongEntry = groupLongEntry || groupLong.Value;
bool groupShortEntry = false;
foreach (KeyValuePair<string, bool> groupShort in groupsAllowShort)
if ((groupsAllowShort.Count > 1 && groupShort.Key != "All") || groupsAllowShort.Count == 1)
groupShortEntry = groupShortEntry || groupShort.Value;
canOpenLong = canOpenLong && groupLongEntry && groupsAllowLong["All"];
canOpenShort = canOpenShort && groupShortEntry && groupsAllowShort["All"];
}
else
{
EntryLogicConditions(bar, "A", openLongPrice, openShortPrice, ref canOpenLong, ref canOpenShort);
}
if (canOpenLong && canOpenShort && Math.Abs(openLongPrice - openShortPrice) < micron)
{
session[bar].BacktestEval = BacktestEval.Ambiguous;
}
else
{
if (canOpenLong)
SetEntryOrders(bar, openLongPrice, PosDirection.Long, TradingSize(Strategy.EntryLots, bar));
if (canOpenShort)
SetEntryOrders(bar, openShortPrice, PosDirection.Short, TradingSize(Strategy.EntryLots, bar));
}
return;
}