Hallo,
wie man die Anzahl der Positionen zählt habe ich hier schon mal irgendwo gepostet. Das geht hiermit:
PHP-Code:
//+------------------------------------------------------------------+
//| Anzahl der Longpositionen |
//+------------------------------------------------------------------+
int CountLong(string countLongSymbol, int countLongMagic)
{
int CountLongReturn = 0;
if (OrdersTotal() > 0 )
{
for(int counterCountLong = 0; counterCountLong < OrdersTotal(); counterCountLong++)
{
OrderSelect(counterCountLong, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == countLongSymbol && OrderMagicNumber() == countLongMagic)
{
if(OrderType() == OP_BUY)
{
CountLongReturn++;
}
}
}
}
return (CountLongReturn);
}
Wenn man diese Funktion jetzt etwas abändert, dann kann man auch die Gesamtgröße der Lots berechnen.
PHP-Code:
//+------------------------------------------------------------------+
//| Gesamtgröße der Lots |
//+------------------------------------------------------------------+
double CountLongLots(string countLongSymbol, int countLongMagic)
{
double CountLongLotsReturn = 0.0;
if (OrdersTotal() > 0 )
{
for(int counterCountLong = 0; counterCountLong < OrdersTotal(); counterCountLong++)
{
OrderSelect(counterCountLong, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == countLongSymbol && OrderMagicNumber() == countLongMagic)
{
if(OrderType() == OP_BUY)
{
CountLongLotsReturn+=OrderLots();
}
}
}
}
return (CountLongLotsReturn);
}
Für Short musste das entsprechend ändern, oder einen Schalter als Modus an die Funktion übergeben...
Quasi so:
PHP-Code:
int CountPositions(string countSymbol, int countMagic, int countModus=OP_BUY)
{
int CountReturn = 0;
if (OrdersTotal() > 0 )
{
for(int counter = 0; counter < OrdersTotal(); counter++)
{
OrderSelect(counter, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == countSymbol && OrderMagicNumber() == countMagic)
{
if(OrderType() == countModus)
{
CountReturn++;
}
}
}
}
return (CountReturn);
}
Das ist sogar ne Ecke eleganter.
Für das Aufaddieren der Lotgrößen dann dieses hier:
PHP-Code:
double CountLots(string countSymbol, int countMagic, int countModus=OP_BUY)
{
double CountReturn = 0.0;
if (OrdersTotal() > 0 )
{
for(int counter = 0; counter < OrdersTotal(); counter++)
{
OrderSelect(counter, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == countSymbol && OrderMagicNumber() == countMagic)
{
if(OrderType() == countModus)
{
CountReturn+=OrderLots();
}
}
}
}
return (CountReturn);
}
Hoffe dir geholfen zu haben
Racki