OK, so I've been able to create an EA that can handle simultaneous modules with different trading parameters that can be run at the same time or toggled on and off. Although I'm running into a wall with a order count handling.
I want to have the EA count MaxTotalPositions against Total Positions for ModuleA and Total Positions for ModuleB. The EA must not exceed Max Total (A=B), but it also must not exceed TotalforModuleA and B respectively. For example, if the MaxTotal is 2, and the ModuleA and B total is one each, then it can't exceed 2. This part is easy. However, if the Max is 2, and the ModuleA is 1, it is still trading up to 2. I've tried calling the orders by magic to make it easier to count but somewhere it's overcounting the MaxPerModule. Does anyone have any idea how to approach this? The code is compiling properly so there's no syntax errors. Here's the portion of the code:
/////////////////////////////////////////////////////////////////////////////
TotalMaxPositions is declared globally at the top of the EA as an "extern" variable
extern double TotalMaxPositions = 2;
//////////////////////////////////////////////////////////////////////////////
//--------------------------------------------------
// MAX POSITIONS ORDER COUNT
//--------------------------------------------------
int TotalCurrentOrders;
int countA=0; int countB=0; int totalA; int totalB;
TotalCurrentOrders = OrdersTotal();
if (TotalCurrentOrders >= TotalMaxPositions) return(0);
else
if (TotalCurrentOrders < TotalMaxPositions)
{
if (countA >= MaxPositionsA) return(0);
if (countA < MaxPositionsA)
for (int posA = 0; posA < totalA; posA++)
{
if (OrderSelect(posA, SELECT_BY_POS) == false) continue;
if (OrderMagicNumber() == MagicA) countA++;
}
if (countB >= MaxPositionsB) return(0);
if (countB < MaxPositionsB)
for (int posB = 0; posB < totalB; posB++)
{
if (OrderSelect(posB, SELECT_BY_POS) == false) continue;
if (OrderMagicNumber() == MagicB) countB++;
}
if (TotalCurrentOrders >= TotalMaxPositions) return(0);
}
I want to have the EA count MaxTotalPositions against Total Positions for ModuleA and Total Positions for ModuleB. The EA must not exceed Max Total (A=B), but it also must not exceed TotalforModuleA and B respectively. For example, if the MaxTotal is 2, and the ModuleA and B total is one each, then it can't exceed 2. This part is easy. However, if the Max is 2, and the ModuleA is 1, it is still trading up to 2. I've tried calling the orders by magic to make it easier to count but somewhere it's overcounting the MaxPerModule. Does anyone have any idea how to approach this? The code is compiling properly so there's no syntax errors. Here's the portion of the code:
/////////////////////////////////////////////////////////////////////////////
TotalMaxPositions is declared globally at the top of the EA as an "extern" variable
extern double TotalMaxPositions = 2;
//////////////////////////////////////////////////////////////////////////////
//--------------------------------------------------
// MAX POSITIONS ORDER COUNT
//--------------------------------------------------
int TotalCurrentOrders;
int countA=0; int countB=0; int totalA; int totalB;
TotalCurrentOrders = OrdersTotal();
if (TotalCurrentOrders >= TotalMaxPositions) return(0);
else
if (TotalCurrentOrders < TotalMaxPositions)
{
if (countA >= MaxPositionsA) return(0);
if (countA < MaxPositionsA)
for (int posA = 0; posA < totalA; posA++)
{
if (OrderSelect(posA, SELECT_BY_POS) == false) continue;
if (OrderMagicNumber() == MagicA) countA++;
}
if (countB >= MaxPositionsB) return(0);
if (countB < MaxPositionsB)
for (int posB = 0; posB < totalB; posB++)
{
if (OrderSelect(posB, SELECT_BY_POS) == false) continue;
if (OrderMagicNumber() == MagicB) countB++;
}
if (TotalCurrentOrders >= TotalMaxPositions) return(0);
}