[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 645

 
artmedia70:

There's hardly any logic to it - the simple output of lines in order one after the other...




I would use functions to make it easy to understand

//--------------------------------------------------------------- 1 --
// Функция вывода на экран графических сообщений.
//--------------------------------------------------------------- 2 --
  int Informations()
  {
   int   Win_ind;                     // Номер окна индикатора
   int   x,y;
   
   trH4     =Trend_PSAR(NULL,240);  // Четырёхчасовой тренд
   trH1     =Trend_PSAR(NULL,60);   // Часовой тренд
   trM30    =Trend_PSAR(NULL,30);   // Получасовой тренд
   trM15    =Trend_PSAR(NULL,15);   // 15-ти минутный тренд

//--------------------------------------------------------------- 3 --
   Win_ind= WindowFind("Info");        // Ищем номер окна индикатора
   if (Win_ind<0)return;               // Если такого окна нет, уходим
//--------------------------------------------------------------- 4 --
   x =10; y =17;
   MyObject("Equ",         x,    y,   "Свободные средства",                   9, "Tahoma", Gold);
   MyObject("EquVal",      x*23, y,   DoubleToStr(Equ_NEW,2),                 9, "Tahoma", Yellow);

//.................................
   WindowRedraw();                      // Перерисовываем все объекты
   return;
  }


void MyObject(string Name, int X, int Y, string Text, int Size, string Srift, color CL){
   if (ObjectFind(Name)==-1)
      ObjectCreate(Name,OBJ_LABEL,1,0,0,0,0);
   ObjectSet(Name,OBJPROP_XDISTANCE,X);
   ObjectSet(Name,OBJPROP_YDISTANCE,Y);
   ObjectSetText(Name, Text, Size, Srift, CL);
}
 
ToLik_SRGV:

I also wondered about it, but did not find anything useful. When it comes to optimization, you already know about the great brake of iCustom :), in indicators there is a restriction on the number of bars, that can be calculated (through IndicatorCounted() or by the number of bars). In the code, there is no sense to bother with the number and complexity of different constructions like if, while, etc. You won't gain much, but with time and experience, the code will become more "beautiful". Well, in visualization mode, when every "bounce" is modeled, it will be slow almost in any case (depending on complexity of the system, of course). Somewhere I read that if complex calculations in a dll, it will be faster, but I have not checked it. With dll, also enough nuances.

I remember that commands like TimeCurrent() slowed down much (when there are several of them in the code).

- It's much better to use it once - put it into a variable, and then access the variable.

 
Vinin:


I would use the functions for easy perception

Yes, of course, Victor, it's much more readable. But I'm already trying, where possible, to write "head-on" - it's very slow, and where possible, I'm trying to save milliseconds...
 
chief2000:

I remember commands like TimeCurrent() being very slow (when there are several of them in the code)

- It's much better to use it once - put it into a variable, and then access the variable.

Great! It's worth looking through the code and redoing it...
 
chief2000:

I remember commands like TimeCurrent() being very slow (when there are several of them in the code)

- It's much better to use it once, i.e. store it in a variable and then access the variable.

How do I correctly set such a variable so that it can be called later?

I declare it in global variables first

datetime CurTime;

And then in start()

I assign a value to it:

CurTime=TimeCurrent();

and I get an error: 'CurTime' - variable expected.

How to do it correctly?

And another question: if I assign values to some variables not in start() but in init(), will they work correctly?

Well, I mean, that some functions, e.g. TimeCurrent(), will still be called on every tick, if a variable is assigned to this function at the beginning of start()

 
Bummer! CurTime gives an error, CurrTime does not... What's the problem?
 
artmedia70:
Bummer! CurTime gives an error and CurrTime does not... What's the point?
The point is that CurTime is the obsolete name of the TimeCurrent function, so the compiler always complains when a variable name coincides with a function name...
 
keekkenen:
The point is that CurTime is the obsolete name of the TimeCurrent function, so when a variable name matches a function name, the compiler always frowns...
Well! Thank you, I will know it in future.
 

Friends, my personal logic block is a bit on the fritz. I can not decide how to be in this situation:

We work in two directions, i.e. Buy and Sell have their own separate control units. Positions may be opened counter-directionally, it all depends on which way the market moves in each TF.

Suppose the situation when Sell and Buy are open (on M5 and M15) and suddenly the market turns in the opposite direction, opposite to the open Sell on M5 and M15 (well, whatever the situation is in the world...). In this case, all of the open Sells begin to greatly increase the drawdown, and since we have also open Buy, it is possible to close some positions in both Buy and Sell, to close loss-making sells with minimal losses at the expense of closed Buy.

So, I cannot decide on the logic of this situation. What it should be?

Just in case, here is an example:


 

Good people, getting back to yesterday's topic:

   double c1b[];
   for(i=1;i<=PeriodB;i++)
   {
   c1b[i]=iCCI(NULL,0,PeriodB,PRICE_TYPICAL,i);
   }
   double c1b_1=iMAOnArray(c1b,0,AvgB,0,MODE_SMA,1);
   double c1b_2=iMAOnArray(c1b,0,AvgB,0,MODE_SMA,2);
   double c1b_3=iMAOnArray(c1b,0,AvgB,0,MODE_SMA,3);
   
   double c1s[];
   for(i=1;i<=PeriodS;i++)
   {
   c1s[i]=iCCI(NULL,0,PeriodS,PRICE_TYPICAL,i);
   }
   double c1s_1=iMAOnArray(c1s,0,AvgS,0,MODE_SMA,1);
   double c1s_2=iMAOnArray(c1s,0,AvgS,0,MODE_SMA,2);
   double c1s_3=iMAOnArray(c1s,0,AvgS,0,MODE_SMA,3);

if (NormalizeDouble(c1s_1,4)>NormalizeDouble(c1s_2,4)&&NormalizeDouble(c1s_2,4)<NormalizeDouble(c1s_3,4))
//if (c1s_1>c1s_2&&c1s_2<c1s_3)
     {                                          // 
      Opn_B=true;                               // Критерий откр. Buy
      Cls_S=true;                               // Критерий закр. Sell
     }
if (NormalizeDouble(c1b_1,4)<NormalizeDouble(c1b_2,4)&&NormalizeDouble(c1b_2,4)>NormalizeDouble(c1b_3,4))
//if (c1b_1<c1b_2&&c1b_2>c1b_3)
     {                                          // 
      Opn_S=true;                               // Критерий откр. Sell
      Cls_B=true;                               // Критерий закр. Buy
     }

please tell me what the message from the logbook means:

2010.06.24 17:28:26 TestGenerator: unmatched data error (volume limit 5357 at 2010.01.06 08:00 exceeded)

Reason: