Expert Advisor öffnet viele kleine Positionen gleichzeitig

Einloggen oder registrieren, um einen Kommentar zu schreiben
Kay7667
340
Kay7667  

Guten Tag leute, und zwar habe ich folgendes Problem,


und zwar tut der EA was er machen soll, er geht bei bestimmten Kerzenformationen Long/Short, nur eröffnet er nicht eine einzige, sondern viele kleine Positionen gleichzeitig.

Den EA habe ich hier downgeloaded und für meine zwecke geändert.

Nur weiß ich nicht, was im Code falsch geschrieben sein soll,

HIer der EA

#include <OCL_Patterns\RevPatterns.mqh>
#include <Trade\Trade.mqh>
#include <OCL_Patterns\Duration.mqh>
// input parameters
input int      inp_ref     =   100;
input int      inp_tp      = 29927;    // Take Profit in Punkten
input int      inp_sl      = 34043;    // Stop Loss in Punkten
input int      inp_timeout =   2534;   // Zeit in Stunden
input double   inp_lot_size= 0.1;      // Lot Anzahl

input bool     inp_bullish_pattern = true;
input bool     inp_bearish_pattern = true;
input bool     inp_bullish_pattern_2 = true;
input bool     inp_bearish_pattern_2 = true;
input bool     inp_bullish_pattern_3 = true;
input bool     inp_bearish_pattern_3 = true;
input bool     inp_bullish_pattern_4 = true;
input bool     inp_bearish_pattern_4 = true;
input bool     inp_bullish_pattern_5 = true;
input bool     inp_bearish_pattern_5 = true;
input bool     inp_bullish_pattern_6 = true;
input bool     inp_bearish_pattern_6 = true;
input bool     inp_bullish_pattern_7 = true;
input bool     inp_bearish_pattern_7 = true;


CTrade      trade;      // trading class
CDuration   time;       // class for working with the duration between reference points
uint        p_flags;    // pattern flags
double      distSL,     // SL distance as price
            distTP;     // TP distance as price
double      calcSL,     // SL calculated as price
            calcTP;     // TP calculated as price

//+------------------------------------------------------------------+
int OnInit()
  {
   time.Start();
   p_flags=0;
   if(inp_bullish_pattern)      p_flags|=PAT_BULLISH_PATTERN;
   if(inp_bearish_pattern)      p_flags|=PAT_BEARISH_PATTERN;
   if(inp_bullish_pattern_2)    p_flags|=PAT_BULLISH_PATTERN_2;
   if(inp_bearish_pattern_2)    p_flags|=PAT_BEARISH_PATTERN_2;
   if(inp_bullish_pattern_3)    p_flags|=PAT_BULLISH_PATTERN_3;
   if(inp_bearish_pattern_3)    p_flags|=PAT_BEARISH_PATTERN_3;
   if(inp_bullish_pattern_4)    p_flags|=PAT_BULLISH_PATTERN_4;
   if(inp_bearish_pattern_4)    p_flags|=PAT_BEARISH_PATTERN_4;
   if(inp_bullish_pattern_5)    p_flags|=PAT_BULLISH_PATTERN_5;
   if(inp_bearish_pattern_5)    p_flags|=PAT_BEARISH_PATTERN_5;
   if(inp_bullish_pattern_6)    p_flags|=PAT_BULLISH_PATTERN_6;
   if(inp_bearish_pattern_6)    p_flags|=PAT_BEARISH_PATTERN_6;
   if(inp_bullish_pattern_7)    p_flags|=PAT_BULLISH_PATTERN_7;
   if(inp_bearish_pattern_7)    p_flags|=PAT_BEARISH_PATTERN_7;
   
   distSL=inp_sl*_Point;
   distTP=inp_tp*_Point;

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   time.Stop();
   Print("Test lasted "+time.ToStr());
  }

//+------------------------------------------------------------------+
bool IsNewBar(void)
  {
   static datetime tprev=0;
   datetime tcur=iTime(_Symbol,_Period,0);
   if(tprev!=tcur)
     {
      tprev=tcur;
      return true;
     }
   else
      return false;
  }

//+------------------------------------------------------------------+
void OnTick()
  {
                                                      // handle open positions
   int total= PositionsTotal();
   for(int i=0;i<total;i++)
     {
      PositionSelect(_Symbol);
      datetime t0=datetime(PositionGetInteger(POSITION_TIME));
      if(TimeCurrent()>=(t0+(inp_timeout*3600)))
        {
         trade.PositionClose(PositionGetInteger(POSITION_TICKET));
        }
      else
         break;
     }

   if(IsNewBar()==false)
      return;

   ENUM_PATTERN pat=IsPattern(p_flags,inp_ref);       // check if the pattern is present
   if(pat==PAT_NONE)
      return;

   double candleSize=iHigh(_Symbol,_Period,1)-        // höhe der Kerze 1 berechnen
                     iLow (_Symbol,_Period,1);
                                                      // open positions
   double ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   double bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);

  
  
  
   if((pat&(PAT_BULLISH_PATTERN))!=0)
      {  // buy
         calcSL=NormalizeDouble(ask-distSL,_Digits);
         calcTP=NormalizeDouble(ask+distTP,_Digits);
         trade.Buy (inp_lot_size,_Symbol,ask,calcSL,calcTP);
      }
   else
      {  // sell
         calcSL=NormalizeDouble(bid+distSL,_Digits);
         calcTP=NormalizeDouble(bid-distTP,_Digits);
         trade.Sell(inp_lot_size,_Symbol,bid,calcSL,calcTP);
      }
      
 
 
 
 
 
 
 
  if((pat&(PAT_BULLISH_PATTERN_2))!=0)
      {  // buy
         calcSL=NormalizeDouble(ask-distSL,_Digits);
         calcTP=NormalizeDouble(ask+distTP,_Digits);
         trade.Buy (inp_lot_size,_Symbol,ask,calcSL,calcTP);
      }
   else
      {  // sell
         calcSL=NormalizeDouble(bid+distSL,_Digits);
         calcTP=NormalizeDouble(bid-distTP,_Digits);
         trade.Sell(inp_lot_size,_Symbol,bid,calcSL,calcTP);
      }
      
 
 
 
 
 
 
 
  if((pat&(PAT_BULLISH_PATTERN_3))!=0)
      {  // buy
         calcSL=NormalizeDouble(ask-distSL,_Digits);
         calcTP=NormalizeDouble(ask+distTP,_Digits);
         trade.Buy (inp_lot_size,_Symbol,ask,calcSL,calcTP);
      }
   else
      {  // sell
         calcSL=NormalizeDouble(bid+distSL,_Digits);
         calcTP=NormalizeDouble(bid-distTP,_Digits);
         trade.Sell(inp_lot_size,_Symbol,bid,calcSL,calcTP);
      }
   
 
 
 
 
 
 
  if((pat&(PAT_BULLISH_PATTERN_4))!=0)
      {  // buy
         calcSL=NormalizeDouble(ask-distSL,_Digits);
         calcTP=NormalizeDouble(ask+distTP,_Digits);
         trade.Buy (inp_lot_size,_Symbol,ask,calcSL,calcTP);
      }
   else
      {  // sell
         calcSL=NormalizeDouble(bid+distSL,_Digits);
         calcTP=NormalizeDouble(bid-distTP,_Digits);
         trade.Sell(inp_lot_size,_Symbol,bid,calcSL,calcTP);
      }
      
  
  
  
  
  
  
  
  
  if((pat&(PAT_BULLISH_PATTERN_5))!=0)
      {  // buy
         calcSL=NormalizeDouble(ask-distSL,_Digits);
         calcTP=NormalizeDouble(ask+distTP,_Digits);
         trade.Buy (inp_lot_size,_Symbol,ask,calcSL,calcTP);
      }
   else
      {  // sell
         calcSL=NormalizeDouble(bid+distSL,_Digits);
         calcTP=NormalizeDouble(bid-distTP,_Digits);
         trade.Sell(inp_lot_size,_Symbol,bid,calcSL,calcTP);
      }
      
   
   
  
  
  
  
  
   if((pat&(PAT_BULLISH_PATTERN_6))!=0)
      {  // buy
         calcSL=NormalizeDouble(ask-distSL,_Digits);
         calcTP=NormalizeDouble(ask+distTP,_Digits);
         trade.Buy (inp_lot_size,_Symbol,ask,calcSL,calcTP);
      }
   else
      {  // sell
         calcSL=NormalizeDouble(bid+distSL,_Digits);
         calcTP=NormalizeDouble(bid-distTP,_Digits);
         trade.Sell(inp_lot_size,_Symbol,bid,calcSL,calcTP);
      }
      
      
      
 
 
 
  if((pat&(PAT_BULLISH_PATTERN_7))!=0)
      {  // buy
         calcSL=NormalizeDouble(ask-distSL,_Digits);
         calcTP=NormalizeDouble(ask+distTP,_Digits);
         trade.Buy (inp_lot_size,_Symbol,ask,calcSL,calcTP);
      }
   else
      {  // sell
         calcSL=NormalizeDouble(bid+distSL,_Digits);
         calcTP=NormalizeDouble(bid-distTP,_Digits);
         trade.Sell(inp_lot_size,_Symbol,bid,calcSL,calcTP);
      }
  }
Otto Pauser
1401
Otto Pauser  

Musst du abfragen ob bereits Position offen

if(PositionSelect(_Symbol))
  {
    PositionVerwalten
  }
else
  {
    CheckAufPositionseröffnung
  }
Kay7667
340
Kay7667  
Otto Pauser:

Musst du abfragen ob bereits Position offen

Vielen Dank, kriegt dieser Code eine eigene Zeile ? Oder muss etwas ersetzt werden ? 
Mit freundlichen Grüßen. 
Otto Pauser
1401
Otto Pauser  
Manchmal versteh ich euch wirklich nicht
amando
1435
amando  
Otto Pauser:
Manchmal versteh ich euch wirklich nicht

Also ich finde Deine Antwort sehr eindeutig Otto, da sollten keine fragen offen bleiben

Einloggen oder registrieren, um einen Kommentar zu schreiben