Einzelnen Beitrag anzeigen
  #2 (permalink)  
Alt 06.08.11
sunnyboy20 sunnyboy20 ist offline
Neues Mitglied
 
Registriert seit: Mar 2011
Beiträge: 27
sunnyboy20 befindet sich auf einem aufstrebenden Ast
Question ..........

so ich bin nun schon ein stück weiter durch googlen ;-) aber es funktioniert trotzdem nicht... hier nochmal der code vielleicht findet sich jemand der mir hilft

erhalte jetzt halt diese Fehlermeldung
Code:
17:17:07 2011.01.11 00:00  bastiEA GBPUSD,M15: CheckTrailingStop() - OrderSelect returned the error of 0
Code:
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Sebastian Meissner"


extern string  Expert_Name    = "Trading Basti";
extern double iLots=0.1;
extern double iMaximumRisk= 0.02;
extern int iTakeProfit=50;
extern int iStopLoss=650;
extern int TrailingStop = 35;
extern int iMaxTrades=1;
extern int iMagicNumber=336699;

double stochg,stochr;

int iTotalTrades;
int iOrderOpenStatus;
int iErrorNumber;
int currentOrderTicket;

string strErrorMessage;

double LotsOptimized()
  {
  double lot=iLots;
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*iMaximumRisk/1000.0,1);
//---- return lot size
   if(lot<0.1) lot=0.1;
   if(lot>50.0) lot=50.0;
   return(lot);
  }

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
void CheckTrailingStop(int order_Ticket, int trailingStopValue)
{
   double oldStopLoss;
   double newStopLoss;
   double nextStopLoss;
   int _trailingStop = trailingStopValue;
   
   if (order_Ticket < 0) return;
                                    
   if(OrderSelect(order_Ticket,SELECT_BY_TICKET,MODE_TRADES) == false)
   {
      Print("CheckTrailingStop() - OrderSelect returned the error of ", GetLastError());
      return;   
   }
         
   if (OrderType() == OP_BUY)
   {      
      if(Bid-OrderOpenPrice() > Point*_trailingStop)
      {       
         oldStopLoss = OrderStopLoss();
         newStopLoss = Bid-Point*_trailingStop;
         nextStopLoss = oldStopLoss + Point; // Adding 1 point to oldStopLoss, i.e. 76.78 to 76.79 to fix mq4 compare doubles bug         
                    
         if(newStopLoss >= nextStopLoss || OrderStopLoss() == 0)
         {                              
            OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,0,0,Green);
            return;
         }
      }
   }
                                             
   if (OrderType() == OP_SELL)
   {               
      if(OrderOpenPrice()-Ask > Point*_trailingStop)
      {
         oldStopLoss = OrderStopLoss();
         newStopLoss = Ask+Point*_trailingStop;
         nextStopLoss = oldStopLoss - Point; // Subtracting 1 point to oldStopLoss, i.e. 76.78 to 76.77 to fix mq4 compare doubles bug
                    
         if(newStopLoss <= nextStopLoss || OrderStopLoss() == 0)
         {                              
            OrderModify(OrderTicket(),OrderOpenPrice(),newStopLoss,0,0,Green);
            return;
         }
      }
   }

   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }

//+------------------------------------------------------------------+
//| The functions from this point to the start function are where    |
//| changes are made to test other systems or strategies.            |
//|+-----------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void start()
{ 

   if (TrailingStop > 0) CheckTrailingStop(currentOrderTicket, TrailingStop);


  stochg = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_MAIN,0);
  stochr = iCustom (NULL,0,"Stochastic",8,3,3,MODE_SMA,0,MODE_SIGNAL,0);
  double willd       = 81;
  double willu       = 19;
  double will1       = 80;
  double will2       = 20;
//Buy-Logik
  
  
//Sell-Logik

   
// Buy-Order ausführen

iTotalTrades=OrdersTotal();

if (( stochg > will2) && (stochg > stochr) && (stochr < will2) && (stochr > willu) && (iTotalTrades < iMaxTrades))

{ 
double dBuyStopLoss=Ask-(iStopLoss*Point);
double dBuyTakeProfit=Ask+(iTakeProfit*Point);

iOrderOpenStatus=OrderSend (Symbol(), OP_BUY,LotsOptimized(), Ask, dBuyStopLoss, dBuyTakeProfit, "Trading Basti",iMagicNumber,0,Green);
   if (iOrderOpenStatus<0)
      {
      iErrorNumber=GetLastError();
      Print ("Order fehlgeschlagen!: ", iErrorNumber);
      return;
      }
}
      
// Sell-Order ausführen

iTotalTrades=OrdersTotal();

if (( stochg < will1) && (stochg < stochr) && (stochr > will1) && (stochr < willd) && (iTotalTrades < iMaxTrades))

   {
   double dSellStopLoss=Bid+(iStopLoss*Point);
   double dSellTakeProfit=Bid-(iTakeProfit*Point);
 
   
iOrderOpenStatus=OrderSend (Symbol(), OP_SELL,LotsOptimized(), Bid, dSellStopLoss, dSellTakeProfit, "Trading Basti",iMagicNumber,0,Red);
   if (iOrderOpenStatus<0)
      {
      iErrorNumber=GetLastError();
      Print ("Order fehlgeschlagen!: ", iErrorNumber);
      return;
      }
}
   return(0);
  }
//----