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

 
Artyom Trishkin:

Advertising a third-party resource and private channels. If it wasn't for me, I might have been banned.

What ad? A video tutorial on what's being asked.

 
Andrey Sokolov:

What kind of commercial? A video tutorial on what is being asked.

Video lessons via the button
 
What am I doing wrong?
int OnInit()
  {
//--- indicator buffers mapping
    SetIndexBuffer(0,Buy);
   SetIndexBuffer(1,Sell);  
   // Устанавливаем нулевые значения для индикатора, при которых не будет сигнальных стрелок
   SetIndexEmptyValue (0, 0);
   SetIndexEmptyValue (1, 0);
   //Определяем стиль отображения индикаторных линий - стрелка
   SetIndexStyle (0, DRAW_ARROW);
   SetIndexStyle (1, DRAW_ARROW); 
   // Установим значки "стрелки" для буферов
   SetIndexArrow(0, 234);  //Стрелка "вниз" для продаж
   SetIndexArrow(1, 233);  //Стрелка "вверх" для покупок
   //Устанавливаем текст описания стрелок индикатора для отображения информации в всплывающей подсказке.
   SetIndexLabel(0, "Продаём");
   SetIndexLabel(1, "Покупаем");
   //Определяем разрядность значений индикаторных линий - приравниваем разрядности фин. инструмента
   IndicatorDigits (Digits);
   //Строка с кратким названием индикатора выводится в сплывающей подсказке при наведении указателя мыши на стрелку
   IndicatorShortName ("Мой первый индикатор");
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
    int limit=rates_total-prev_calculated-5;
   if(limit<1) return(0);
   for(int i=limit;i>=0;i--)
     {
      // Снимем показания индикатора
     double in1b = iCustom(NULL,0,"in1",1,0); // индикатор 1 стрелка вверх
     double in1s = iCustom(NULL,0,"in1",0,0); // индикатор 1 стрелка вниз
     
     double in2b = iCustom(NULL,0,"in2",0,0); // индикатор 2 стрелка вверх
     double in2s = iCustom(NULL,0,"in2",1,0); // индикатор 2 стрелка вниз
     
     if (in1b/* && in2b*/)
           Buy[i]=high[i];
     if (in1s/* && in2s*/)
            
             Sell[i]=low[i];
   
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
jarikn:
what am i doing wrong?
if (in1b)

what??? more, less or equal...what are you comparing "in1b" to?

 

Good afternoon everyone. I am trying to attach a fixed points profit to my EA in addition to the profit calculated in the risk size. Profit in risk size is working fine. But it sets some unreal value in pips. I have a listing of what will be the profit in the risk size or in points

  enum enumTP //ПЕРЕЧИСЛЕНИЕ ДЛЯ ТЕЙК ПРОФИТА
  {
   en_fiks_tp = 1, // ФИКСИРОВАННЫЙ В ПУНКТАХ
   en_v_r = 0,  // В КОЛИЧЕСТВЕ Р
  };


I set a variable that defines profit size in points.

extern int Razmer_tp = 1500; // ТЕЙК ПРОФИТ В ПУНКТАХ

Then I write the following profit calculation and check its correctness in the on-tick.

//+--НАЧАЛО РАСЧЁТА ПРОФИТА---------------------------------------------------------------------- Разделитель ---+

if(sl > 0 && Tip_tp == en_v_r) // ЕСЛИ ПРОФИТ В КОЛИЧЕСТВЕ Р
//{// НАЧАЛО ПРОВЕРКИ НА НОЛЬ
  tp=sl*tp_v_R; // ВЫЧИСЛЯЕМ ПРОФИТ УМНОЖАЯ СТОП ЛОС НА КОЛИЧЕСТВО РИСКА
  //-НАЧАЛО РАСЧЁТА ПРОФИТА В ПУНКТАХ---------------------------------------------------------------------------------------------+
  
  if(Tip_tp == en_fiks_tp)
  {//--НАЧАЛО ЕСЛИ ПРОФИТ В ПУНКТАХ---------------------------------------------------------------------------------------------+
  tp = Razmer_tp;  // ПРОФИТУ ПРИСВАЕВАЕМ КОЛИЧЕСТВО ПУНКТ
  
  }//---КОЕНЦ ЕСЛИ ПРОФИТ В ПУНКТАХ---------------------------------------------------------------------------------------------+
  tp= NormalizeDouble(tp, Digits());// НОРМАЛИЗУЕМ ПРОФИТ, ЧТОБЫ РАБОТАЛО НА ЛЮБЫХ КАТИРОВКАХ
  
  // ПРОВЕРКА ТЕЙК ПРОФИТА НА СТОП ЛЕВЕЛ ОТ МАКАРА--
  if(tp<stoplevel)                                                           // ЕСЛИ ПРОФИТ МЕНЬШЕ ЧЕМ МИНИМАЛЬНО ДОПУСТИМЫЙ УРОВЕНЬ ЕГО УСТАНОВКИ ТО
  {
         tp=NormalizeDouble(stoplevel*1.5,Digits); // ПРОФИТУ ПРИСВАЕВАЕМ МИНИМАЛЬНО ДОПУСТИМУЮ ВЕЛИЧИНУ ЕГО УСТАНОВКИ
  }
  //} // КОНЕЦ ПРОВЕРКИ НА НОЛЬ 
  
  //+--КОНЕЦ РАСЧЁТА ПРОФИТА---------------------------------------------------------------------- Разделитель ---+


For profit in risk size it works fine, but not for fixed profit in pips. Please advise me what I am doing wrong and what should be corrected to make my profit calculation work correctly in points?

 
DanilaMactep:

Good afternoon everyone. I am trying to attach a fixed points profit to my EA in addition to the profit calculated in the risk size. Profit in risk size is working fine. But it sets some unreal value in pips. I have a listing of what will be the profit in the risk size or in points


I set a variable that defines profit size in points.

Then I write the following profit calculation and check its correctness in the on-tick.


For profit in risk size it works fine, but not for fixed profit in pips. Please advise what I am doing wrong and what should be corrected when calculating profit in points?

I would like to ask you to multiply the profit in pips by"Point".

 
jarikn:
What am I doing wrong?

What are you doing?

 
MakarFX:

what??? more, less or equal... what are you comparing "in1b" to?

i don't have the add screenshot button you wrote about, i'll add a screenshot this way.

I wrote it down a bit but it still doesn't work)

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[])
  {
//---
    int limit=rates_total-prev_calculated-
1 ;
   if(limit<1) return(0);
   for(int i=limit;i>=0;i--)
     {
     
      // Снимем показания индикатора
     double in1b = iCustom(NULL,0,"in1",1,1); // индикатор 1 стрелка вверх
     double in1s = iCustom(NULL,0,"in1",0,1); // индикатор 1 стрелка вниз
     
     double in2b = iCustom(NULL,0,"in2",0,0); // индикатор 2 стрелка вверх
     double in2s = iCustom(NULL,0,"in2",1,0); // индикатор 2 стрелка вниз
      Comment("in1b = "+in1b+"\n""in1s = "+in1s);
     if (in1b<999999 && in1s>999999)
           Sell[i]=low[i];
     if (in1s<999999 && in1b>999999)
            Buy[i]=high[i];
             
   
     }
     
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Files:
 
jarikn:

I don't have the add screenshot button you wrote about, I'll add a screenshot this way.

I've done it a little bit but it still doesn't work)

Run your indicator on a clean chart, open the data window and take a screenshot
 
For example, here are 2 indicators. When an arrow and a point appear on one candle we need a buy signal and vice versa
Files:
in1.ex4  11 kb
in2.ex4  3 kb