Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 711

 
Artyom Trishkin:

Quicker to figure out and understand

write down the prices, how to take them afterwards, when what?

void PriceTimePos(string sy="",int op=-1,int mn=-1)
  {
  double Цены[3];
   datetime t;
   bool daa;
   int d,k_=OrdersTotal(),typ_;
   double   r=0;
   int      i,k=OrdersHistoryTotal();

   if(sy=="0") sy=Symbol();
   for(i=0; i<k; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               if(op<0 || OrderType()==op)
                 {
                  if(mn<0 || OrderMagicNumber()==mn)
                    {
                     if(OrderCloseTime()>=TimeCurrent()-2440*60)
                       {
                        t=OrderCloseTime();
                        r=OrderOpenPrice();
                        sl=OrderStopLoss();
                        tp=OrderTakeProfit();
                        lot=OrderLots();
                        typ_=OrderType();
                        Print("OpenPrice",r);
                       Цены[0]=OrderOpenPrice();
                    
                       }
                    }
                 }
              }
           }
        }
     }
//
  }
to insert in this loop instead of r
                        daa=false;
                        for(i=0; i<k; i++)
                          {
                           if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
                             {
                              if((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op))
                                {
                                 if(OrderType()>1 && OrderType()<6)
                                   {
                                    d=MarketInfo(OrderSymbol(), MODE_DIGITS);
                                    r=NormalizeDouble(r, d);
                                    if(r==NormalizeDouble(OrderOpenPrice(),d)) daa=true; 
                                   }
                                }
                             }
                          }
 

Hello, I have made a function which should increase the stop loss after the last order has closed in minus.

Increases it by the set step, until it reaches the maximum. As a result, it always sets the original value of stop loss.

What is wrong? Thank you!

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

double SL()

{

double sL;

if(OrdersHistoryTotal()==0)

{

sL=StopLoss;

}

if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))

{

if(OrderProfit()>=0)

{

sL=StopLoss;

}

if(OrderProfit()<0 && OrderType()==OP_BUY)

{

sL=OrderOpenPrice()-OrderStopLoss()+SLStep;

}

if(OrderProfit()<0 && OrderType()==OP_SELL)

{

sL=OrderStopLoss()-OrderOpenPrice()+SLStep;

}

}

if(sL>maxStep)

{

sL=StopLoss;

}

return(sL);

}

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

 
Artyom Trishkin:
  1. You are correct to return values from non- void functions, but it is better to switch to new rails - there is nothing complicated there.
  2. Write, do not forget to insert #property strict directive at the very beginning of the code - where all directives are written, read error codes - their descriptions are in the documentation and everything will be fine and not complicated.
Where can I find the error codes? Where is this documentation?
 
#property strict

int Count=0;

void OnInit()     
{
   Alert ("Сработала ф-ия init() при запуске");   // Сообщение
   return;                                                                     // Выход из init()
   }   
//--------------------------------------------------------------------
void OnStart()                                                                       // Спец. ф-ия start()
   {
   double Price = Bid;                                                      // Локальная перемен.
   Count++;                                                                      // Счётчик тиков
   Alert("Новый тик ",Count," Цена = ",Price);       // Сообщение
   return;                                                                        // Выход из start()
   }
void OnDeinit()                                                                              // Спец. ф-ия deinit()
   {
   Alert ("Сработала ф-ия deinit() при выгрузке");         // Сообщение
   return;                                                                                 // Выход из deinit()
   }

What am I writing it wrong?

It should go like this http://prntscr.com/lu1kb9


Tried to insert the data under the current template

//+------------------------------------------------------------------+
//|                                                            п.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

   Alert ("Сработала ф-ия init() при запуске");   // Сообщение
                                                                       // Выход из init()
     
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
Alert ("Сработала ф-ия deinit() при выгрузке");         // Сообщение
   return;
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 
   double Price = PRICE_OPEN;                                                      // Локальная перемен.
   Count++;                                                                      // Счётчик тиков
   Alert("Новый тик ",Count," Цена = ",Price);       // Сообщение
   return;                                                                        // Выход из start()
   
   
  }
//+------------------------------------------------------------------+


But it's still not the same. help me
Скриншот
Скриншот
  • prnt.sc
Снято с помощью Lightshot
 
Please help, does anyone have a function that can pass an array to calculate the maximum drawdown?
 

Good afternoon.

I am mastering emq-el by Sergei Kovalev's tutorial.

I downloaded the Expert Advisor from there, compiled it, it even seems to work, but when compiling it displays some comments, not errors, but warnings.

What should I change to make it compile without any errors? Thank you in advance.

Files:
expert.mq4  28 kb
 
Sergey Branin:
Where can I find the error codes? Where is this documentation?

In the menu of this website - look up

 
Artyom Trishkin:

In the menu of this site - look up

Artem, there is documentation on mql5, and the questions are in the mql4 section

Sergey Branin:
Where can I find the error codes? Where is this documentation?

Here is mql4 documentation. You may also press F1 in MetaEditor

Справочник MQL4
Справочник MQL4
  • docs.mql4.com
MetaQuotes Language 4 (MQL4) - встроенный язык программирования торговых стратегий, разработанный компанией MetaQuotes Software Corp. на основе своего многолетнего опыта в создании торгово-информационных платформ. Этот язык позволяет писать собственные программы-эксперты (Expert Advisors), автоматизирующие управление торговыми процессами и...
 
Alexey Viktorov:

Artyom, is the mql5 documentation there? and the questions are in the mql4 section

There is a documentation on mql4. And it is better to press F1 while in the MetaEditor

Ahh... Well all the same - it's not so complicated either - it's faster to put your finger on F1 and find everything you need than to wait 24 hours for an answer on the forum. I don't understand ...

 
Hello, I'm new to programming. I haven't found any ready-made code anywhere. The idea is the following - I need to control a custom indicator from an EA, or rather change its external parameters (one) when some event happens. The logic in brief - if the lot (or for example the number of positions) > a predefined value, the external setting in the indicator (which is in another window and is not connected with this EA) changes on the fly without re-initialization of the indicator. Maybe you can try to do it through
 string ServiceCustomIndicatorByIndexA(int nIndex);// я даже не знаю тут   ANSI или UNICODE нужно
и
int ServiceGetNamesIndicatorsMA(int hwndChart,int nWindow,string &asIndicators[],int nSize);   
I do not know how to do it, may any programmer write a simple code block for an example. c/o Denis