Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Offene Positionen abfragen (http://www.expert-advisor.com/forum/showthread.php?t=2873)

feelfree 19.04.13 14:53

Offene Positionen abfragen
 
Servus zusammen,

mal wieder stehe ich vor einem kleinen Rätsel.

Wie kann ich meine tatsächlich offenen Positionen abfragen?
Also quasi OrdersTotal minus PendingOrders.

Wer hat Ideen??? :)

Besten Dank und Grüße,
Dan

Deepack 19.04.13 23:00

hi
ja mit einer for schleife gehst du alle orders durch

und mit if (ordertyp() == OP_SELL)...
OP_BUY, usw. kannst du abfragen um welchen ordertyp es sich handelt

lg

Racki 20.04.13 00:49

Du meinst sowas?

PHP-Code:

//+------------------------------------------------------------------+
//| Anzahl der Longpositionen                                        |
//+------------------------------------------------------------------+
int CountLong(string countLongSymbolint countLongMagic)
{
   
int CountLongReturn 0;
   if (
OrdersTotal() > )
   {
       for(
int counterCountLong 0counterCountLong OrdersTotal(); counterCountLong++)
       {
           
OrderSelect(counterCountLongSELECT_BY_POSMODE_TRADES);
           if(
OrderSymbol() == countLongSymbol && OrderMagicNumber() == countLongMagic)
           {
              if(
OrderType() == OP_BUY)
                 {
                    
CountLongReturn++;
                 }
           }
       }
   }
   return (
CountLongReturn);
}
//+------------------------------------------------------------------+
//| Anzahl der Shortpositionen                                       |
//+------------------------------------------------------------------+
int CountShort(string countShortSymbolint countShortMagic)
{
   
int CountShortReturn 0;
   if (
OrdersTotal() > )
   {
       for(
int counterCountShort 0counterCountShort OrdersTotal(); counterCountShort++)
       {
           
OrderSelect(counterCountShortSELECT_BY_POSMODE_TRADES);
           if(
OrderSymbol() == countShortSymbol && OrderMagicNumber() == countShortMagic)
           {
              if(
OrderType() == OP_SELL)
                 {
                    
CountShortReturn++;
                 }
           }
       }
   }
   return (
CountShortReturn);


So bekommst du mit
PHP-Code:

int AnzahlLong CountLong(Symbol(),Magic);
int AnzahlShort CountShort(Symbol(),Magic); 

die jeweilige Anzahl der offenen Typen.

feelfree 20.04.13 13:56

Servus und vielen Dank für die Hammer Antwort. :)

die beiden int Count Funktionen hab ich erfolgreich einbauen können aber die beiden Zeilen zur Abfrage der Werte wollen noch nicht so recht.

Bei
int AnzahlLong = CountLong(Symbol(),Magic);
int AnzahlShort = CountShort(Symbol(),Magic);

heißt es immer "Initialization expexted".

Und wenn ich die Werte von CountLong oder CountShort in einer anderen Abfrage nutzen will heißt es das beide Variablen nicht definiert sind.

Hintergrund dazu:
Für meinen EA gibt es fest definierte Zeiten, die mit TradingTime() abgefragt werden. Er soll allerdings weiterarbeiten solange noch eine Position offen ist.
Abgekürzt:

Code:

bool TradingTime()
{
    {
    if ((AnzahlLong > 0) || (AnzahlShort > 0)) return(true);
    }       
 return(false);
}

Ohne diese Abfrage stellt er nämlich die Arbeit (Close oder Modify) konsequent ein und die Position bleibt sich selbst überlassen.

Danke für eure tatkräftige Unterstützung. :)

Dan

feelfree 20.04.13 16:37

gelöst
 
mit diesem Code läuft's:

Code:

    if (OrdersTotal() > 0 )
      {
      OrderSelect(SELECT_BY_POS, MODE_TRADES);
      {
      if((OrderType() == OP_SELL)||(OrderType() == OP_BUY))  return(true);
      }
      }

Nochmals vielen Dank an Racki und Deepack


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:14 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum