Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   automatische Anpassung der Positionsgröße (http://www.expert-advisor.com/forum/showthread.php?t=6182)

Blancomi 26.08.18 15:59

automatische Anpassung der Positionsgröße
 
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 :)

traderdoc 26.08.18 16:16

Ok, aber dann solltest Du erst einmal einen Code schreiben mit klaren Strukturen. Bei den {} Setzungen sieht doch keiner durch!

traderdoc

daybyter 27.08.18 03:05

Fehlt in der Zeile mit

if (total <50)

eine geöffnete geschweifte Klammer?

Blancomi 27.08.18 18:45

Zitat:

Zitat von traderdoc (Beitrag 41497)
Ok, aber dann solltest Du erst einmal einen Code schreiben mit klaren Strukturen. Bei den {} Setzungen sieht doch keiner durch!

traderdoc


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());
       
}

}

}

}

}


Blancomi 27.08.18 18:46

Zitat:

Zitat von daybyter (Beitrag 41502)
Fehlt in der Zeile mit

if (total <50)

eine geöffnete geschweifte Klammer?

Nein das ist vermutlich nicht das Problem. Trotzdem Danke

traderdoc 27.08.18 19:57

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

Blancomi 27.08.18 20:27

Okay ich setz mich morgen nochmal hin und versuche das richtig zu stellen

daybyter 27.08.18 21:53

Ruf doch einfach den Styler des Metaeditor mal auf. Einfach Strg + <Komma> drücken.

Blancomi 28.08.18 21:26

Zitat:

Zitat von daybyter (Beitrag 41508)
Ruf doch einfach den Styler des Metaeditor mal auf. Einfach Strg + <Komma> drücken.

Habe ich bisher nicht gekannt, Danke!
Leider hilft mir das aber nicht weiter.

Blancomi 28.08.18 21:26

Zitat:

Zitat von traderdoc (Beitrag 41506)
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

Nächster Versuch ;)

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
//---------------------------------------------------------------------------------------------//



Alle Zeitangaben in WEZ +2. Es ist jetzt 00:13 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum