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)
-   -   Probleme mit dem EAs auf dem VPS (http://www.expert-advisor.com/forum/showthread.php?t=4696)

Raul0 19.01.16 00:56

Probleme mit dem EAs auf dem VPS
 
Hallo,

ich muss das mal ansprechen. Mir hat es eine manuelle Order bearbeitet von einem EA aus.

Der EA hat folgenden Orderverwaltungscode:

PHP-Code:

   int Magic 12345678;

   
int total OrdersTotal();
   for( 
int pos pos totalpos++ )
   {
      if( 
OrderSelect(posSELECT_BY_POSMODE_TRADES) )
      if( 
OrderMagicNumber() == Magic 
      {

         
//TRAILING
         
if( TrailingStopTrigger )
         {
            ... 
Code ...
         }

      }
   } 

Theoretisch sollte sowas nicht passieren Aufgrund der Magic.

Zudem merke ich auf dem VPS einige Probleme er EAs untereinander, was nicht mit dem EAs zu tun hat, sondern ein Fehler am MT4.

Ziehe ich z.B. EA_EURTest.ex4 auf einen Chart, dann habe ich den Copyright, Text und die Eingaben von einem anderen EA drin stehen.

Macht keinen Sinn, ist aber so.

Bei jemand ähnlich?

Hosch 19.01.16 09:20

Zitat:

Zitat von Raul0 (Beitrag 32618)
Hallo,

ich muss das mal ansprechen. Mir hat es eine manuelle Order bearbeitet von einem EA aus.

Der EA hat folgenden Orderverwaltungscode:

PHP-Code:

   int Magic 12345678;

   
int total OrdersTotal();
   for( 
int pos pos totalpos++ )
   {
      if( 
OrderSelect(posSELECT_BY_POSMODE_TRADES) )
       if( 
OrderMagicNumber() == Magic 
       {

         
//TRAILING
         
if( TrailingStopTrigger )
         {
            ... 
Code ...
         }

      }
   } 

Theoretisch sollte sowas nicht passieren Aufgrund der Magic.

Zudem merke ich auf dem VPS einige Probleme er EAs untereinander, was nicht mit dem EAs zu tun hat, sondern ein Fehler am MT4.

Ziehe ich z.B. EA_EURTest.ex4 auf einen Chart, dann habe ich den Copyright, Text und die Eingaben von einem anderen EA drin stehen.

Macht keinen Sinn, ist aber so.

Bei jemand ähnlich?



Ich würde das wie folgt machen:
PHP-Code:

   int total OrdersTotal();
   for( 
int pos pos totalpos++ )
   {
      
OrderSelect(posSELECT_BY_POSMODE_TRADES); // if kann weggelassen werden, da Zugriff auf Index des Order Pools
// Zusätzlich Prüf noch nach Symbol bzw. Long oder Short Posi 
      
if(OrderSymbol()==Symbol())
      {
        if( 
OrderMagicNumber() == Magic 
        {

           
//TRAILING
          
if( TrailingStopTrigger )
          {
            ... 
Code ...
          }
        }
      }
   } 

Das mit den Fehlern von EAs untereinander klingt komisch, habe ich noch nie gesehen, ausser die EAs können nicht untereinander da keine Magic-Nr verwendet wird bzw. die gleiche ?

Carpe Diem,
Hosch

Raul0 19.01.16 13:23

Ich erhalte ohne dem if einen Fehler beim kompilieren. Von daher hatte ich überall die Anweisungen auf den aktuellen Stand gebracht.
Auch in der mql4 Dokumentation ist es mit if.
Das Beispiel dazu: if(OrderSelect(12470, SELECT_BY_TICKET)==true)

Bitte, was meinst Du mit Zugriff auf den Order-Pool, wenn if davorsteht?

Hosch 19.01.16 13:41

Zitat:

Zitat von Raul0 (Beitrag 32623)
Ich erhalte ohne dem if einen Fehler beim kompilieren. Von daher hatte ich überall die Anweisungen auf den aktuellen Stand gebracht.
Auch in der mql4 Dokumentation ist es mit if.
Das Beispiel dazu: if(OrderSelect(12470, SELECT_BY_TICKET)==true)

Bitte, was meinst Du mit Zugriff auf den Order-Pool, wenn if davorsteht?

Moin,


bei dem Beispiel in mql4 Doku wird nur die Ticket-Nr. geprüft und dann ist das mit if-Richtig. Bei deiner Schleife gehst du ein Pool an offenen Posis durch.
SELECT_BY_POS - index in the order pool,
SELECT_BY_TICKET - index is order ticket.

pool=MODE_TRADES


Das ist ein Beispiel bei mir und da kommt kein Komp-Fehler:
PHP-Code:

double getOpenBuyTrade()
  {
   
int total=OrdersTotal();
   for(
int i=0;i<total;i++)
     {
      
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(
OrderType()==OP_BUY && OrderSymbol()==Symbol())
        {
         if(
OrderMagicNumber()==MagicNr)
            return(
OrderOpenPrice());

        }
     }
   return(
0);
  } 


Raul0 19.01.16 19:01

Danke erstemal für das Gespräch.

Ich habe den Code von Dir probiert und erhalte die folgende Warnung:

return value of 'OrderSelect' should be checked Test.mq4


Was ist hier richtig, damit es ohne Warnung erscheint?

Mit der if habe ich eine Möglichkeit und die Zweite ist:

bool OrdSel = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

Da OrderSelect eine Bool Funktion ist, setze ich eine bool Variable davor.


PHP-Code:

double getOpenBuyTrade()
  {
   
int total=OrdersTotal();
   for(
int i=0;i<total;i++)
     {
      
bool OrdSel OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(
OrderType()==OP_BUY && OrderSymbol()==Symbol())
        {
         if(
OrderMagicNumber()==MagicNr)
            return(
OrderOpenPrice());

        }
     }
   return(
0);
  } 


Nachtrag:
Da die OrderSelect Funktion eine bool Funktion ist, gibt sie true bei erfolgreicher Funktionsausführung zurück, oder false bei verfehlter Funktionsausführung.
D.h. damit sollte der Code mit der if-Anweisung Sinn machen. Da dieser bei erfolgter true Meldung gleich weiter im Codeablauf geht, oder unterbricht.
Durchführung und Bestätigung sind hier in einer Zeile.

Hosch 19.01.16 20:08

Zitat:

Zitat von Raul0 (Beitrag 32635)
Danke erstemal für das Gespräch.

Ich habe den Code von Dir probiert und erhalte die folgende Warnung:

return value of 'OrderSelect' should be checked Test.mq4


Was ist hier richtig, damit es ohne Warnung erscheint?

Mit der if habe ich eine Möglichkeit und die Zweite ist:

bool OrdSel = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

Da OrderSelect eine Bool Funktion ist, setze ich eine bool Variable davor.


PHP-Code:

double getOpenBuyTrade()
  {
   
int total=OrdersTotal();
   for(
int i=0;i<total;i++)
     {
      
bool OrdSel OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(
OrderType()==OP_BUY && OrderSymbol()==Symbol())
        {
         if(
OrderMagicNumber()==MagicNr)
            return(
OrderOpenPrice());

        }
     }
   return(
0);
  } 


Nachtrag:
Da die OrderSelect Funktion eine bool Funktion ist, gibt sie true bei erfolgreicher Funktionsausführung zurück, oder false bei verfehlter Funktionsausführung.
D.h. damit sollte der Code mit der if-Anweisung Sinn machen. Da dieser bei erfolgter true Meldung gleich weiter im Codeablauf geht, oder unterbricht.
Durchführung und Bestätigung sind hier in einer Zeile.

Sali,

das ist richtig, was du schreibst und auch richtig, dass der Compiler einer Warnung wirft. Du kannst das abprüfen. Wichtig ist, dass das funktioniert wenn du das so wie unten dargestellt abprüfst.

PHP-Code:

double getOpenBuyTrade()
  {
   
int total=OrdersTotal();
   for(
int i=0;i<total;i++)
     {
      
bool OrdSel OrderSelect(i,SELECT_BY_POS,MODE_TRADES)
// oder
    
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
      if(
OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrdSel)
        {
         if(
OrderMagicNumber()==MagicNr)
            return(
OrderOpenPrice());

        }
 }

     }
   return(
0);
  } 


Raul0 23.01.16 07:03

Guten Morgen,

ich muss das Thema noch einmal aufgreifen.

Ein EA mit dem Namen EA_EURUSD.ex4 wird auf den EURUSD mit zwei Perioden gezogen. Periode H1 und H4.

Die Magicnummer ist unterschiedlich und mit GlobalVariableGet("xyz") arbeite ich nicht. Auch nicht über den Orderkommentar.
Es sind nur normale im EA befindliche Variablen. Er arbeitet mit zwei iMA.

H1 hat kein TakeProfit und H4 hat TakeProfit, trotzdem wirft es zu H1 ein TakeProfit. Oder es wird durcheinander gehandelt.

Die initialisierten Variablen sollten doch innerhalb eines Chartfensters bleiben.

Das Phänomen ist weg, wenn der MT4 neu gestartet wurde.

Im Alleingang nur mit einer Periode läuft der EA.

Was kann so einen Fehler bewirken? Wäre es sinnvoll dem EA jeweils einen anderen Dateinamen zu geben?

Gruss, Raul

Raul0 26.01.16 11:56

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);
         }
     }
}
//----- 


Hosch 26.01.16 14:06

Moin,

teste das mal. Ich habe mir nicht alle Code-Stellen angeschaut.
Carpe Diem,
Hosch

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;
double Points 1;
//+------------------------------------------------------------------+
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;
     if(
Digits==|| Digits==2Points=Point;
   else if(
Digits==|| Digits==3Points=10*Point;
//----
   
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;
         if(
OrderSymbol()!=Symbol()) continue;

        if(
OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {  
         
//TRAILING
         
Print("Das Symbol ist:",Symbol());
         Print(
"Die Ticket N ist:",OrderTicket());
         if(
TrailingStopTrigger 0)
         {
            if(
OrderType() == OP_BUY)
            {            
               if(
OrderStopLoss() <   Ask - (TrailingStopPips*Points)&& Ask > (OrderOpenPrice()+TrailingStopTrigger*Points))
               {
                  if(
NormalizePrice(OrderStopLoss())!=NormalizePrice(Ask - (TrailingStopPips*Points)))
                  
moveSL(OrderTicket(),NormalizePrice(Ask - (TrailingStopPips*Points)));  
               } 
            }
            else if(
OrderType() == OP_SELL)
            {
               if(
OrderStopLoss() >  Bid + (TrailingStopPips*Points) && Bid < (OrderOpenPrice()-TrailingStopTrigger*Points))
               {
                  if(
NormalizePrice(OrderStopLoss())!=NormalizePrice(Bid TrailingStopPips*Points))
                  
moveSL(OrderTicket(),NormalizePrice(Bid TrailingStopPips*Points));
               }     
            }
         }
                    
      }
     }
   }      
   
   
   
//OPEN Order
   
if( orders )
   {  
      if(
getSignal(OP_BUY)) 
      {
         if(
TakeProfit>0tp =  Ask TakeProfit Points;
         
         if(
StopLoss>0sl Ask StopLoss*Points;
         
         
openOrder(BaseLot,OP_BUYsl,tp,"START");
      }
      
      if(
getSignal(OP_SELL)) 
      {
         if(
TakeProfit>0tp =  Bid TakeProfit Points;
         
         if(
StopLoss>0sl Bid StopLoss Points;
         
         
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)/Points 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)
               {
                 if( 
ticket 0)
               
OrderModify(ticket,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)
               {
                 if(
ticket 0)
               
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);
         }
     }
}
//-----


double NormalizePrice(double price,bool round=true)
{
     
double tickSize MarketInfo(Symbol(), MODE_TICKSIZE);
  
   
int fullCount price tickSize;           
   
double result fullCount tickSize;       
  
   if (
round)
   {
      
double mod price result;              
      
      if (
mod >= tickSize 2.0)                
         
result result tickSize;            
   }
  
   return(
result);



Raul0 26.01.16 14:49

Hallo Hosch,

ich habe jetzt eine Versuchsreihe auf dem Server gestartet und werde eine Rückmeldung geben.
In der Zwischenzeit gibt es ein Like :-)


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