![]() |
|
|||||||
| 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 Zusammen,
Ich bräuchte mal wieder Hilfe von einem Profi bitte. Gerne will ich die Positionsgröße, abhängig vom Kontostand anpassen lassen. Leider bekomme ich folgende Fehlermeldung: 'LotsOptimized' - function call missing, open parenthesis expected Anbei der Code Code:
#property strict
input int SLPoints = 500;
input int TPPoints = 500;
input int TSLPoints = 500;
input double Lots = 0.1;
input double MaximumRisk =0.02;
input ENUM_TIMEFRAMES Timeframe = PERIOD_H1;
input int PeriodsMAFast = 50;
input int PeriodsMASlow = 200;
input ENUM_MA_METHOD MethodMAFast = MODE_SMA;
input ENUM_MA_METHOD MethodMASlow = MODE_SMA;
input ENUM_TIMEFRAMES TimeframeCCI = PERIOD_H1;
input string Commentary = "Dies ist ein Kommentar";
input int Magic = 111;
//globale Variable
datetime timestamp;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
trailingStop();
if(timestamp == iTime(Symbol(),Timeframe,0)) return;
timestamp = iTime(Symbol(),Timeframe,0);
double maFast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,0);
double maSlow = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,0);
double maFastLast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,1);
double maSlowLast = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,1);
double CCI = iCCI(NULL,TimeframeCCI,14,PRICE_CLOSE,1);
int total = OrdersTotal();
if (total <50)
if(maFast > maSlow && maFastLast < maSlowLast &&CCI >=100){
Print("Long");
int ticket = executeLong();
Print(IntegerToString(ticket));
}else if(maFast < maSlow && maFastLast > maSlowLast && CCI <=-100){
Print("Short");
int ticket = executeShort();
Print(IntegerToString(ticket));
}
}
double LotsOptimized()
{
double lot=Lots;
//--- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
if(lot<0.1) lot=0.1;
return(lot);
}
int executeLong (){
double entry = Ask;
entry = NormalizeDouble(entry,Digits);
double sl = entry - SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry + TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_BUY,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);{
}
return ticket;
}
int executeShort (){
double entry = Bid;
entry = NormalizeDouble(entry,Digits);
double sl = entry + SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry - TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_SELL,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);
return ticket;
}
void trailingStop(){
for(int i = 0; i < OrdersTotal(); i++){
if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic){
if(OrderType() == OP_BUY){
double sl = Bid - TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl > OrderStopLoss()){
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());
}
}
if(OrderType() == OP_SELL){
double sl = Ask + TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl < OrderStopLoss() || OrderStopLoss() == 0){
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());
}
}
}
}
}
Vielen Dank
|
|
|||
|
Ok, aber dann solltest Du erst einmal einen Code schreiben mit klaren Strukturen. Bei den {} Setzungen sieht doch keiner durch!
traderdoc
__________________
Ich erfülle Euch gern Eure EA-, Indikator- und Script-Programmierungswünsche auf Honorarbasis. |
|
|||
|
Fehlt in der Zeile mit
if (total <50) eine geöffnete geschweifte Klammer? |
|
|||
|
Zitat:
Sorry.. hier nochmal der gleiche Code, mit einer Klammersetzung die übersichtlicher ist. Code:
#property strict
input int SLPoints = 500;
input int TPPoints = 500;
input int TSLPoints = 500;
input double Lots = 0.1;
input double MaximumRisk =0.02;
input ENUM_TIMEFRAMES Timeframe = PERIOD_H1;
input int PeriodsMAFast = 50;
input int PeriodsMASlow = 200;
input ENUM_MA_METHOD MethodMAFast = MODE_SMA;
input ENUM_MA_METHOD MethodMASlow = MODE_SMA;
input ENUM_TIMEFRAMES TimeframeCCI = PERIOD_H1;
input string Commentary = "jhjgh";
input int Magic = 111;
//globale Variable
datetime timestamp;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
trailingStop();
if(timestamp == iTime(Symbol(),Timeframe,0)) return;
timestamp = iTime(Symbol(),Timeframe,0);
double maFast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,0);
double maSlow = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,0);
double maFastLast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,1);
double maSlowLast = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,1);
double CCI = iCCI(NULL,TimeframeCCI,14,PRICE_CLOSE,1);
int total = OrdersTotal();
if (total <50)
if(maFast > maSlow && maFastLast < maSlowLast &&CCI >=100)
{
Print("Long");
int ticket = executeLong();
Print(IntegerToString(ticket));
}
else if(maFast < maSlow && maFastLast > maSlowLast && CCI <=-100)
{
Print("Short");
int ticket = executeShort();
Print(IntegerToString(ticket));
}
}
double LotsOptimized()
{
double lot=Lots;
//--- select lot size
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
if(lot<0.1) lot=0.1;
return(lot);
}
int executeLong ()
{
double entry = Ask;
entry = NormalizeDouble(entry,Digits);
double sl = entry - SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry + TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_BUY,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);
return ticket;
}
int executeShort ()
{
double entry = Bid;
entry = NormalizeDouble(entry,Digits);
double sl = entry + SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry - TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_SELL,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);
return ticket;
}
void trailingStop()
{
for(int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if(OrderType() == OP_BUY){
double sl = Bid - TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl > OrderStopLoss()){
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());
}
}
if(OrderType() == OP_SELL){
double sl = Ask + TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl < OrderStopLoss() || OrderStopLoss() == 0){
bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());
}
}
}
}
}
|
|
|||
|
Nein das ist vermutlich nicht das Problem. Trotzdem Danke
|
|
|||
|
Sorry, aber da hat sich aus meiner Sicht an der Klammersetzung nicht viel geändert oder sehe nur ich das auf dem Schirm so. Z.B. die letzten 5 } stehen allen direkt untereinander. Das sollte überhaupt nicht so sein. Die {}-Pärchen müssen eindeutig ersichtlich zuordnungsfähig sein. Wenn man sich erst überlegen muss, welche { zu welcher} gehört, verliert man doch die Lust nach einem Fehler zu suchen.
traderdoc
__________________
Ich erfülle Euch gern Eure EA-, Indikator- und Script-Programmierungswünsche auf Honorarbasis. |
|
|||
|
Okay ich setz mich morgen nochmal hin und versuche das richtig zu stellen
|
|
|||
|
Ruf doch einfach den Styler des Metaeditor mal auf. Einfach Strg + <Komma> drücken.
|
|
|||
|
Zitat:
Leider hilft mir das aber nicht weiter. |
|
|||
|
Zitat:
![]() Code:
#property strict
input double Lots = 0.01;
input int SLPoints = 500;
input int TPPoints = 500;
input int TSLPoints = 500;
input double MaximalesRisiko = 0.01;
input ENUM_TIMEFRAMES Timeframe = PERIOD_H1;
input int PeriodsMAFast = 50;
input int PeriodsMASlow = 200;
input ENUM_MA_METHOD MethodMAFast = MODE_SMA;
input ENUM_MA_METHOD MethodMASlow = MODE_SMA;
input string Commentary = "Long/Short";
input int Magic = 111;
//globale Variable
datetime timestamp;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{//Beginn Aktion
trailingStop();
if(timestamp == iTime(Symbol(),Timeframe,0)) return;
timestamp = iTime(Symbol(),Timeframe,0);
//Berechnung Moving Averages
double maFast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,1);
double maSlow = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,1);
double maFastLast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,2);
double maSlowLast = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,2);
//-----------------------------------------------------------------------------------------//
//Bedingungen Long
int total = OrdersTotal();
if (total <20)
if(maFast > maSlow && maFastLast < maSlowLast)
{Print("Long");
int ticket = executeLong();
Print(IntegerToString(ticket));}
//------------------------------------------------------------------------------------------//
//Bedingungen Short
else if(maFast < maSlow && maFastLast > maSlowLast)
{Print("Short");
int ticket = executeShort();
Print(IntegerToString(ticket));}
//------------------------------------------------------------------------------------------//
}//Ende Aktion
//Ticket auf Long
int executeLong ()
{double entry = Ask;
entry = NormalizeDouble(entry,Digits);
double sl = entry - SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry + TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_BUY,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);
return ticket;}
//------------------------------------------------------------------------------------------//
//Ticket auf Short
int executeShort ()
{double entry = Bid;
entry = NormalizeDouble(entry,Digits);
double sl = entry + SLPoints * Point;
sl = NormalizeDouble(sl,Digits);
double tp = entry - TPPoints * Point;
tp = NormalizeDouble(tp,Digits);
int ticket = OrderSend(Symbol(),OP_SELL,LotsOptimized,entry,1000,sl,tp,Commentary,Magic);
return ticket;}
//-------------------------------------------------------------------------------------------//
//Berechnung der Handelsgröße
double LotsOptimized()
{double lot=Lots;
lot=NormalizeDouble(AccountFreeMargin()*MaximalesRisiko/1000.0,1);
if(lot<0.1) lot=0.1;
return(lot);}
//------------------------------------------------------------------------------------------//
//TrailingsStop
void trailingStop()
{//Beginn Aktion
for(int i = 0; i < OrdersTotal(); i++)
if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
if(OrderType() == OP_BUY)
{
double sl = Bid - TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl > OrderStopLoss())
{bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());}
}
if(OrderType() == OP_SELL)
{
double sl = Ask + TSLPoints * Point;
sl = NormalizeDouble(sl,Digits);
if(sl < OrderStopLoss() || OrderStopLoss() == 0)
{bool res = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration());}
}
}//Ende Aktion
//---------------------------------------------------------------------------------------------//
Geändert von Blancomi (28.08.18 um 21:37 Uhr) |
![]() |
| Lesezeichen |
| Themen-Optionen | Thema durchsuchen |
| Ansicht | |
|
|