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

 
novichok2018 #:

So, is it possible to specify in the code that the EA opens a position (or reflects it) not on the chart where it is set, but on the same symbol, but on a different chart? Or it is not possible in principle?

Any request for account or trade status goes to the grid, where there are no conditions and no timeframes. The answer to your question: This is not possible.

 
novichok2018 #:

So, is it possible to specify in the code that the EA opens a position (or reflects it) not on the chart where it is set, but on the same symbol, but on a different chart? Or it is not possible in principle?

You want EA #2 to see all positions opened by EA #1, right?

Well, that's easy.

 
Alekseu Fedotov #:

You want EA #2 (let's say) to see all the positions opened by EA #1, right?

Well, that's easy.

He wants the monitor to not see anywhere that he interferes with EA trading.

 

Alexey Viktorov #:

  HideTestIndicators(true); 
   MaCurrent=iMA(NULL,0,56,0,MODE_EMA,PRICE_CLOSE,0); 
   MaPrevious=iMA(NULL,0,56,0,MODE_EMA,PRICE_CLOSE,1); 
   HideTestIndicators(false);



Thanks for the previous reply, but now another problem. When testing for over a year the memory runs out. The tester writes "Channel_1" : out of memory. Also, "Channel_1" : not initialized. These messages appear after testing for a year or more on 3 computers. The indicator (Channel_1) is connected via a resource. Did not do any dynamic memory allocation via new. The whole problem appeared after the changes described in the previous post. I started to loop through the connected indicator and each time I change intu parameter (period) in it.

Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
  • 2022.02.05
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...
 
Aleksandr Kononov #:

Thanks for the previous reply, but now another problem. When testing for over a year the memory runs out. The tester writes "Channel_1" : out of memory. Also, "Channel_1" : not initialized. These messages appear after testing for a year or more on 3 computers. The indicator (Channel_1) is connected via a resource. Did not do any dynamic memory allocation via new. The whole problem appeared after the changes described in the previous post. I started to loop through the indicator and every time I change its intu parameter (period).

Maybe that's the problem? Try periodically deleting the resource

bool  ResourceFree( 
   const string  resource_name      // имя ресурса 
   );

But then you have to create it dynamically.

bool  ResourceCreate( 
   const string      resource_name,       // имя ресурса 
   const string      path                 // относительный путь к файлу 
   );

That is, first delete the resource, then re-create it. The only problem is that I don't know how it will work. Or if it will work at all. We'll have to try...

 
Alekseu Fedotov #:

You want EA #2 (let's say) to see all the positions opened by EA #1, right?

Well, that's easy.

Yes, exactly: that EA #2, would see all positions opened by EA #1. Only if it were easy for me, I would not ask for help.

So far, I see the following solution: to write an indicator that creates an object "point" with coordinates of position opening by EA #1 and place it on a chart with EA #2 installed.

If my logic is correct, I still need help writing this indicator.

 

Good afternoon. I have added everything to the script as suggested - code of the script to translate the graphs to d1 and the midterm template below.

//+------------------------------------------------------------------+
//|                                               D1_AND_SHABLON.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright " КОПИЯ 1 "
#property link      "https://vk.com/danila_mastep"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
string tplName = "FIBOmAGIC СРЕДНЕСРОК";
void OnStart()
 {
  long prevChart = ChartFirst();
  while(prevChart >= 0 && IsStopped())
   {
    if(ChartPeriod(prevChart) != PERIOD_D1)
      ChartSetSymbolPeriod(prevChart, ChartSymbol(prevChart), PERIOD_D1);
      ChartApplyTemplate(prevChart, tplName);
    prevChart = ChartNext(prevChart);
   }
 }/******************************************************************/
/*****************************End program****************************/

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

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


The terminal window with open charts in the screenshot below.

7 charts with scalping pattern

I have 7 open charts in the screenshot and all of them have the scalping pattern as well as AUD/USD. When I drag and drop the script D1_AND_SHABLON.mq4 nothing happens - what is the reason for this error? O_o

 
DanilaMactep #:

Good afternoon. I have added everything to the script as suggested - code of the script to transfer the graphs to d1 and the midterm template below.


The terminal window with open charts in the screenshot below.

I have 7 open charts in the screenshot and all of them have the scalping pattern as well as AUD/USD. When I drag and drop the script D1_AND_SHABLON.mq4 nothing happens - what is the reason for this error? O_o

The problem is that there are too many Expert Advisors and everyone has a different solution. Even if it is correct, it differs from others. But it is often completely wrong.

Sasha advised to put the template name without .tpl, but in my tip it is

This is the forum for trading, automated trading systems and strategy testing.

Any questions from newbies on MQL4 and MQL5, tips and discussion on algorithms and codes

Alexey Viktorov, 2022.02.17 08:29

You have only one more line in your code. Or even replace two lines with one.

string tplName = "name.tpl";
/********************Script program start function*******************/
void OnStart()
 {
  long prevChart = ChartFirst();
  while(prevChart >= 0)
   {
    //if(ChartPeriod(prevChart) != PERIOD_H1)
    //  ChartSetSymbolPeriod(prevChart, ChartSymbol(prevChart), PERIOD_H1);
    ChartApplyTemplate(prevChart, tplName);
    prevChart = ChartNext(prevChart);
   }
 }/******************************************************************/
/*****************************End program****************************/

You took some from there, some from there and you got a porridge... not even a pearl...
 
novichok2018 #:

Yes, exactly: that EA #2, would see all open positions by EA #1. Only if it were easy for me, I would not ask for help.

So far, I see the following solution: write an indicator that would create a "point" object with coordinates of position opening by EA #1 and place it on a chart with EA #2 installed.

If my logic is correct, I still need help writing this indicator.

He sees them
 
novichok2018 #:

Yes, exactly: that EA #2, would see all open positions by EA #1. Only if it were easy for me, I would not ask for help.

So far, I see the following solution: write an indicator that would create a "point" object with coordinates of position opening by EA #1 and place it on a chart with EA #2 installed.

If my logic is correct, then I still need help in writing this indicator.

It is not quite clear whether you need to see the position opened by EA #1

or EA #2?

Here, below is the code of EA that sees open positions opened by EA #1,

You just need to put it in EA#1's magic properties.

//+------------------------------------------------------------------+
//|                                                  советник №2.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input int  Magic = 0;  //

datetime OOT;   //время последней открытой позиции.
double  OOP;    //цена последней открытой позиции.

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   GetPos(Symbol(),Magic);

   Comment("время последней открытой позиции =",TimeToString(OOT),
           "\nцена последней открытой позиции = ",DoubleToString(OOP,_Digits));

  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void GetPos(string sy,int mn)
  {

   int      i,k=OrdersTotal();

   for(i=0; i<k; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderMagicNumber()==mn && OrderSymbol()==sy)
           {
            if(OOT<OrderOpenTime())
              {
               OOT = OrderOpenTime();
               OOP = OrderOpenPrice();
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+

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

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

And it displays the coordinates of the last open position in the somment.

Reason: