Fragen von Anfängern MQL5 MT5 MetaTrader 5 - Seite 1324

 
Alexey Viktorov:

Gestern habe ich dieses Wunder heruntergeladen, um es zu sehen... Plötzlich hatte ich kein Internet. Nach einem Gewitter hatte ich für den Rest des Tages technische Probleme. Also beschloss ich, es aus Faulheit in MQL5 neu zu schreiben und hier zu veröffentlichen.

Jede Wolke hat also einen Silberstreif.........

Ich habe einen Indikator zu Ihrem Expert Advisor hinzugefügt - ich denke, Sie werden nichts dagegen haben! Ich denke, es hat funktioniert, wie Sprut es wollte 185

(in Gelb habe ich es zu meinem bestehenden Expert Advisor hier hinzugefügt).

//+------------------------------------------------------------------+
//|                                                 2 DVA_Martin.mq5 |
//|                                          © 2021, Alexey Viktorov |
//|                     https://www.mql5.com/ru/users/alexeyvik/news |
//+------------------------------------------------------------------+
#property copyright "© 2021, Alexey Viktorov"
#property link      "https://www.mql5.com/ru/users/alexeyvik/news"
#property version   "2.00"
//---
#include <Trade\Trade.mqh>
CTrade trade;
//---
input int     TakeProfit1         = 300;  // профит первой позиции
input int     TakeProfit2         = 250;  // профит второй позиции
input int     TakeProfit3         = 200;  // профит третьей позиции
input int     TakeProfit4         = 100;  // профит четвертой и следующих позиций
input int     Step                = 200;  // шаг первой позиции
input int     Delta               = 100;  // добавка к шагу
// со второй позиции увеличивает расстояние последующих позиций на величину "дельта" от предыдущего
input double  Lot                 = 0.03; // первый лот открытия
input double  MaximalLot          = 0.5;  // максимальный лот, который мы разрешаем
input int     MaxTrades           = 9;    // максимальное количество позиций одного направления
input double  MultiplicatorLot    = 1.6;  // умножаем последующие позиции
input int     Magic               = 123;  // идентификатор советника
//--- Пременные для хранения собранной информации
double MaxLot  = 0;
double LotBuy  = 0;
double LotSell = 0;
//---
int m_bar_current=0;
int StepMA_NRTR_Handle;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   trade.SetExpertMagicNumber(Magic);
   MaxLot = contractSize(MaximalLot);
//--- create StepMA_NRTR indicator
   StepMA_NRTR_Handle=iCustom(NULL,0,"StepMA_NRTR");
   if(StepMA_NRTR_Handle==INVALID_HANDLE)
     {
      printf("Error creating StepMA_NRTR indicator");
      return(false);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double StepMA_NRTR[],StepMA_NRTRS[];
   ArraySetAsSeries(StepMA_NRTR,true);
   ArraySetAsSeries(StepMA_NRTRS,true);
   int start_pos=1,count=3;
   if(!iGetArray(StepMA_NRTR_Handle,0,start_pos,count,StepMA_NRTR)||
      !iGetArray(StepMA_NRTR_Handle,1,start_pos,count,StepMA_NRTRS))
     {
      return;
     }
//---
   int posTotal = PositionsTotal();
   double BuyMinPrice = DBL_MAX, //  Минимальная цена Buy позиции
          SelMaxPrice = DBL_MIN, //  Максимальная цена Sell позиции
          BuyMinLot = 0,         //  Лот самой нижней Buy позиции
          SelMaxLot = 0,         //  Лое самой верхней Sell позиции
          posPrice = 0.0,
          posLot = 0.0,
          BuyAwerage = 0,
          SelAwerage = 0,
          BuyPrice = 0,
          SelPrice = 0,
          BuyLot = 0,
          SelLot = 0;
   MqlTick tick;
   if(!SymbolInfoTick(_Symbol, tick))
      return;
   int b = 0,
       s = 0;
   for(int i = 0; i < posTotal; i++)
     {
      ulong posTicket = PositionGetTicket(i);
      if(PositionGetString(POSITION_SYMBOL) == _Symbol && PositionGetInteger(POSITION_MAGIC) == Magic)
        {
         posPrice = PositionGetDouble(POSITION_PRICE_OPEN);
         posLot = PositionGetDouble(POSITION_VOLUME);
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
           {
            b++; // Считаем открытые позиции на покупку
            if(posPrice < BuyMinPrice)
              {
               BuyMinPrice = posPrice;
               BuyMinLot = posLot;
               BuyPrice += posPrice*posLot;  // добавить к переменной BuyPrice Цена оредра 1 * лот ордера 1
               BuyLot += posLot;             // суммируем лоты
              }
           }
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
           {
            s++; // Считаем открытые позиции на продажу
            if(posPrice > SelMaxPrice)
              {
               SelMaxPrice = posPrice;
               SelMaxLot = posLot;
               SelPrice += posPrice*posLot;  // добавить к переменной BuyPrice Цена оредра 1 * лот ордера 1
               SelLot += posLot;             // суммируем лоты
              }
           }
        }
     }
   LotBuy = b == 0 ? contractSize(Lot) : fmin(MaxLot, contractSize(BuyMinLot*MultiplicatorLot));
   LotSell = s == 0 ? contractSize(Lot) : fmin(MaxLot, contractSize(SelMaxLot*MultiplicatorLot));
//---
//--- BUY Signal
   if(StepMA_NRTR[m_bar_current]<StepMA_NRTRS[m_bar_current])
     {
      if(b == 0 || (b < MaxTrades && BuyMinPrice-tick.ask >= (Step+Delta*b)*_Point))
         openPos(ORDER_TYPE_BUY, LotBuy, tick.ask);
     }
//--- SELL Signal
   if(StepMA_NRTR[m_bar_current]>StepMA_NRTRS[m_bar_current])
     {
      if(s == 0 || (s < MaxTrades && tick.bid-SelMaxPrice >= (Step+Delta*s)*_Point))
         openPos(ORDER_TYPE_SELL, LotSell, tick.bid);
     }
//--- посчитаем математические формулы средних цен
   switch(b)
     {
      case 0 :
         return;
      case 1 :
         BuyAwerage = BuyPrice/BuyLot+TakeProfit1*_Point;
         break;
      case 2 :
         BuyAwerage = BuyPrice/BuyLot+TakeProfit1*_Point;
         break;
      case 3 :
         BuyAwerage = BuyPrice/BuyLot+TakeProfit3*_Point;
         break;
      default:
         BuyAwerage = BuyPrice/BuyLot+TakeProfit4*_Point;
         break;
     }
   switch(s)
     {
      case 0 :
         return;
      case 1 :
         SelAwerage = SelPrice/SelLot-TakeProfit1*_Point;
         break;
      case 2 :
         SelAwerage = SelPrice/SelLot-TakeProfit2*_Point;
         break;
      case 3 :
         SelAwerage = SelPrice/SelLot-TakeProfit3*_Point;
         break;
      default:
         SelAwerage = SelPrice/SelLot-TakeProfit4*_Point;
         break;
     }
   normalizePrice(BuyAwerage); // Произведем расчет цены TP Buy
   normalizePrice(SelAwerage); // Произведем расчет цены TP Sell
//---
   for(int i = 0; i < posTotal; i++)
     {
      ulong posTicket = PositionGetTicket(i);
      if(PositionGetString(POSITION_SYMBOL) == _Symbol && PositionGetInteger(POSITION_MAGIC) == Magic)
        {
         double posTP = PositionGetDouble(POSITION_TP);
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
           {
            if(fabs(posTP-BuyAwerage) > _Point && tick.ask < BuyAwerage) // Если тейк не равен требуемой цене
               if(!trade.PositionModify(posTicket, 0.0, BuyAwerage))
                  Print("Ошибка ", __LINE__);
           }
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
           {
            if(fabs(posTP-SelAwerage) > _Point && tick.bid > SelAwerage) // Если тейк не равен требуемой цене
               if(!trade.PositionModify(posTicket, 0.0, SelAwerage))
                  Print("Ошибка ", __LINE__);
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void openPos(ENUM_ORDER_TYPE type, double lot, double price)
  {
   trade.CheckVolume(_Symbol, lot, price, type);
   if(trade.CheckResultMarginFree() <= 0.0)
     {
      Print("Not enough money for ", EnumToString(type), " ", lot, " ", _Symbol, " Error code=", trade.CheckResultRetcode());
      return;
     }
   if(!trade.PositionOpen(_Symbol, type, LotBuy, price, 0.0, 0.0))
      Print(trade.ResultRetcode());
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double contractSize(double volume, string symbol = NULL)
  {
   symbol = symbol == NULL ? _Symbol : symbol;
   double v = volume;
   double volumeStep = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
   v = round(volume/volumeStep)*volumeStep;
   double minLot = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
   return((v < minLot ? minLot : v));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double normalizePrice(double &price, string symbol = NULL)
  {
   symbol = symbol == NULL ? _Symbol : symbol;
   double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
   price = round(price/tickSize)*tickSize;
   return(tickSize);
  }
//+------------------------------------------------------------------+
//| Filling the indicator buffers from the indicator                 |
//+------------------------------------------------------------------+
bool iGetArray(const int handle,const int buffer,const int start_pos,
               const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      return(false);
     }
   ArrayFree(arr_buffer);
//--- reset error code
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      return(false);
     }
   return(result);
  }
//+------------------------------------------------------------------+

Советники: DVA_Martin
Советники: DVA_Martin
  • 2021.06.30
  • www.mql5.com
Статьи и техническая библиотека по автоматическому трейдингу: Советники: DVA_Martin
 
SanAlex:

Ich habe einen Indikator zu Ihrem Expert Advisor hinzugefügt - ich denke, Sie haben nichts dagegen? es scheint zu funktionieren, wie Sprut es wollte 185

(in Gelb habe ich es zu meinem bestehenden Expert Advisor hier hinzugefügt).

Und warum die Indikatorwerte von drei Balken? Und warum sollte man das Feld in Zeitreihen umwandeln?

Im Allgemeinen scheint es mir, dass es nicht der richtige ist... Kein Martin wird funktionieren.

 
Alexey Viktorov:

Warum brauchen Sie die Indikatorwerte von drei Balken? Und warum sollte man das Feld in Zeitreihen umwandeln?

Im Allgemeinen scheint es mir, dass dies nicht der Fall ist... Kein Martin wird funktionieren.

Der Indikator ist hier nur ein Richtungsfilter - und Ihr Expert Advisor übernimmt die ganze Aufgabe

\\\\\\\\\\\\\

Der Indikator selbst eröffnet keine Positionen.

 
SanAlex:

Der Indikator ist hier nur ein Richtungsfilter - und Ihr Experte übernimmt die ganze Aufgabe

Der geschriebene Code sollte die Aufgabe erfüllen. Aber Sie haben eine solche Bedingung gestellt, dass sich der Martin niemals einschalten wird. Ich glaube schon, aber ich habe weder Lust noch Zeit, das zu überprüfen.

 
Alexey Viktorov:

Die Aufgabe muss durch den von Ihnen geschriebenen Code erledigt werden. Aber Sie haben zur Bedingung gemacht, dass sich der Martin niemals einschalten wird. Ich glaube schon, aber ich habe weder Lust noch Zeit, das zu überprüfen.

Hier überprüfe ich seine Arbeit - alles funktioniert wie vorgesehen.

2 DVA_Martin

 
Alexey Viktorov:

Soll Martin nur aktiviert werden, wenn das Blinkersignal entgegengesetzt ist oder unabhängig davon?

Beispiel: Gemäß dem Indikator wurde eine Kaufposition eröffnet. Der Kurs ist um die festgelegte Strecke gefallen und der Indikator zeigt bereits Sell an. Soll die Kaufposition eröffnet werden?

Wie versprochen - ich habe etwas photoshopped.

1

Wenn es nicht klar ist, kann ich die Bedeutung meiner Idee nur in einem persönlichen Gespräch mit Ihnen erklären.

 
SanAlex:

Ich habe hier etwas falsch gemacht - ich weiß nicht, was aus 100.000 Rubel zwei Millionen gemacht hat.

änderte den Indikator und 5min Euro\bucks in 15 Tagen auf eine Million.

LeMan_BrainTrend1Sig 2

LeMan_BrainTrend1Sig

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

zum Expert Advisor hinzugefügt - um den Gewinn (von allen Paaren) zu schließen und den Expert Advisor zu löschen

input group  "---- : Parameters:  ----"
input int    TargetProfit     = 1000000; // : Balance + Profit(add to balance)
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(void)
  {
//---
   if(AccountInfoDouble(ACCOUNT_EQUITY)>=TargetProfit)
     {
      AllClose();
      ExpertRemove();
     }
//---

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Ich benötige diese 2 Indikatoren (die Namen der Indikatoren sollten sich nicht ändern)

 
SanAlex:

tauschte den Indikator und die 5-Minuten-Euros in 15 Tagen gegen eine Million.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

in Expert Advisor hinzugefügt - durch Gesamtgewinn (von allen Paaren) zu Close Profit und Expert Advisor löschen

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Diese 2 Indikatoren müssen vorhanden sein (d.h. die Namen der Indikatoren würden sich nicht ändern)

Nicht genügend Stoploss im Setup

 

Es gibt Möglichkeiten, eine Zeichenkette mit einer Methode wie \n" in mehrere Strings aufzuteilen.

Gibt es Möglichkeiten, eine String-Variable in einen einzelnen String aufzuteilen?

Das heißt, alle Texte, Werte, Parameter usw., die in dieser String-Variablen vorhanden sind, in einen String zu schreiben.

Das Problem trat beim Schreiben in eine csv-Datei auf (die Werte von String-Variablen werden in ein Bündel von Strings geschrieben).

 
Vitaly Muzichenko:

Nicht genügend Stoploss im Setup

mit Stop Loss ist nicht mehr der gleiche Gewinn

Verluststopp

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Ich denke, dass der Expert Advisor öfters neu gestartet werden muss - zum Beispiel habe ich den Gesamtgewinn (von allen Paaren) für die Woche genommen und den Expert Advisor von allen Paaren gelöscht.

und starten Sie den EA neu, bis ein neuer Gesamtgewinn aus allen Paaren erreicht ist.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

eine weitere Idee bezüglich des Stopps - Stoppen Sie nicht, um die Position zu schließen, sondern um eine entgegengesetzte Position mit vielen entgegengesetzten (verlustreichen) offenen Positionen zu eröffnen

Hier ist eine Übersicht über die offenen Positionen in Losen

   int total=PositionsTotal();
   for(int i=total-1; i>=0; i--) // returns the number of open positions
     {
      string   position_GetSymbol=PositionGetSymbol(i); // GetSymbol позиции
      if(position_GetSymbol==m_symbol.Name())
        {
         if(m_position.PositionType()==POSITION_TYPE_BUY)
           {
            PROFIT_BUY=PROFIT_BUY+PositionGetDouble(POSITION_PROFIT);
            PROFIT_BUY_Lot=PROFIT_BUY_Lot+PositionGetDouble(POSITION_VOLUME);
           }
         else
           {
            PROFIT_SELL=PROFIT_SELL+PositionGetDouble(POSITION_PROFIT);
            PROFIT_SELL_Lot=PROFIT_SELL_Lot+PositionGetDouble(POSITION_VOLUME);
           }
           {
            PROFIT_CLOSE=AccountInfoDouble(ACCOUNT_PROFIT);
           }
        }
     }
//---

Stop Loss 777

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Der Grund dafür ist, dass der Stopp die Position nicht schließt und das entgegengesetzte Los beim manuellen Handel helfen soll.

Grund der Beschwerde: