Fragen von Neueinsteigern zu MQL4 und MQL5, Hilfe und Diskussion über Algorithmen und Codes - Seite 1371

 
MakarFX:

Bis ganz nach unten in der EA.

Leider lässt es sich nicht multiplizieren!!!(((

 
Сергей Дыбленко:

Leider lässt es sich nicht multiplizieren!!!(((

Diese Funktion berechnet das Los im Verhältnis zur freien Marge und dem angegebenen Risiko!

Von welcher Multiplikation sprechen Sie?

 
MakarFX:

Diese Funktion berechnet das Lot im Verhältnis zur freien Marge und dem angegebenen Risiko!

Von welcher Multiplikation sprechen Sie?

Der Anstieg der Lose nach jedem Gewinn!

 
Сергей Дыбленко:

über die Erhöhung der Lose nach jedem Gewinn!

Diese Funktion erhöht das Lot nach einem Gewinn, aber wenn der Gewinn eine Erhöhung um den minimalen Lot-Inkrement erlaubt

 
Сергей Дыбленко:

über die Erhöhung der Lose nach jedem Gewinn!

hier ist ein Beispiel bis 10 000 Ihr Saldo wird Lot 0,1 von 10 000 bis 20 000 mit 0,5 Lot

von 20 000 bis 40 000 mit Los 1,0 über 40 000 mit Los 2,0

//+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Average sample expert advisor"

#define  MAGICMA  20131111
//--- Inputs
input double InpLots       =0.1;
input int    MovingPeriod  =12;
input int    MovingShift   =6;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)
            buys++;
         if(OrderType()==OP_SELL)
            sells++;
        }
     }
//--- return orders volume
   if(buys>0)
      return(buys);
   else
      return(-sells);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double Lots=InpLots;
   double ab=AccountBalance();
   if(ab>=10000 && ab<20000)
      Lots=0.5;
   if(ab>=20000 && ab<40000)
      Lots=1.0;
   if(ab>=40000)
      Lots=2.0;
   return(Lots);
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma;
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1)
      return;
//--- get Moving Average
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//--- sell conditions
   if(Open[1]>ma && Close[1]<ma)
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
      return;
     }
//--- buy conditions
   if(Open[1]<ma && Close[1]>ma)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
      return;
     }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1)
      return;
//--- get Moving Average
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol())
         continue;
      //--- check order type
      if(OrderType()==OP_BUY)
        {
         if(Open[1]>ma && Close[1]<ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]<ma && Close[1]>ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0)
      CheckForOpen();
   else
      CheckForClose();
//---
  }
//+------------------------------------------------------------------+
 
SanAlex:

hier ist ein Beispiel bis 10 000 Ihr Saldo wird Lot 0,1 von 10 000 bis 20 000 mit 0,5 Lot

von 20 000 bis 40 000 mit Los 1,0 über 40 000 mit Los 2,0

dies ist eine feste Losgröße.

für mich, wenn der Gewinn größer oder gleich ist

 MarketInfo(Symbol(), MODE_MARGINREQUIRED)*MarketInfo(Symbol(), MODE_LOTSTEP)

es wird das Los vergrößern,

aber wenn es keine anderen offenen Aufträge gibt, die eine Marge verwenden.

 
MakarFX:

es handelt sich um eine feste Erhöhung des Loses.

In meinem Fall, wenn der Gewinn größer oder gleich ist

dann wird sich das Los vergrößern,

aber wenn es keine anderen offenen Aufträge gibt, die eine Marge verwenden.

Ich habe geschummelt - wenn die Position im Defizit ist, würde es das Los erhöhen

//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedBuy(void)
  {
   double PROFIT_BUY=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           {
            PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_BUY;
   if(ab<-1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if(ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if(ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if(ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell(void)
  {
   double PROFIT_SELL=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
           {
            PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_SELL;
   if(ab<-1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if(ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if(ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if(ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+
 
Ich danke euch allen für eure Hilfe, ABER mein Verstand, der nicht da ist, war nicht genug, um das zu tun, was ich brauchte!
 
Сергей Дыбленко:
Ich danke Ihnen allen für Ihre Hilfe, ABER mein Verstand reicht nicht aus, um das zu tun, was ich tun muss!

Sie erklären Punkt für Punkt, was erforderlich ist.

Wie viele Aufträge in der Arbeit, wie viele Paare Sie gleichzeitig handeln, was sind die Risiken pro Handel (wenn überhaupt)

Und noch etwas von Ihnen)

 
SanAlex:

Hier habe ich geschummelt - wenn die Positionen defizitär sind, würde die Menge steigen

Sasha hat es ein bisschen verändert, um die Quote zu erhöhen

input double factor=1.05;        // коофициент умножения
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell(void)
  {
   double Lots       =0.00;
   double PROFIT_BUY =0.00;
   double LOT_BUY    =0.00;
   double PROFIT_SELL=0.00;
   double LOT_SELL   =0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY)
              {
               PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
               LOT_BUY   =LOT_BUY+NormalizeDouble(OrderLots(),2);
              }
            if(OrderType()==OP_SELL)
              {
               PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
               LOT_SELL   =LOT_SELL+NormalizeDouble(OrderLots(),2);
              }
           }
        }
     }
   if(PROFIT_BUY<0)
      Lots=LOT_BUY*factor;
      else Lots=LOT_BUY;
   if(PROFIT_SELL<0)
      Lots=LOT_SELL*factor;
      else Lots=LOT_SELL;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+ 
Grund der Beschwerde: