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)
-   -   Nur eine Position (http://www.expert-advisor.com/forum/showthread.php?t=6266)

Max2018 26.11.18 12:58

Nur eine Position
 
Hallo,
ich finde einfach den Fehler nicht.

Es soll nur EINE position eröffnet werden. Obwohl ich die Deals zähle eröffnet er mir dutzende Positionen ....
HILFEEEE

Code:


input string  u9="000000000000000000000000000000000000000000000000000000000000O00000000";
 
input int EINSATZpunkte=1;
input double MARGE=1;
double spreadReal=Bid-Ask;
int Slippage=3;
int MagicNumber1=MathRand();
double AB3,AB2,AB,StopLoss,LINIE_1,TakeProfit,LINIE_2,ABAB,AB4,AB5,AB6,AB7,AB8,AB9,AB10,AB11,AB12,AB13,SchliessZeit,LINIE_3,LINIE_4,LINIE_5,LINIE_6,LINIE_7,LINIE_8,LINIE_9,LINIE_10,LINIE_11,LINIE_12,LINIE_13;
datetime SignalTime, Waitzeit, WaitzeitTP, CurrentTimeStamp ; 
datetime Time_bar = 0;
int      UseSlippage,UseSpread,UseSL,UseTagesSL,Order,LotsRundung,DealCount,LongCount,ShortCount,BuyLimits,SellStops,LastTicket;
int      MagicNumber=MathRand();
int init()
    {
   
CurrentTimeStamp = Time[0] ;
 

}
 
//---

int start()
  { 
//++++++++++++++++++++++++++++++++++++NEW BAR ABFRAGEN
  bool NewBar = false ;
if (Time[0]  != CurrentTimeStamp)
  {
  NewBar = true ;
  CurrentTimeStamp = Time[0] ;
  }
//++++++++++++++++++++++++++++++++++++ NEW BAR ENDE
  double MyPoint=1;
  double TheStopLoss=0;
  double TheTakeProfit=0;
       
// ERKENNEN DER NACHKOMMASTELLEN
  int NACHKOMMA=MarketInfo(Symbol(),MODE_DIGITS);
double Lots;
if(NACHKOMMA==5)Lots=0.01*EINSATZpunkte;
if(NACHKOMMA==3)Lots=0.01*EINSATZpunkte;
if(NACHKOMMA==2)Lots=0.1*EINSATZpunkte;
if(NACHKOMMA==1)Lots=0.1*EINSATZpunkte;
// +++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++ 
        //NEU PREIS-START
        //NEU PREIS-START
        //NEU PREIS-STARTdouble price[31];
double price[300];
double priceSL[300];
double priceZIEL[300];
int result[300];
int STOPTrade=0;

int STOPTrade1=0;
int PositionEroeffnet[300];
int LastTicketAlt=LastTicket;
DealCounter();
 
if(ShortCount==0&&SellStops==0);
for (int vv = 0; vv <= 300; vv++)
{
//Hier werden der Start, Ziel und SL eines jeden Objektes ausgelesen
 
  price[vv] = NormalizeDouble(ObjectGetDouble(0,vv,OBJPROP_PRICE2),NACHKOMMA); 
  priceSL[vv] = NormalizeDouble(ObjectGetDouble(0,vv,OBJPROP_PRICE1),NACHKOMMA)-NormalizeDouble(spreadReal,NACHKOMMA);  // da spreadReal negativ hier minus !
  priceZIEL[vv] =NormalizeDouble(price[vv]-((priceSL[vv]-price[vv])*MARGE),NACHKOMMA);

  result[vv]=0; 
  if(DealCount==0)result[vv]=OrderSend(Symbol(),OP_SELLSTOP,Lots,price[vv],Slippage,0,0,"X"+MARGE+"_"+MagicNumber,MagicNumber,0,Blue);
  ObjectsDeleteAll(0,OBJ_ARROW);
  TheStopLoss=priceSL[vv]+100;
  TheTakeProfit=priceZIEL[vv];
  if(StopLoss>0) TheStopLoss=priceSL[vv];
  OrderSelect(result[vv],SELECT_BY_TICKET);
  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
  if(Open[0]>priceSL[vv])OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
  if(Open[0]>priceSL[vv])STOPTrade=0;
  if(price[vv]>0)PositionEroeffnet[vv]=price[vv];
      Comment (result[vv]);
      if(ShortCount>0||SellStops>0)break;
}

//ALLES-LÖSCHEN
//ALLES-LÖSCHEN
if (Hour()==9)
{
  int total = OrdersTotal();
  for(int i=total-1;i>=0;i--)
  {
    if (!OrderSelect(i, SELECT_BY_POS)) continue;
    if (OrderSymbol() != Symbol())      continue;
    int type  = OrderType();

    bool result1 = false;
   
    switch(type)
    {
      //Close opened long positions
      case OP_BUY      : result1 = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                          break;
     
      //Close opened short positions
      case OP_SELL      : result1 = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                         
                          break;

      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP  :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result1 = OrderDelete( OrderTicket() );
    }
   
    if(result1 == false)
    {
      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    } 
  }
  return(0);
}
 

}
void DealCounter()
  {
      //Loop through current deal pool
      DealCount = 0;
      LongCount = 0;
      ShortCount = 0;
      BuyLimits=0;SellStops=0;
      LastTicket=-1;
      for(int Count = 0; Count<=OrdersTotal()-1 ; Count++)
        {
            if(OrderSelect(Count,SELECT_BY_POS,MODE_TRADES))
              {
                  if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
                    {
                        if(OrderType()==OP_BUY)
                          {
                              LongCount++;
                              DealCount++;
                          }
                        else if(OrderType()==OP_SELL)
                          {
                              ShortCount++;
                              DealCount++;
                          } 
                        else if(OrderType()==OP_BUYLIMIT)BuyLimits++;
                        else if(OrderType()==OP_SELLSTOP)SellStops++;
                        LastTicket=OrderType();
                    }
              } 
        }
  }


Max2018 26.11.18 13:24

also um diesen Teil gehts:
Code:

for (int vv = 0; vv <= 300; vv++)
{
//Hier werden der Start, Ziel und SL eines jeden Objektes ausgelesen
 
  price[vv] = NormalizeDouble(ObjectGetDouble(0,vv,OBJPROP_PRICE2),NACHKOMMA); 
  priceSL[vv] = NormalizeDouble(ObjectGetDouble(0,vv,OBJPROP_PRICE1),NACHKOMMA)-NormalizeDouble(spreadReal,NACHKOMMA);  // da spreadReal negativ hier minus !
  priceZIEL[vv] =NormalizeDouble(price[vv]-((priceSL[vv]-price[vv])*MARGE),NACHKOMMA);

  result[vv]=0; 
  if(DealCount==0)result[vv]=OrderSend(Symbol(),OP_SELLSTOP,Lots,price[vv],Slippage,0,0,"X"+MARGE+"_"+MagicNumber,MagicNumber,0,Blue);
  ObjectsDeleteAll(0,OBJ_ARROW);
  TheStopLoss=priceSL[vv]+100;
  TheTakeProfit=priceZIEL[vv];
  if(StopLoss>0) TheStopLoss=priceSL[vv];
  OrderSelect(result[vv],SELECT_BY_TICKET);
  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
  if(Open[0]>priceSL[vv])OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
  if(Open[0]>priceSL[vv])STOPTrade=0;
  if(price[vv]>0)PositionEroeffnet[vv]=price[vv];
      Comment (result[vv]);
      if(ShortCount>0||SellStops>0)break;
}

Der DealCount bezieht sich auf den void DealCounter();
....selbst wenn ich den davor setze zählt der nicht....

Code:

DealCounter(); 
  if(DealCount==0)result[vv]=OrderSend(Symbol(),OP_SELLSTOP,Lots,price[vv],Slippage,0,0,"X"+MARGE+"_"+MagicNumber,MagicNumber,0,Blue);


AVT 26.11.18 19:59

So auf die Schnelle überflogen wie ich das verstehe:

In DealCounter() zählst Du die Positionen. Die müssen aber auch als Resultat irgendwie erscheinen, also muß die Funktion nicht void sein, sondern int (weil sie einen integer Wert ausgeben soll) und dann müssen alle Zählungen addiert werden und als Resultat mit return(Resultat) am Ende der Funktion ausgespuckt werden.

Dann kannst Du ein Abfrage machen, wenn DealCounter()==0, das heißt, wenn die DealCounter() Funktion Null ausspuckt weil es noch keine Positionen gibt, dann ... könnte er 1 Position öffnen zum Beispiel.

Bei Dir steht aber wenn DealCount==0, wo ist der Bezug zum DealCounter(), wenn es einen geben sollte?

Hoffentlich hab ich das nicht zu schnell überflogen und es ist das, was Du brauchst. AVT


Alle Zeitangaben in WEZ +2. Es ist jetzt 02:40 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