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

 
Alexander Avksentyev #:

Es tut mir leid, dass ich aufdringlich war.

Es ist nicht aufdringlich. Scheuen Sie sich nicht zu sagen, dass Sie etwas nicht wissen - fragen Sie immer.

Ich gebe Ihnen ein Beispiel.
 
Alexander Avksentyev #:

Was sind "iTrailStart" und "iTrailDist"?

 
Tretyakov Rostyslav #:

Was sind "iTrailStart" und "iTrailDist"?

Anzahl der einzuschaltenden Punkte und Entfernung vom Markt zum Schleppnetz

iTrailStart = 10; //Anzahl der Punkte zur Aktivierung des Schleppnetzes;

iTrailDist = 10; //Entfernung von der Haltestelle zum Markt;

Wenn der Auftrag um 11 Pips im Plus liegt, dann ist 11-10=1 Pips ohne Verlust.

 
Alexander Avksentyev #:

Anzahl der einzubeziehenden Punkte und Entfernung vom Markt zum tsl

Mehr oder weniger

//--- input parameters
int iTrailStart   = 10;  //Кол-во пунктов для включения тралa
int iTrailDist    = 10;  //Расстояние от стопа до рынка
//--- global parameters
int iDistTrail = iTrailDist;
//+------------------------------------------------------------------+
void OnTick()
  {
//---
if(iDistTrail<MarketInfo(Symbol(),MODE_STOPLEVEL))
   iDistTrail = MarketInfo(Symbol(),MODE_STOPLEVEL);
   
   // дальше твой код

  }
//+------------------------------------------------------------------+
void TrailSL()
  {
   if(iTrailStart <= 0) return; 
      
   double sl_lev;
         
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            if(OrderType() == OP_BUY) 
              {
               if ((OrderStopLoss() == 0 && Bid > OrderOpenPrice() + iTrailStart * _Point)||(OrderStopLoss() != 0 && Bid > OrderStopLoss() + (iDistTrail+iTrailStep) * _Point))
                 {
                  sl_lev = NormalizeDouble(Bid - iDistTrail * _Point,Digits);
                  if (OrderModify(OrderTicket(), OrderOpenPrice(), sl_lev, OrderTakeProfit(), 0, clrRed))
                     Print("Удачная модифиция стоплосс ордера №",OrderTicket());
                  else
                     Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
                 }
              }
            if(OrderType() == OP_SELL) 
              {
               if ((OrderStopLoss() == 0 && Ask < OrderOpenPrice() - iTrailStart * _Point)||(OrderStopLoss() != 0 && Ask < OrderStopLoss() - (iDistTrail+iTrailStep) * _Point))
                 {
                  sl_lev = NormalizeDouble(Ask + iDistTrail * _Point,Digits);
                  if (OrderModify(OrderTicket(), OrderOpenPrice(), sl_lev, OrderTakeProfit(), 0, clrRed))
                     Print("Удачная модифиция стоплосс ордера №",OrderTicket());
                  else
                     Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
 

Gibt es eine ENUM für diese Konstanten oder muss ich meine eigene schreiben?

Konstante

Wert

Beschreibung

DRAW_LINE

0

Einfache Linie

ZEICHNEN_SCHNITT

1

Liniensegmente zwischen nicht leeren Linienwerten

DRAW_HISTOGRAM

2

Histogramm

ZEICHEN_PFEIL

3

Pfeile (Symbole)

DRAW_ZIGZAG

4

Intervalle zwischen den nicht leeren Werten der geraden und ungeraden Linien (Zickzack), 2

DRAW_NONE

12

Keine Zeichnung irgendeiner Art

 
Tretyakov Rostyslav #:

Gibt es eine ENUM für diese Konstanten oder muss ich meine eigene schreiben?

Konstante

Wert

Beschreibung

DRAW_LINE

0

Einfache Linie

ZEICHNEN_SCHNITT

1

Liniensegmente zwischen nicht leeren Linienwerten

DRAW_HISTOGRAM

2

Histogramm

ZEICHEN_PFEIL

3

Pfeile (Symbole)

DRAW_ZIGZAG

4

Intervalle zwischen den nicht leeren Werten der geraden und ungeraden Linien (Zickzack), 2

DRAW_NONE

12

Keine Zeichnung

Zeichnungsstile

ENUM_DRAW_TYPE

sorry mql4 hat so etwas nicht...
 
Alexey Viktorov #:
Zeichnungsstile

ENUM_DRAW_TYPE

Tut mir leid, mql4 hat so etwas nicht...
Danke, ich werde meine eigene schreiben)
 
Tretyakov Rostyslav #:

So ist das nun mal.

Danke, ich werde weiter graben und es herausfinden.

 
Tretyakov Rostyslav #:

Etwa so

int      Login = 4950287;

datetime time  = D'2022.01.01 00:00:00';

string   name  = "Test";

datetime time1 = 0;

double   TP, lastlot, minlot;

int      Forder;

int      TakeProfit,TrailStart,TrailDist,TrailStep,TrailTakeProfit,Step,Slippage;

double   level_count=0;

int iDistTrail = iTrailDist;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

//Torder-Цена открытия первого ордера

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

{

     if(AccountNumber() != Login)

       {

        int close = MessageBox("Неверный номер счёта","Ошибка",MB_OK|MB_ICONSTOP);

        return(INIT_FAILED);

       }else (AccountNumber() == Login);

             {

              int close = MessageBox("Проверка прошла успешно.Экcперт может приступить к работе.","Инициализация",MB_OK|MB_ICONEXCLAMATION);

             }

 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//  

     if (TimeCurrent() > time)

        {

         int close = MessageBox("Время работы закончилось!!!","Время работы",MB_OK|MB_ICONSTOP);

         return(INIT_FAILED);

        }else(TimeCurrent() < time);

             {

              int close = MessageBox("Проверка времени работы прошла успешно.Эксперт может приступить к работе!","Время работы",MB_OK|MB_ICONEXCLAMATION);

             }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

      TakeProfit         =iTakeProfit;

      TrailStart         =iTrailStart;

      TrailDist          =iTrailDist;

      TrailStep          =iTrailStep;

      TrailTakeProfit    =iTrailTakeProfit;

      Step               =iStep;

      Slippage           =iSlippage;

      

 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//   

     if(Digits == 3 || Digits == 5)

       {

        TakeProfit      *=10;

        TrailStart      *=10;

        TrailDist       *=10;

        TrailStep       *=10;

        TrailTakeProfit *=10;

        Step            *=10;

        Slippage        *=10;

       }

       return(INIT_SUCCEEDED);

    }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+



void OnTick()

  {

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

 /*  Comment( 

  "\n",                      name,

  "\n", 

  " ",                       Symbol(),  

  "\n",

  "Тайм Фрейм ",             Period(),

  "\n",                      AccountCompany(),

  "\n",

  "\n ",                     AccountServer(),

  "\n", 

  "Lots\n",                  B_S_Lot(),

  "\n",

  "Price ",                  Bid,

  "\n", 

  "Дата ",                   TimeToString( TimeCurrent(), TIME_DATE ),

  "\n",

  "Server Time ",            TimeToString( TimeCurrent(), TIME_SECONDS ),

  "\n", 

  "Profit ",                 Profit(),

  "\n",

  "AvTP ",                   CalcTP (),

  "\n", 

  "Количество ордеров ",     CountTrades(),

  "\n",

  "\n ",                     GetVolumeLotLastOrder(),

  "\n",

  "\n", "Процент просадки ", NormalizeDouble(  (AccountInfoDouble(ACCOUNT_BALANCE)-AccountInfoDouble(ACCOUNT_MARGIN_FREE))/AccountInfoDouble(ACCOUNT_BALANCE)*100,2)

  );*/ 

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

   double body = Close[1] - Open[1];

   if (CountTrades() == 0 && body > 0) BuyOpen();     // Если нет открытых и сигнал бай

   if (CountTrades() == 0 && body < 0) SellOpen();    // Если нет открытых и сигнал селл

   if (CountTrades(0) > 0 && body > 0) BuyOpen();     // Если есть открытые бай и сигнал бай

   if (CountTrades(1) > 0 && body < 0) SellOpen();    // Если есть открытые селл и сигнал селл

  /* if (iTrailStart<MarketInfo(Symbol(),MODE_STOPLEVEL))

   iTrailStart= MarketInfo(Symbol(), MODE_STOPLEVEL * Point);

   iTrailSL();

  */

   if(iDistTrail<MarketInfo(Symbol(),MODE_STOPLEVEL))

   iDistTrail = MarketInfo(Symbol(),MODE_STOPLEVEL);

  }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

void BuyOpen() //Открытие позиции Buy

  {

   Forder = (OrderSend(_Symbol,OP_BUY,Lot,Ask,iSlippage,0,0,"Коммент",Magic,0,Blue));

   if(Forder > 0)

     {

      Print("Открыта Позиция BUY");

      if(OrderSelect(Forder, SELECT_BY_TICKET))

        {

         TP = NormalizeDouble((Ask+iTakeProfit*_Point),_Digits);

         if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))

            Print("Ордер Модифицирован BUY "); 

         else 

            Print("Ошибка Модификации Ордера BUY = ",GetLastError());

        }

     }

   else Print("Ошибка Открытия Позиции BUY");

  }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

void SellOpen() //Открытие позиции Sell  

  {

   Forder = (OrderSend(_Symbol,OP_SELL,Lot,Bid,iSlippage,0,0,"Коммент Sell",Magic,0,Red));

   if (Forder > 0)

     {

      Print("Открыта Позиция SELL");

      if(OrderSelect(Forder, SELECT_BY_TICKET))

        {

         TP = NormalizeDouble((Bid-iTakeProfit*_Point),_Digits);

         if (OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0))

            Print("Ордер Модифицирован SELL "); 

         else 

            Print("Ошибка Модификации Ордера SELL = ",GetLastError());

        }

     }

   else Print("Ошибка Открытия Позиции SELL");

  }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

//+------------------------------------------------------------------+

//| Tester function                                                  |

//+------------------------------------------------------------------+

double OnTester()

  {

//---

   double ret=0.0;

//---



//---

   return(ret);

  }

//+------------------------------------------------------------------+

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

//+------------------------------------------------------------------+

//|                       Подсчёт эквити                             |

//+------------------------------------------------------------------+

double Profit(){double count=0;

    for (int i=OrdersTotal()-1; i>=0; i--){

        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){

           if(OrderSymbol() == Symbol() && OrderMagicNumber()==Magic)

              count+=OrderProfit();  count+=OrderSwap();               

           }   

        }   

    return(NormalizeDouble(count, 2));

}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx//

void TrailSL()

  {

   if(iTrailStart <= 0) return; 

      

   double sl_lev;

         

   for(int i=OrdersTotal()-1; i>=0; i--)

     {

      if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

           {

            if(OrderType() == OP_BUY) 

              {

               if ((OrderStopLoss() == 0 && Bid > OrderOpenPrice() + iTrailStart * _Point)||(OrderStopLoss() != 0 && Bid > OrderStopLoss() + (iDistTrail+iTrailStep) * _Point))

                 {

                  sl_lev = NormalizeDouble(Bid - iDistTrail * _Point,Digits);

                  if (OrderModify(OrderTicket(), OrderOpenPrice(), sl_lev, OrderTakeProfit(), 0, clrRed))

                     Print("Удачная модифиция стоплосс ордера №",OrderTicket());

                  else

                     Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());

                 }

              }

            if(OrderType() == OP_SELL) 

              {

               if ((OrderStopLoss() == 0 && Ask < OrderOpenPrice() - iTrailStart * _Point)||(OrderStopLoss() != 0 && Ask < OrderStopLoss() - (iDistTrail+iTrailStep) * _Point))

                 {

                  sl_lev = NormalizeDouble(Ask + iDistTrail * _Point,Digits);

                  if (OrderModify(OrderTicket(), OrderOpenPrice(), sl_lev, OrderTakeProfit(), 0, clrRed))

                     Print("Удачная модифиция стоплосс ордера №",OrderTicket());

                  else

                     Print("Не удалось модифицировать стоплосс ордера №",OrderTicket(),". Ошибка: ",GetLastError());

                 }

              }

           }

        }

     }

  }

//+------------------------------------------------------------------+

Hier ist der Code, vielleicht habe ich ihn falsch verstanden, aber es gibt keinen Effekt.

 
Alexander Avksentyev #:

Hier ist der Code, vielleicht habe ich ihn falsch verstanden, aber es gibt keinen Effekt.

Was steht im Logbuch?

Posten Sie den gesamten Code und hängen Sie ihn als Datei an.