Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools
Zurück   Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools > Metatrader 4 > Programmierung MQL4

Programmierung MQL4 Hier gehts rund ums Programmieren in MQL4.

Login
Benutzername:
Kennwort:


Statistik
Themen: 4973
Beiträge: 43267
Benutzer: 7.220
Aktive Benutzer: 82
Links: 84
Wir begrüßen unseren neuesten Benutzer: JosephTK
Mit 2.475 Benutzern waren die meisten Benutzer gleichzeitig online (16.01.20 um 22:38).
Neue Benutzer:
vor 2 Stunden
- JosephTK
vor 2 Tagen
- Hopfen&Mal...
vor 2 Tagen
- frankmicha...
vor einer Woche
- DFeck
vor einer Woche
- bb1107

Onlineuser
'Wer ist online' anzeigen Benutzer: 0
Gäste: 318
Gesamt: 318
Team: 0
Team:  
Benutzer:  
Freunde anzeigen

Empfehlungen

Thema geschlossen
 
Themen-Optionen Thema durchsuchen Ansicht
  #1 (permalink)  
Alt 06.08.11
Neues Mitglied
 
Registriert seit: Mar 2011
Beiträge: 27
sunnyboy20 befindet sich auf einem aufstrebenden Ast
Question Brauche hilfe bei TrailingStop und BreakEven

Hallo,

ich habe hier meinen ersten EA programmiert und komme aber nun nicht weiter
ich wollte in meinen EA einen TrailingStop einfügen und einen BreakEven aber weiß nicht wo habe schon mehrere Varianten probiert aber keine will funktionieren.

Ich bin auch noch absoluter Noob auf dem Gebiet und habe das "programmieren" ;-) mit hilfe einer LernDVD "gelernt" eher mit Schrittanweisung nach programmiert und das so das es für mich übersichtlich ist und nachvollziehbar, halt so das man jederzeit die Strategie und Indikatoren jederzeit ändern kann.

Nun gut hier ist mein EA und ich brauch wie gesagt hilfe ;-)

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 iStopLoss=650;
extern int iTakeProfit=50;
extern int iMaxTrades=1;
extern int iMagicNumber=336699;

double stochg,stochr;

int iTotalTrades;
int iOrderOpenStatus;
int iErrorNumber;

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                                   |
//+------------------------------------------------------------------+
int init()
  {
   

   
//----
   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                                            |
//+------------------------------------------------------------------+
int start()
  {

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

   
// Buy-Order ausführen

iTotalTrades=OrdersTotal();

if (( stochg > will2) && (stochg > stochr) && (stochr < will2) && (stochr > willu) && (iTotalTrades < iMaxTrades)) //// dont touch this

{ 
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)) ///// dont touch

   {
   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);
  }
//----
Angehängte Dateien
Dateityp: mq4 bastiEA.mq4 (3,2 KB, 2x aufgerufen)
  #2 (permalink)  
Alt 06.08.11
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);
  }
//----
  #3 (permalink)  
Alt 06.08.11
Neues Mitglied
 
Registriert seit: Mar 2011
Beiträge: 27
sunnyboy20 befindet sich auf einem aufstrebenden Ast
Standard

kann mir bitte jemand helfen, würde natürlich auch was dafür springen lassen das hätte ich vielleicht schon vorher daz schreiben sollen ;-)
  #4 (permalink)  
Alt 08.08.11
Mitglied
 
Registriert seit: Jun 2011
Ort: Minsk, Weißrussland
Beiträge: 87
Bobs befindet sich auf einem aufstrebenden Ast
Standard Hilfe

Hallo Sunnyboy20,
Ich habe den Beispielcode in Private Nachrichten geschickt.
  #5 (permalink)  
Alt 09.08.11
Neues Mitglied
 
Registriert seit: Mar 2011
Beiträge: 27
sunnyboy20 befindet sich auf einem aufstrebenden Ast
Standard

danke ich schau mir es gleich mal an
Thema geschlossen

Lesezeichen

Stichworte
breakeven, trailingstop

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are aus
Pingbacks are aus
Refbacks are aus




Alle Zeitangaben in WEZ +1. Es ist jetzt 00:01 Uhr.





Suchmaschine - Reisen - Wavesnode - Facebook Forum - Spam Firewall
-----------------------------------------------------------------------------------------------------------------------------
Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
SEO by vBSEO 3.6.1
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum
MetaTrader bzw. MetaTrader 4 und MetaTrader 5 sind eingetragene Marken der MetaQuotes Software Corp.
-----------------------------------------------------------------------------------------------------------------------------