![]() |
|
|||||||
| Startseite | Registrieren | Hilfe | Benutzerliste | Kalender | Suchen | Heutige Beiträge | Alle Foren als gelesen markieren |
| Programmierung MQL4 Hier gehts rund ums Programmieren in MQL4. |
![]() |
|
|
Themen-Optionen | Thema durchsuchen | Ansicht |
|
|||
|
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);
}
//----
|
|
|||
|
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);
}
//----
|
|
|||
|
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 ;-)
|
|
|||
|
Hallo Sunnyboy20,
Ich habe den Beispielcode in Private Nachrichten geschickt. |
![]() |
| Lesezeichen |
| Stichworte |
| breakeven, trailingstop |
| Themen-Optionen | Thema durchsuchen |
| Ansicht | |
|
|