Creating a robot - page 5

 

Added two more buttons - for setting Horizontal Lines.

-------------------------------------------------


Files:
ioia3x_0004.PNG  96 kb
0004.mq5  44 kb
 

Added commands for Horizontal or Trend lines

//+------------------------------------------------------------------+
//|                                                         0005.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#define    InpMagic  182979245
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
//---
CPositionInfo  m_position; // trade position object
CTrade         m_trade;    // trading object
CSymbolInfo    m_symbol;   // symbol info object
//+------------------------------------------------------------------+
//| ENUM_TRADE_COMMAND                                               |
//+------------------------------------------------------------------+
enum ENUM_TRADE_COMMAND
  {
   Turn_Off=0,       // TURN  OFF
   UpName=1,         // Line UpName
   DownName=2,       // Line DownName
   UpName_s=3,       // Line UpName + Open Sell
   UpName_b=4,       // Line UpName + Open Buy
   DownName_b=5,     // Line DownName + Open Buy
   DownName_s=6,     // Line DownName + Open Sell
   close_buys=7,     // Close All Buy's
   close_sells=8,    // Close All Sell's
   close_all=9,      // Close All Buy's and Sell's
   open_buy=10,      // Open  Buy
   open_sell=11,     // Open  Sell
   close_open_b=12,  // Close Sell + Open Buy
   close_open_s=13,  // Close Buy + Open Sell
   open_buy_sell=14, // Open  Buy and Sell
  };
//+------------------------------------------------------------------+
input string   t="----- Lots                -----";              //
input double   InpLots                      = 0.01;              // Lots
input string   t0="---- Line Name           -----";              //
input string   InpObjUpName                 = "Имя Линии Up";    // Obj: Up (Trailing Horizontal Line) or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommand    = UpName_s;          // Obj:  command: UP
input string   InpObjDownName               = "Имя Линии Down";  // Obj: Down (Trailing Horizontal Line) or Trend Line)
input ENUM_TRADE_COMMAND InTradeCommand     = DownName_b;        // Obj:  command: DOWN
input ushort   InpObjStep                   = 15;                // Obj: Step (distance from price to object, in pips)
input string   t1="---- Indicators: UP      -----";              //
input bool     InpIndicatorsUp              = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY1  = open_buy;          // Trade command: ( Buy )
input ENUM_TRADE_COMMAND InpTradeCommandU1  = open_sell;         // Trade command: ( Sell )
input string   t2="---- Indicators:         -----";              //
input bool     InpIndicators                = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY   = close_sells;       // Trade command: ( Buy )
input ENUM_TRADE_COMMAND InpTradeCommandU   = close_buys;        // Trade command: ( Sell )
//---
double   m_adjusted_point;                // point value adjusted for 3 or 5 points
int      handle_iCustomUp;                // variable for storing the handle of the iStochastic indicator
int      handle_iCustom;                  // variable for storing the handle of the iStochastic indicator
datetime ExtPrevBarsUp           = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtPrevBars             = 0;     // "0" -> D'1970.01.01 00:00';
double   m_obj_step              = 0.0;   // Obj: Trailing Stop   -> double
uint     SLEEPTIME               = 1;     // Время паузы между повторами в секундах
ushort   InpSignalsFrequency     = 1;     // Search signals, in seconds (min value "1")
datetime ExtLastSignalsRx        = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtPrevBarsRx           = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtLastSignalsSx        = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtPrevBarsSx           = 0;     // "0" -> D'1970.01.01 00:00';
bool     ExtTurnOff              = false; //
bool     ExtUpName               = false; //
bool     ExtDownName             = false; //
bool     ExtNeedCloseBuy         = false; //
bool     ExtNeedCloseSell        = false; //
bool     ExtNeedCloseAll         = false; //
bool     ExtNeedOpenBuy          = false; //
bool     ExtNeedOpenSell         = false; //
bool     ExtNeedOpenBuySell      = false; //
//+------------------------------------------------------------------+
Files:
0005.mq5  101 kb
 
SanAlex:

Added commands for Horizontal or Trend lines

Have a nice day and good mood everyone!

What did Roman ask for? Here's a quote from his first post: "Completely program, to open a trade when it starts and please explain what's what. Help out a lot."

Just add codes without explaining what they are for is useless!

Roman, your solution to this situation is exactly the same as mine. Take any simple Expert Advisor from CodeBase, well, at least this one https://www.mql5.com/ru/code/138

Open its code in MetaEditor and begin to study the comments that are in each line of the code. There are EAs where all comments are written in English. If you do not know the language well, Google Translator will help you. If in any Expert Advisor, the commentary to the lines is missing, then sequentially search all colored words in the program code, set the cursor on them, press the F1 key and the appropriate sections of the MQL5 manual will open for you. Read these sections, comment on these lines in your own words, and if something is not clear, then ask questions here. This way, you will move faster in learning the programming language.

Regards, Vladimir.

Советник "Метод Пуриа"
Советник "Метод Пуриа"
  • www.mql5.com
Предлагается использовать следующие валютные пары в торговой стратегии форекс "Метод Пуриа" : AUDJPY - M30 - 15 пунктов (т.е. закрываем сделку при 15 пипсов тейк-профита) NZDUSD - 1H - 25 пунктов USDCAD - H1 - 20 пунктов EURGBP - H1 - 10 пунктов USDJPY - M30 - 15 пунктов GBPUSD - М30 - 20 пунктов USDCHF - M30 - 10 пунктов EURCHF - H1 - 15...
 
MrBrooklin:

Good day and good mood everyone!

What did Roman ask for? Here's a quote from his first post: "Completely program, on opening a trade when it starts and please explain what's what. Help out a lot."

Simply adding codes without explanation is useless for him!

Roman, your solution in this situation is exactly the same as mine. Take any simple Expert Advisor from CodeBase, well, at least this one https://www.mql5.com/ru/code/138

Open its code in MetaEditor and begin to study the comments that are in each line of the code. There are EAs where all comments are written in English. If you do not know the language well, Google Translator will help you. If in any Expert Advisor, the commentary to the lines is missing, then sequentially search all colored words in the program code, set the cursor on them, press the F1 key and the appropriate sections of the MQL5 manual will open for you. Read these sections, comment on these lines in your own words, and if something is not clear, then ask questions here. This way, you will move faster in learning the programming language.

Regards, Vladimir.

I do not understand - is it better to delete what I cheated? - That he himself, how to learn?

 
SanAlex:

I don't get it - is it better to delete what I did? - so he can learn on his own?

Not delete, but explain what is written in the codes and why it is done!

Sincerely, Vladimir.

 
MrBrooklin:

Not delete, but explain what is written in the codes and why it is done!

Respectfully, Vladimir.

I'm self-taught myself - and I copy from the available codes myself, - The problem is that I don't know how to explain how to sculpt!? - something inside tells me how to sculpt.

----------------------------------

I know what I've moulded, what's missing there is a Thrall for the line.

 
SanAlex:

I am self-taught myself - and I copy from the available codes myself, - The problem is that I don't know how to explain how to sculpt!? - something inside tells me how to sculpt.

That's exactly the problem! When I started studying the MQL5 language, I read a lot of articles on creating Expert Advisors. STARTING I haven't found it yet. Of course, there are some articles with links to Roman, but they are not enough, at least for me.

I myself, for example, see a lot of EA codes, but no way to understand why this or that line was written. So far, I have had enough brains to rewrite the code for myself using one of the ready-made Expert Advisors.

Regards, Vladimir.

 
MrBrooklin:

That's the problem! I have read a lot of articles on creation of Expert Advisors when I started studying the MQL5 language. BEGINNERS I haven't found it yet. Of course, there are some articles with links to Roman, but they are not enough, at least for me.

For instance, I see a lot of Expert Advisor codes myself, but I cannot understand why this or that line was written. So far, I've had enough brains to rewrite the code for myself from one ready-made Expert Advisor.

Sincerely, Vladimir.

I'm looking for functions for my tasks - I take a function apart as I start to understand how it works, then everything is easier to learn.

 
SanAlex:

I look for functions for my tasks - I take the function apart as I begin to understand how it works, then everything is easier to learn.

Here is a live example of one problem that I have been struggling with for over an hour. I need it to create and display ZigZagColor indicator on the chart at the start of the EA. It was done in int OnInit:

   handle_iCustom=iCustom(m_symbol.Name(),Period(),"Examples\\ZigzagColor",
                          Inp_ZZ_Depth,
                          Inp_ZZ_Deviation,
                          Inp_ZZ_Backstep);
   ChartIndicatorAdd(ChartID(),0,handle_iCustom);

The indicator was created and displayed. Now I need the indicator to be deleted after the Expert Advisor is removed. I am writing it:

void OnDeinit(const int reason)
  {
//---
   IndicatorRelease(handle_iCustom);
   ObjectsDeleteAll(0,"Examples\\ZigzagColor");
  }

But the indicator is not removed. I have sorted everything out. I have cleaned the handle and applied the delete function. I wonder what is the reason why it is not uninstalling.

Regards, Vladimir.

 
MrBrooklin:

Here is a live example of one problem that I've been struggling with for over an hour. I wanted the ZigZagColor indicator to be created and displayed on the chart when starting the EA. It was done in int OnInit:

The indicator was created and displayed. Now I need the indicator to be deleted after the Expert Advisor is removed. I am writing it:

But the indicator is not removed. I have sorted everything out. I have cleaned the handle and applied the delete function. I wonder what is the reason why it is not uninstalling.

Regards, Vladimir.

There is a more complicated function for deleting

input string   t12="--- Indicator Delete    -----";              //
input string   Inpshort_name                = "Имя Индикатора";  // Delete Indicator Name
input string   Inpshort_name_1              = "Имя Индикатора";  // Delete Indicator Name
input bool     Inpres                       = false;             // Delete All Indicators
//+------------------------------------------------------------------+
//| ChartIndicatorDelete                                             |
//+------------------------------------------------------------------+
bool IndicatorDelete(void)
  {
     {ActionsOnTheChart(0);}
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ActionsOnTheChart(const long chart_id)
  {
   int sub_windows_total =-1;
   int indicators_total  =0;
//---
   if(!ChartWindowsTotal(chart_id,sub_windows_total))
     {
      return(false);
     }
//---
   for(int i=sub_windows_total-1; i>=0; i--)
     {
      indicators_total=ChartIndicatorsTotal(chart_id,i);
      //---
      if(indicators_total>0)
        {
         ChIndicatorsDelete(chart_id,i,indicators_total);
        }
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChartWindowsTotal(const long chart_ID,int &sub_windows_total)
  {
   long value=-1;
//---
   if(!ChartGetInteger(chart_ID,CHART_WINDOWS_TOTAL,0,value))
     {Print(__FUNCTION__," Error = ",GetLastError()); return(false);}
//---
   sub_windows_total=(int)value;
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChIndicatorsDelete(const long  chart_id,
                        const int   sub_window,
                        const int   indicators_total)
  {
   for(int i=indicators_total-1; i>=0; i--)
     {
      string indicator_name=ChartIndicatorName(chart_id,sub_window,i);
      //---
      ChIndicatorDelete(indicator_name,chart_id,sub_window);
      ChartRedraw();
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChIndicatorDelete(const string shortname,
                       const long   chartid=0,
                       const int    subwindow=0)
  {
   bool res=ChartIndicatorDelete(chartid,subwindow,Inpshort_name);
   bool res2=ChartIndicatorDelete(chartid,subwindow,Inpshort_name_1);
   if(Inpres)
      bool res0=ChartIndicatorDelete(chartid,subwindow,shortname);
//--- проанализируем результат вызова ChartIndicatorDelete()
   if(!res)
     {
      PrintFormat("%s",shortname,subwindow,GetLastError());
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+