Questions from Beginners MQL5 MT5 MetaTrader 5 - page 323

 

I.e. as I understand it, when receiving data after this print and the message in the logbook

Wait Data for GBPUSD 

the test proceeds according to the algorithm?

 
R0MAN:

I.e. as I understand it, when receiving data after this print and the message in the logbook

the test goes according to the algorithm?

In which function is the line? If it's in OnInit() - then after this line, everything below it won't work... OnCalculate() starts working. We are testing with not fully initialized GBPUSD indicator.
 
Hi all, I put the#property strictdirective and 4 errors popped up.
mistakes in 2,3,5,8 lines

if (CloseFriday == TRUE && DayOfWeek() == 5 && TimeCurrent() >= StrToTime(CloseFridayHour + ":00")) return (0);
op = NormalizeDouble(Bid,Digits);
tp = NormalizeDouble(Bid - (TakeProfit)*Point,Digits);
if (TakeProfit==0) tp=0;
sl = NormalizeDouble(Bid + (StopLoss)*Point,Digits);
if (StopLoss==0) sl=0;
CalcLot();
Ticket=OrderExists(OP_SELL);
if (Ticket<MaxTrades && OrderSymbol()==Symbol())
if (Ticket==-1)
 
MigVRN:
But which line should it be in? If it's in OnInit() - everything below it won't work... OnCalculate() starts working. We are testing with not fully initialized GBPUSD indicator.

Understood. Thank you. This hasn't happened before...

OnCalculate() is starting to work.

//------------------------------------------------------------------    OnInit
int OnInit()
{
        SetIndexBuffer(0, Mediana, INDICATOR_DATA);
        ArraySetAsSeries(Mediana, true);
        // задали имена валют
      ...
//------------------------------------------------------------------    OnCalculate
int OnCalculate(const int rates_total, const int prev_calculated,
                const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[],
                const long& tick_volume[], const long& volume[], const int& spread[])
{

        for (int i=0; i<6; i++) if (Pair[i].CopyBuf(nBars)<0) { Print("Wait Data for "+Pair[i].m_name); return(0); } // получили данные из МА в буфера // при ошибке выходим
        
        int limit=rates_total-prev_calculated; if (limit>=rates_total) limit=rates_total-1; // ограничили на таймсерию
        if (limit>nBars) limit=nBars; // ограничили на число скопированных данных
        
        for(int i=0; i<limit; i++) // проходим по треубемому промежутку и расчитываем медиану
        {
 

Good afternoon dear forum users.

Please tell me the reason why the cycle does not repeat.

This is my first test creation, so-so do not judge severely).

Thanks in advance.

//+-------------------Переменные MACD--------------------------------+
extern int fast_ema_period=12; // период быстрой средней
extern int slow_ema_period=26; // период медленной средней
extern int signal_period=9; // период усреднения разности
extern int shift_MACD=0; // сдвиг индикатора MACD
//+-------------------Переменные DeM---------------------------------+
extern int DeM_period=14; // период усреднения
extern double levelUP=0.7; // верхний уровень
extern double levelDONE=0.3; // нижний уровень
extern int shift_DeM=0; // сдвиг индикатора DeM
//+-------------------Общие переменные-------------------------------+
extern int Magic=7770000; // магический номер
extern double Lot=0.01; // размер лота
extern int slippage=4; // проскальзывание цены
extern int SL=150; // СтопЛосс
extern int TP=300; // ТейкПрофит
int kolpos=0; // количество позиций советника
//+------------------------------------------------------------------+
//| Старт советника                                                  |
//+------------------------------------------------------------------+
int start()                                  
{
   double MAIN=iMACD(Symbol(),0,fast_ema_period,slow_ema_period,signal_period,PRICE_CLOSE,MODE_MAIN,shift_MACD);
   double SIGNAL=iMACD(Symbol(),0,fast_ema_period,slow_ema_period,signal_period,PRICE_CLOSE,MODE_SIGNAL,shift_MACD);
   double DeMval=iDeMarker(Symbol(),0,DeM_period,shift_DeM);
//---
   for (int pos=0; pos<OrdersTotal(); pos++)
      {
      OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
      if (OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
      kolpos++;
      }
   if(kolpos==0)
      {
      if(MAIN>0&&SIGNAL>0&&SIGNAL>MAIN&&DeMval>levelUP)
      OrderSend(Symbol(),OP_SELL,Lot,Bid,slippage,Bid+SL*Point,Bid-TP*Point,NULL,Magic,0,clrBlue);
      if(MAIN<0&&SIGNAL<0&&SIGNAL<MAIN&&DeMval<levelDONE)
      OrderSend(Symbol(),OP_BUY,Lot,Ask,slippage,Ask-SL*Point,Ask+TP*Point,NULL,Magic,0,clrRed);
      }
//---
   return(0);
} 
 
N0mad:

Good afternoon dear forum users.

Can you please tell me the reason why the cycle does not repeat.

This is my first test creation, so-so do not judge severely).

Thanks in advance.

Good evening. Put the variable kolpos in the body of start().
 
Tapochun:
Good evening. Put the variable kolpos in the body of start().
Thank you for your prompt reply. Very helpful.
 

Hello, everyone!

Here is the situation.

The Expert Advisor works on TF M15.

At the same time I can not copy price data for older TFs ( for example CopyHigh(Symbol,PERIOD_D1,0,period,Hi_array) )

cannot copy more than a year. In general it's not surprising, because the synchronization results show about 25 thousands 15M bars, which is exactly a year.

How can I get data for a longer period? Should I synchronize it to D1 or do I have another way?

 
metatrader4 745build, how to insert a script for a previous version, the scripts do not work
 
valera5111:
Metatrader4 745build, how to insert a script for a previous version, scripts do not work

Please specify what exactly you want to do?

  • insert the scriptcode into an indicator or Expert Advisor
  • compile the script code
Describe what errors occur (when compiling, look at the "Errors" tab, when launching in the terminal, look at the "Experts" tab).

Reason: