Thema: erster EA
Einzelnen Beitrag anzeigen
  #5 (permalink)  
Alt 10.04.13
Racki Racki ist offline
Mitglied
 
Registriert seit: Apr 2011
Ort: Osnabrück
Beiträge: 103
Racki befindet sich auf einem aufstrebenden Ast
Standard

Ich habe deinen Code entsprechend angepasst und so ein paar Kleinigkeiten eingesetzt.
Z.B. die Prints durch Comment ersetzt, damit mir die Logs nicht vollgeschrieben werden^^

PHP-Code:
#property link      ""
#define  MAGIC    08042010
double   startkurs 0.0;
extern double   diff 1.2;
double   buystop;
double   sellstop;
bool     CheckedToday FALSE;
extern double LOT 0.1;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()   

  {
//----
            
startkurs Bid
            
buystop startkurs + (diff*ThisPip()) ;
            
sellstop startkurs - (diff*ThisPip()) ;

         
//+------------------------------------------------------------------+
         //| Horizontale Linie zeichnen                                       |
         //+------------------------------------------------------------------+
         
            
ObjectCreate("startkurs"OBJ_HLINE,0,Time[0],startkurs);
            
ObjectSet("startkurs"OBJPROP_COLORYellow);      

         
//+------------------------------------------------------------------+
         //| Pending Orders absetzen                                          |
         //+------------------------------------------------------------------+

           
{
           
OrderSend(Symbol(), OP_SELLSTOPLOT, (sellstop), 00.00.0"SellStop Order"MAGIC);
           
OrderSend(Symbol(), OP_BUYSTOPLOT, (buystop), 00.00.0"SellStop Order"MAGIC);
          
             {
             Print(
"OrderSend failed with error #",GetLastError());
             return(
0);
             }
           }            
           
//----
   
return;
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int Tick;
int start()
   {  
   
string ThisComment "Ticknummer: " Tick "\nLetztes Hoch = " High[0];
   
ThisComment ThisComment "\nLetztes Tief = " Low[0] + "\nStartpreis = " startkurs;
   
ThisComment ThisComment "\nBUYSTOP ist = " buystop "\nSELLSTOP ist = " sellstop;

   
         
Tick++;
         
Comment(ThisComment);
         
         
//+------------------------------------------------------------------+
         //| Prüfe ob eine Pending Order ausgefürt wurde                      |
         //+------------------------------------------------------------------+


          //----     
            
if (CountLong(Symbol(),MAGIC)+CountShort(Symbol(),MAGIC) > 0ClosePending(Symbol(),MAGIC);   
          
//----   
         
return(0);    
   }   


//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
   
int deinit()
  {
   
//----
   
   //----
   
return(0);
  }
//+------------------------------------------------------------------+
//| MSP bestimmen                                                    |
//+------------------------------------------------------------------+
double ThisPip() 
   {
   
//----
      
double returnPoint 0.000001;
      
int ThisDigits MarketInfo(Symbol(), MODE_DIGITS);
         if (
ThisDigits == || ThisDigits == 3returnPoint 0.01;
         if (
ThisDigits == || ThisDigits == 5returnPoint 0.0001;
      return(
returnPoint);
   
//----
   
}
//+------------------------------------------------------------------+
//| Anzahl der Longpositionen                                        |
//+------------------------------------------------------------------+
void ClosePending(string ThisSymbol="EURUSD",int ThisMagigNumber=123)
{
   
int ThisOrdersTotal OrdersTotal();
   for (
int ThisCounter 0ThisCounter ThisOrdersTotalThisCounter++)
   {
      
OrderSelect(ThisCounter,SELECT_BY_POS,MODE_TRADES);
      if (
OrderMagicNumber() == ThisMagigNumber && OrderSymbol() == ThisSymbol && (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP) )
      {
         
OrderDelete(OrderTicket());
      }
   }
}

int CountLong(string countLongSymbolint countLongMagic)
{
   
int CountLongReturn 0;
   
int ThisOrdersTotal OrdersTotal();
   if (
ThisOrdersTotal )
   {
       for(
int counterCountLong 0counterCountLong ThisOrdersTotalcounterCountLong++)
       {
           
OrderSelect(counterCountLongSELECT_BY_POSMODE_TRADES);
           if(
OrderSymbol() == countLongSymbol && OrderMagicNumber() == countLongMagic)
           {
              if(
OrderType() == OP_BUY)
                 {
                    
CountLongReturn++;
                 }
           }
       }
   }
   return (
CountLongReturn);
}
//+------------------------------------------------------------------+
//| Anzahl der Shortpositionen                                       |
//+------------------------------------------------------------------+
int CountShort(string countShortSymbolint countShortMagic)
{
   
int CountShortReturn 0;
   
int ThisOrdersTotal OrdersTotal();
   if (
ThisOrdersTotal )
   {
       for(
int counterCountShort 0counterCountShort ThisOrdersTotalcounterCountShort++)
       {
           
OrderSelect(counterCountShortSELECT_BY_POSMODE_TRADES);
           if(
OrderSymbol() == countShortSymbol && OrderMagicNumber() == countShortMagic)
           {
              if(
OrderType() == OP_SELL)
                 {
                    
CountShortReturn++;
                 }
           }
       }
   }
   return (
CountShortReturn);