[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 227

 

Dear fellow professionals, I need your help (pli-is). I want to make a function in my EA that displays a notification in the back corner of the screen about the current trend on different timeframes and the upcoming reversal. I am using my LinearRegression and Diverg functions for this purpose. However, I have never worked with theComment function and therefore cannot understand where I made a mistake. Anyway, the code below only displays the "Trend W = Down" message but I want it to show information for all other TFs as well.

void UPDN ()
{
if(LinearRegression(Symbol( ), LR_TFr_1, 0, Diver_Per_H1, 0) < 0) Comment("Trend H1 = Up");
if(Diverg(LR_TFr_1,0,Diver_Per_H1)<0) Comment("...!Pivot on H1 = Down");
if(LinearRegression(Symbol( ), LR_TFr_2, 0, Diver_Per_H4, 0) < 0) Comment("Trend H4 = Up");
if(Diverg(LR_TFr_2,0,Diver_Per_H4)<0) Comment("...!Pivot on H4 = Down");
if(LinearRegression(Symbol( ), LR_TFr_3, 0, Diver_Per_D1, 0) < 0) Comment("Trend D1 = Up");
if(Diverg(LR_TFr_3,0,Diver_Per_D1)<0) Comment("..!Pivot on D1 = Down");
if(LinearRegression(Symbol( ), LR_TFr_4, 0, Diver_Per_W, 0) < 0) Comment("Trend W = Up");
if(Diverg(LR_TFr_4,0,Diver_Per_W)<0) Comment("...!Pivot to W = Down");

if(LinearRegression(Symbol( ), LR_TFr_1, 0, Diver_Per_H1, 0) > 0) Comment("Trend H1 = Down");
if(Diverg(LR_TFr_1,0,Diver_Per_H1)>0) Comment("...!Pivot on H1 = Up");
if(LinearRegression(Symbol( ), LR_TFr_2, 0, Diver_Per_H4, 0) > 0) Comment("Trend H4 = Down");
if(Diverg(LR_TFr_2,0,Diver_Per_H4)>0) Comment("...!Pivot on H4 = Up");
if(LinearRegression(Symbol( ), LR_TFr_3, 0, Diver_Per_D1, 0) > 0) Comment("Trend D1 = Down");
if(Diverg(LR_TFr_3,0,Diver_Per_D1)>0) Comment("...!Pivot on D1 = Up");
if(LinearRegression(Symbol( ), LR_TFr_4, 0, Diver_Per_W, 0) > 0) Comment("Trend W = Down");
if(Diverg(LR_TFr_4,0,Diver_Per_W)>0) Comment("....W = Up");
return(0);
}

 
Optim:

Dear colleagues-professionals, I need your help (pli-is). I want to make a function in my EA that displays a notification in the back corner of the screen about the current trend on different timeframes and the upcoming reversal. I am using my LinearRegression and Diverg functions for this purpose. However, I have never worked with the Comment function and therefore cannot understand where I made a mistake. Anyway, the code below displays only the "Trend W = Down" message but I want it to inform me about other TFs.

void UPDN ()
{
if(LinearRegression(Symbol( ), LR_TFr_1, 0, Diverg_Per_H1, 0) < 0) Comment("Trend H1 = Up")
if(Diverg(LR_TFr_1,0,Diver_Per_H1)<0) Comment("...!Turn at H1 = Down");
if(LinearRegression(Symbol( ), LR_TFr_2, 0, Diverg_Per_H4, 0) < 0) Comment("Trend H4 = Up")
if(Diverg(LR_TFr_2,0,Diver_Per_H4)<0) Comment("...!H4 trend reversal = Down")
if(LinearRegression(Symbol( ), LR_TFr_3, 0, Diver_Per_D1, 0) < 0) Comment("Trend D1 = Up")
if(Diverg(LR_TFr_3,0,Diver_Per_D1)<0) Comment("...!Pivot on D1 = Down");
if(LinearRegression(Symbol( ), LR_TFr_4, 0, Diver_Per_W, 0) < 0) Comment("Trend W = Up");
if(Diverg(LR_TFr_4,0,Diver_Per_W)<0) Comment(";)

if(LinearRegression(Symbol( ), LR_TFr_1, 0, Diverg_Per_H1, 0) > 0) Comment("Trend H1 = Down")
if(Diverg(LR_TFr_1,0,Diver_Per_H1)>0) Comment("...!H1 trend reversal = Up");
if(LinearRegression(Symbol( ), LR_TFr_2, 0, Diver_Per_H4, 0) > 0) Comment("Trend H4 = Down")
if(Diverg(LR_TFr_2,0,Diver_Per_H4)>0) Comment("...!H4 trend reversal = Up");
if(LinearRegression(Symbol( ), LR_TFr_3, 0, Diver_Per_D1, 0) > 0) Comment("Trend D1 = Down")
if(Diverg(LR_TFr_3,0,Diver_Per_D1)>0) Comment("...!Pivot on D1 = Up");
if(LinearRegression(Symbol( ), LR_TFr_4, 0, Diver_Per_W, 0) > 0) Comment("Trend W = Down");
if(Diverg(LR_TFr_4,0,Diver_Per_W)>0) Comment("...!Diverg to W = Up")
return(0);
}


voidComment(...)
The function outputs a user-defined comment to the upper left corner of the graph. Parameters can be of any type. The number of parameters can not exceed 64.

Arrays cannot be passed to Comment(). Arrays must be printed element by element.

Data of double type is output with 4 decimal digits after the point. To print numbers with higher precision, use theDoubleToStr() function.
The bool, datetime and colour types will be printed as numbers.
To output datetime data as a string, use theTimeToStr() function.

To split the output into multiple lines, you may use line feed character "\n" or "\r\n".
See alsoAlert() andPrint().
Parameters:
...-Any values, separated by commas.
Example:
 double free=AccountFreeMargin(); Comment("Account free margin is ",DoubleToStr(free,2),"\n", "Current time is ",TimeToStr(TimeCurrent());
 
At least read the documentation before asking questions. Half the answers are already there
 

Thank you, I got it. I need to enter variables according to the results of LinearRegression and Diverg functions for each TF and then output them with one comment, can be in several lines.

 
Optim:

Thank you, I got it. I need to enter variables according to the results of LinearRegression and Diverg functions for each TF and then output them with one comment, can be in several lines.


There is only a limitation in terms of line length. You can use the function of Alexander Pak. If you can't find it, I'll look for it myself
 

Dear Sirs!

I have a question about passing an array by reference.

The algorithm scheme is as follows:

We pass an array by reference from one library to another.

We copy it there using the built-in function:

ArrayCopy.

Next, the array passed by reference is used

in the first module.

But for some reason, an error occurs, and not always.

I.e. sometimes the array is copied, sometimes it's not.

What's the reason?

The log entry is as follows:

21:07:12 openHistory CADCHF,H1:

2 arrays ranges for ArrayCopy function (0 and 4)

Connecting the module

Copy

 
Roger:
That's because you copied my example wrong. Look carefully where is the i and where is the k.

Corrected the code according to yours.
When testing, four orders closed in the order they were set on the first tick, the fifth closed on the next tick. Probably something else is wrong here as I have tested it many times.
I am pasting the program code and logs of the tester.
Sincerely. Shurkin

Код программы.
//+------------------------------------------------------------------+
//|                                                     Poligon1.mq4 |
//|                                            21 февраля 2013 года. |
//|Тестирование оператора цикла for.                                 |
//+------------------------------------------------------------------+
#property copyright "21 февраля 2013 года."
#property link      ""
//+------------------------------------------------------------------+
//|Объявленные переменные                                            |
//+------------------------------------------------------------------+
int Mn=357;//Magic number
int i;//Показатель счётчика итераций
double PriTP;//TP серии
int Tick;//Счётчик тиков
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----Установка серии ордеров
OrderSend(Symbol(),OP_BUY,0.5,Ask,0,NormalizeDouble(Bid-35*Point,Digits),
NormalizeDouble(Ask+35*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,1,Ask,0,NormalizeDouble(Bid-25*Point,Digits),
NormalizeDouble(Ask+25*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,1.5,Ask,0,NormalizeDouble(Bid-15*Point,Digits),
NormalizeDouble(Ask+15*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,2.5,Ask,0,NormalizeDouble(Bid-15*Point,Digits),
NormalizeDouble(Ask+15*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUY,3.5,Ask,0,NormalizeDouble(Bid-15*Point,Digits),
NormalizeDouble(Ask+15*Point,Digits),NULL,Mn,0,CLR_NONE);//OP_BUY
OrderSend(Symbol(),OP_BUYLIMIT,1,NormalizeDouble(Ask-15*Point,Digits),0,
NormalizeDouble(Bid-40*Point,Digits),NormalizeDouble(Ask+25*Point,Digits),
NULL,Mn,0,CLR_NONE);//OP_BUYLIMIT
OrderSend(Symbol(),OP_SELLSTOP,3,NormalizeDouble(Ask-30*Point,Digits),0,
NormalizeDouble(Bid+15*Point,Digits),NormalizeDouble(Ask-75*Point,Digits),
NULL,Mn,0,CLR_NONE);//OP_SELLSTOP
//----
   PriTP=Bid;//PriTP
   Print("Кс0:"," OrdersTotal=",OrdersTotal());//Сообщение
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   Tick++;//Tick
//   Print("Кс0:"," Tick=",Tick);//Сообщение
//----
//   for(i=0;i<OrdersTotal();i++)//Инициализация цикла
//   for(i=OrdersTotal()-1; i>=0; i--)//
   for(i=0, int k=0; i<OrdersTotal();i++,k++)//
   {
   Print("Кс1:"," Tick=",Tick," i=",i," k=",k);//Сообщение
   if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES)==true)//Выбор ордера k
    {
   if(OrderSymbol()==Symbol())//Символ
     {
   if(OrderMagicNumber()==Mn)//Идентификационное число
      {
   if(OrderType()==OP_BUY && OrderTakeProfit()>PriTP)//Тип операции текущего выбранного ордера
       {
   OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE);//Закрытие позиции
   k--;//?
       }//Закрыто if(OrderType()==OP_BUY && OrderTakeProfit()>PriTP)
      }//Закрыто if(OrderMagicNumber()==Mn)
     }//Закрыто if(OrderSymbol()==Symbol()
    }//Закрыто if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
   }//Закрыто for(i=0, int k=0; i<OrdersTotal();i++,k++)
/*   
   for(i=0, int k=0; i<OrdersTotal();i++,k++)//
   {
   Print("Кс1:"," Tick=",Tick," i=",i," k=",k);//Сообщение
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)//Выбор ордера i
    {
   if(OrderSymbol()==Symbol())//Символ
     {
   if(OrderMagicNumber()==Mn)//Идентификационное число
      {
   if(OrderType()==OP_BUY && OrderTakeProfit()>PriTP)//Тип операции текущего выбранного ордера
       {
   OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE);//Закрытие позиции
   k--;//Зачем сначала прибавлять и тут же убавлять ???
       }//Закрыто if(OrderType()==OP_BUY && OrderTakeProfit()>PriTP)
      }//Закрыто if(OrderMagicNumber()==Mn)
     }//Закрыто if(OrderSymbol()==Symbol()
    }//Закрыто if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
   }//Закрыто for(i=0;i<OrdersTotal();i++)
*/   
//----
   return(0);
  }
//+------------------------------------------------------------------+
Записи в журнале тестера.
2013.03.18 13:58:21     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=4 i=1 k=1
2013.03.18 13:58:21     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=4 i=0 k=0
2013.03.18 13:57:57     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=3 i=1 k=1
2013.03.18 13:57:57     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=3 i=0 k=0
2013.03.18 13:57:33     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=2 i=1 k=0
2013.03.18 13:57:33     2013.02.11 12:15  Poligon1 EURUSD,M15: close #5 buy 3.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 at price 1.3394
2013.03.18 13:57:33     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=2 i=0 k=0
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: close #4 buy 2.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 at price 1.3395
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=1 i=3 k=0
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: close #3 buy 1.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 at price 1.3395
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=1 i=2 k=0
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: close #2 buy 1.00 EURUSD at 1.3397 sl: 1.3370 tp: 1.3422 at price 1.3395
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=1 i=1 k=0
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: close #1 buy 0.50 EURUSD at 1.3397 sl: 1.3360 tp: 1.3432 at price 1.3395
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ1: Tick=1 i=0 k=0
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: Êñ0: OrdersTotal=7
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: open #7 sell stop 3.00 EURUSD at 1.3367 sl: 1.3410 tp: 1.3322 ok
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: open #6 buy limit 1.00 EURUSD at 1.3382 sl: 1.3355 tp: 1.3422 ok
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: open #5 buy 3.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 ok
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: open #4 buy 2.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 ok
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: open #3 buy 1.50 EURUSD at 1.3397 sl: 1.3380 tp: 1.3412 ok
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: open #2 buy 1.00 EURUSD at 1.3397 sl: 1.3370 tp: 1.3422 ok
2013.03.18 13:57:09     2013.02.11 12:15  Poligon1 EURUSD,M15: open #1 buy 0.50 EURUSD at 1.3397 sl: 1.3360 tp: 1.3432 ok
2013.03.18 13:57:09     Poligon1 test started
2013.03.18 13:57:02     Poligon1 EURUSD,M15: loaded successfully
 
Where is the best place to declare a variable type (int, double, etc.) in terms of reducing the resource consumption of program execution. For example, int i can be declared globally or in int start() ... for (int i=OrdersTotal()-1; i>=0; i--) ... I have a feeling that declaring it on every tick is more costly than declaring it once at global level, right after extern parameters. Or is the difference in resource-intensiveness the same?
 
Zhunko:
You have to loop the start. Work inside the loop. You can do anything there.

This is a little different. when the connection is lost, the log says "Ping failed". it means there are fi ries, but they are not documented for some reason.
How much of the load on the CPU and memory is increased by looping?

 
Dimka-novitsek:

Good evening! Excuse me, I would like to return to an unsolved problem.

'Buy' - incompatible types D:\TeleTRADE\experts/experts/clean.mq4 (102, 53)

'Sell' - incompatible types D:\TeleTRADE\experts\clearlist.mq4 (102, 79)


if (!Pishem&&PozyProstavleny){SaveArray(FileBuy, Buy); SaveArray(FileSell, Sell); Pishem=1;}

This line does not compile.
Reason: