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

 
de_leonid:

Thank you for your help. Can I also ask for an example of EA (part of the code) on how to get value from these lines in EA.

I made an Expert Advisor for myself https://www.mql5.com/ru/code/34046- which can perform operations on horizontal or trend lines

You need to know the name of horizontal lines fromTymen_STARC_Bands_MTF

here are their names

string   m_r2_name      = "Highest";
string   m_r1_name      = "Top";
string   m_0_name       = "Middle";
string   m_s1_name      = "Bottom";
string   m_s2_name      = "Lowest";

and enter them into the Expert Advisor and set the command

here

sinput group "----------------- Trade Line UP ------------------------"
sinput ENUM_MODE          FilterLine_13              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Up               = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedUp         = open_buy;         // Trade command:
sinput string             InpNameAverageUp           = "Line Up";        // Line Name UP(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedUpLow      = open_sell;        // Trade command:
sinput bool               InpDelLineUp               = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeUp          = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrUp         = clrBlue;          // EA only monitors this lines color
sinput group "----------------- Trade Line_2 UP ----------------------"
sinput ENUM_MODE          FilterLine_15              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Up_2             = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedUp_2       = open_buy;         // Trade command:
sinput string             InpNameAverageUp_2         = "Line_2 Up";      // Line Name UP(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedUpLow_2    = open_sell;        // Trade command:
sinput bool               InpDelLineUp_2             = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeUp_2        = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrUp_2       = clrBlue;          // EA only monitors this lines color
sinput group "----------------- Trade Line DOWN ----------------------"
sinput ENUM_MODE          FilterLine_14              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Down             = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedDown       = open_buy;         // Trade command:
sinput string             InpNameAverageDown         = "Line Down";      // Line Name DOWN(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedDownLow    = open_sell;        // Trade command:
sinput bool               InpDelLineDown             = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeDown        = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrDown       = clrRed;           // EA only monitors this lines color
sinput group "----------------- Trade Line_2 DOWN --------------------"
sinput ENUM_MODE          FilterLine_16              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Down_2           = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedDown_2     = open_buy;         // Trade command:
sinput string             InpNameAverageDown_2       = "Line_2 Down";    // Line Name DOWN(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedDownLow_2  = open_sell;        // Trade command:
sinput bool               InpDelLineDown_2           = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeDown_2      = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrDown_2     = clrRed;           // EA only monitors this lines color
Algorithm manually automate
Algorithm manually automate
  • www.mql5.com
Эксперт для Автоматизации Ручной торговли.
 
de_leonid:

Thank you for your help. Can I also ask for an EA example (part of the code) of how to get the value from these lines in EA.

the function itself in Expert Advisor from Horizontal or Trend line

Here -(marked in yellow - here the name of line is set )\\\\\\\\\\\\ for 1 minute test - manually put a horizontal or trend line, set the same name in Expert Advisor and in the line itself.

//+------------------------------------------------------------------+
//|                                                TrendOpenedUp.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
sinput string InpNameAverageUp = "Line Up"; // Line Name UP(Horizontal Line or Trend Line)
sinput bool   InpDelLineUp     = false;     // Delete (Horizontal Line or Trend Line)
//---
datetime ExtPrevBarsUp;    // "0" -> D'1970.01.01 00:00';
datetime ExtLastAverageUp; // "0" -> D'1970.01.01 00:00';
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   TrendOpenedUp();
  }
//+------------------------------------------------------------------+
//| Check for long position opening                                  |
//+------------------------------------------------------------------+
bool TrendOpenedUp(void)
  {
   bool res=false;
   datetime time_0=iTime(Symbol(),Period(),0);
   if(time_0==ExtPrevBarsUp)
      return(true);
   ExtPrevBarsUp=time_0;
     {
      if(ObjectFind(0,InpNameAverageUp)<0)
         return(true);
      MqlRates ratesAverage[];
      ArraySetAsSeries(ratesAverage,true);
      int start_pos=0,count=3;
      if(CopyRates(Symbol(),Period(),start_pos,count,ratesAverage)!=count)
         return(false);
      if(ratesAverage[0].time==ExtLastAverageUp)
         return(true);
      double price_line=0.0;
      long object_type=ObjectGetInteger(0,InpNameAverageUp,OBJPROP_TYPE);
      if(object_type==OBJ_HLINE)
         price_line=ObjectGetDouble(0,InpNameAverageUp,OBJPROP_PRICE);
      else
         if(object_type==OBJ_TREND)
            price_line=ObjectGetValueByTime(0,InpNameAverageUp,ratesAverage[1].time,0);
      double value_by_time=price_line;
      if(value_by_time==0.0)
         return(true);
      if(ratesAverage[1].open<value_by_time && ratesAverage[1].close>value_by_time)
        {
         PlaySound("request.wav");
         if(InpDelLineUp)
            ObjectsDeleteAll(0,InpNameAverageUp);
         res=true;
        }
      if(ratesAverage[1].open>value_by_time && ratesAverage[1].close<value_by_time)
        {
         PlaySound("tick.wav");
         if(InpDelLineUp)
            ObjectsDeleteAll(0,InpNameAverageUp);
         res=true;
        }
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
 
de_leonid:

Thank you for your help. Can I also ask for an EA example (part of the code) of how to get the value from these lines in EA.

the easiest and simplest way is to get the names of Horizontal or Trend lines from the Indicator.

- right-click on a chart and find LIST OF OBJECTS(copy and paste into Expert Advis or)

Photo by

 
Hi all !
I'm begging for help, I've already racked my brain, I can't find how to implement the following.
When opening a new bar, perform a calculation.
When opening a new bar again, perform the calculation and perform any actions.
I can't find it in MQL5
Please help!!!
 
m-r LSV:
Hi all !
I'm begging for help, I've already racked my brain, I can't find how to implement the following.
When opening a new bar, perform a calculation.
When opening a new bar again, perform the calculation and perform any actions.
I can't find it in MQL5
Please help!!!
If it is for an indicator, there is rates_total and prev_calculated. If it is for an EA, then the same as in mql4...
 
Alexey Viktorov:
If it's for indicator, there are rates_total and prev_calculated. If it's for Expert Advisor, it's the same as in mql4...

Can I have a short piece of code please, I'm a newbie and my head is already boiling. Confused.

 
Alexey Viktorov:
If it is for an indicator, there is rates_total and prev_calculated. If it is for an EA, then the same as in mql4...

Yes, it's for the indicator

 

Alexey Viktorov:
Если это для индикатора, то есть rates_total и prev_calculated. Если-же для советника, то так-же как и в mql4…


if(rates_total > prev_calculated)
 Print("Новый бар");

Am I reading this right?

 

The opening of the candle is delayed by 9-12 seconds.
Can you please tell me if this is the first tick?

It is just extremely important for me to make calculations, and perform any actions on the first tick of a new candle.

2021.06.02 16:42:09.522 Test (Volatility 10 Index,M1)      Новый бар
2021.06.02 16:43:09.621 Test (Volatility 10 Index,M1)      Новый бар
2021.06.02 16:44:09.552 Test (Volatility 10 Index,M1)      Новый бар

 
m-r LSV:

Am I reading this right?

datetime fin=0, last=0;

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[])
   {
   fin=iTime(symbol,frame,0);
   if(last==fin) return(rates_total);
   last=fin;