Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 26.11.18
Max2018 Max2018 ist offline
Mitglied
 
Registriert seit: Sep 2018
Beiträge: 238
Max2018 befindet sich auf einem aufstrebenden Ast
Standard 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();
                     }
               }   
         }
   }

Geändert von Max2018 (26.11.18 um 13:21 Uhr)