Einzelnen Beitrag anzeigen
  #8 (permalink)  
Alt 26.01.16
Raul0 Raul0 ist offline
Premium Mitglied
 
Registriert seit: Apr 2015
Beiträge: 422
Raul0 befindet sich auf einem aufstrebenden Ast
Standard

Da ich letztendlich an dem gleichen Problem sitze, wie hier http://www.expert-advisor.com/forum/...html#post32665, poste ich den Code dazu. Wird der EA mehrmals auf Basiswerte und andere Timeframes genutzt, kommt es zu Fehlern und Übertragungen zwischen den Charts.

Was kann dafür verantwortlich sein?

PHP-Code:
#property copyright ""
#include <stdlib.mqh>
 
extern int        Magic                         1001;
extern double     BaseLot                       0.01;

extern int        TakeProfit                    0;
extern int        StopLoss                      200;

extern int        TrailingStopTrigger           50;//if 0 then is not used
extern int        TrailingStopPips              100;

string Version;
int bm;
//+------------------------------------------------------------------+
int init()
  {
//----
   
Version "EA_Test";
   
bm 1;
   if(
MarketInfo(Symbol(),MODE_DIGITS) == ||  MarketInfo(Symbol(),MODE_DIGITS) == 3)       bm 10;
   if(
TakeProfit>0)                 TakeProfit                 =  TakeProfit                 bm;   
   if(
TrailingStopTrigger>0)        TrailingStopTrigger        =  TrailingStopTrigger        bm;
   if(
TrailingStopPips>0)           TrailingStopPips           =  TrailingStopPips           bm;
   if(
StopLoss>0)                   StopLoss                   =  StopLoss                   bm;
//----
   
return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
//---- 

   
double tp 0;      
   
double sl 0;     
   
   
int orders orderCount(-1);
   if(
orders != 0)
   {
      for(
int pos=0;pos<OrdersTotal();pos++)
      {
         
         if(
OrderSelect(pos,SELECT_BY_POS)==false) continue;
         if(
OrderMagicNumber()!=Magic) continue;

         
         
//TRAILING
         
if(TrailingStopTrigger 0)
         {
            if(
OrderType() == OP_BUY)
            {            
               if(
OrderStopLoss() <   Ask - (TrailingStopPips*Point)&& Ask > (OrderOpenPrice()+TrailingStopTrigger*Point))
               {
                  if(
NormalizeDouble(OrderStopLoss(),Digits)!=NormalizeDouble(Ask - (TrailingStopPips*Point),Digits))
                  
moveSL(OrderTicket(),NormalizeDouble(Ask - (TrailingStopPips*Point),Digits));  
               } 
            }
            else if(
OrderType() == OP_SELL)
            {
               if(
OrderStopLoss() >  Bid + (TrailingStopPips*Point) && Bid < (OrderOpenPrice()-TrailingStopTrigger*Point))
               {
                  if(
NormalizeDouble(OrderStopLoss(),Digits)!=NormalizeDouble(Bid TrailingStopPips*Point,Digits))
                  
moveSL(OrderTicket(),NormalizeDouble(Bid TrailingStopPips*Point,Digits));
               }     
            }
         }
                    
      }
   }      
   
   
   
//OPEN Order
   
if( orders )
   {  
      if(
getSignal(OP_BUY)) 
      {
         if(
TakeProfit>0tp =  Ask TakeProfit Point;
         
         if(
StopLoss>0sl Ask StopLoss*Point;
         
         
openOrder(BaseLot,OP_BUYsl,tp,"START");
      }
      
      if(
getSignal(OP_SELL)) 
      {
         if(
TakeProfit>0tp =  Bid TakeProfit Point;
         
         if(
StopLoss>0sl Bid StopLoss Point;
         
         
openOrder(BaseLot,OP_SELLsl,tp,"START");
      }            
   }      
    
//----
   
   
return(0);
  }
//+------------------------------------------------------------------+
bool getSignal(int mode)
{
   
double SMAredSMAblueSMAred_1SMAblue_1;

   
SMAred    iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,0);
   
SMAblue   iMA(NULL,0,35,0,MODE_SMA,PRICE_CLOSE,0);
   
SMAred_1  iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,1);
   
SMAblue_1 iMA(NULL,0,35,0,MODE_SMA,PRICE_CLOSE,1);

   if(
mode == OP_BUY)
   {
      if( 
SMAred_1 SMAblue_1 && SMAred SMAblue ) { return(true); }
   }
   else if(
mode == OP_SELL)
   {      
      if( 
SMAred_1 SMAblue_1 && SMAred SMAblue ) { return(true); }
   }
    
return(
false); 
}
//----
bool moveSL(int ticket,double stoploss)
{
   
   if(!
IsTradeAllowed())
   return (
false);
   
   if(
MathAbs(Ask-stoploss)/Point MarketInfo(Symbol(),MODE_STOPLEVEL)) 
   {
      Print(
"STOP LOSS too close ",Bid," SL ",stoploss);
      return(
false);
   }
   
   
int error;
   
   
int MAXRETRIES 5;
   
int retries 0;
   while(!
OrderModify(ticket,OrderOpenPrice(), stoplossOrderTakeProfit(), 0,CLR_NONE))
   {
      
error GetLastError();
      
      if(
error>1)   
      Print(
"MoveSL failed with error #",ErrorDescription(error)," CurrentSL ",OrderStopLoss()," NewSL ",stoploss);
       
      
Sleep(1000);
            
      
RefreshRates();
            
      if(
retries >= MAXRETRIES
      return(
false);
      else
      
retries++;
   }
return(
0);

//----
int orderCount(int type)
{
    
int total OrdersTotal();
    
int oc 0;
    for(
int cnt ;cnt<=total;cnt++)
    {
      
OrderSelect(cntSELECT_BY_POSMODE_TRADES);

      if(
OrderMagicNumber() == Magic && (OrderType() == type || type == -1)) 
      
oc+=1;
    } 
    return(
oc);
}
//----
bool openOrder(double LTS,int typedouble sl,double tpstring description "" )
{
   if(!
IsTradeAllowed())
    {
        return (-
1);
    }
   
    
int error 0;
    
int ticket 0;
  
   
       
    if( 
type == OP_SELL )
    {
        while(
true)
        {
           
RefreshRates();
            
             
ticket OrderSend(Symbol(),OP_SELL,LTS,MarketInfo(Symbol(),MODE_BID),0,0,0,StringConcatenate(Version," ",description),Magic,0,Pink);
         
            if(
ticket<=0)
            {
                
error=GetLastError();
            Print(
"SELL ORDER ERROR:"ErrorDescription(error));
            
            if(!
ErrorBlock(error,LTS)) break;
            
            }
            else
            {
               if(
sl>|| tp>0)
               {
                  
OrderSelect(ticket,SELECT_BY_TICKET);
               
OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Green);
            }
                
OrderPrint(); 
               break;
            }
        }     
   }
   else if( 
type == OP_BUY )
   {
        
        while(
true)
        {
           
RefreshRates();
           
            
ticket OrderSend(Symbol(),OP_BUY,LTS,MarketInfo(Symbol(),MODE_ASK),0,0,0,StringConcatenate(Version," ",description),Magic,0,Lime);
         
            if(
ticket<=0)
            {
                
error=GetLastError();
            Print(
"BUY ORDER ERROR:"ErrorDescription(error));
            
            if(!
ErrorBlock(error,LTS)) break;
            
            }
            else
            {
               if(
sl>|| tp>0)
               {
                  
OrderSelect(ticket,SELECT_BY_TICKET);
               
OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Green);
               }
               
OrderPrint(); 
               break;
            }
            
        }
   }
    
   return (
0);
}
//+------------------------------------------------------------------+
bool ErrorBlock(int error 0,double lot 0)
{
   
   switch(
error)
   {
       case 
0
       {
         
//no error - exit from loop
         
Print("NO ERROR");
         return(
false);
       }
       case 
2:
       {
           Print(
"System failure. Reboot the computer/check the server");
           return(
false);  
       }
       case 
3:
       {
           Print(
"Error of the logic of the EA");
           return(
false);  
       }
       case 
4:
       {
           Print(
"Trading server is busy. Wait for 2 minutes.");
           
Sleep(120000);
           return(
true);   
       }
       case 
6:
       { 
           
bool connect false;
           
int iteration 0;
           Print(
"Disconnect ");
           while((!
connect) || (iteration 60))
           {
               
Sleep(10000);
               Print(
"Connection not restored"iteration*10,"  seconds passed");
               
connect IsConnected();
               if(
connect)
               {
                   Print(
"Connection restored");
               }
               
iteration++;
           }
           Print(
"Connection problems");
           return(
false);  
       }
       case 
8:
       {
           Print(
"Frequent requests");
           return(
false);  
       }
       case 
64:
       {
           Print(
"Account is blocked!");
           return(
false);  
       }
       case 
65:
       {
           Print(
"Wrong account number???");
           return(
false);  
       }
       case 
128:
       {
//????
           
Print("Waiting of transaction timed out");
           
Sleep(10000);//10 seconds
           
RefreshRates();
           return(
false);  
       }
       case 
129:
       {
           Print(
"Wrong price");
           
RefreshRates();
           return(
false);  
       }
       case 
130:
       {
           Print(
"Wrong stop SLEVEL"+MarketInfo(Symbol(),MODE_STOPLEVEL)+" FZLVL "+MarketInfo(Symbol(),MODE_FREEZELEVEL)+" FZLVL "+MarketInfo(Symbol(),MODE_SPREAD));
           
RefreshRates();
           return(
false);   
       }
       case 
131:
       {
           Print(
"Wrong calculation of trade volume");
           return(
false);  
       }
       case 
132:
       {
           Print(
"Market closed");
           return(
false);  
       }
       case 
134:
       {
//NOT ENOUGH CASH?
           
Print("Lack of margin for performing operation, margin: "+AccountFreeMargin());
           
           return(
false);  
       }
       case 
135:
         {
           Print(
"Prices changed");
           
RefreshRates();
           return(
true);  
         }
       case 
136:
         {
           Print(
"No price!");
           return(
false);  
         }
       case 
138:
         {
           Print(
"Requote again!");
           
RefreshRates();
           return(
true);  
         }
       case 
139:
         {
           Print(
"The order is in process. Program glitch");
           
Sleep(10000);//10 seconds
           
return(true);  
         }
       case 
141:
         {
           Print(
"Too many requests");
           
Sleep(10000);//10 seconds 
           
return(true);  
         }
       case 
148:
         {
           Print(
"Transaction volume too large");
           return(
false);  
         }                                          
         default:
         {  
            Print(
"Unhandeled exception code:",error," stoplevel ",MarketInfoSymbol(), MODE_STOPLEVEL) ," spread ",MarketInfoSymbol(), MODE_SPREAD)+" LOTS:"lot);
            return(
false);
         }
     }
}
//----- 
__________________

Easy Trading Assistant

Geändert von Master (26.01.16 um 16:52 Uhr) Grund: Link geändert