[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 370

 
TarasBY:

Regarding this line:

Recently, DTs often add different prefixes to the symbol name (EURUSDm - for example) - these should be taken into account when referring to the market environment of the symbol.

P.S. ...And for the standard "EURUSD" StringSubstr ("EURUSD", 6) will be not zero but "".

Thank you very much, Igor! I did not know about DTs and the letter. It may be a mini-account for the "m".

Do you know where the JPY has the coefficient 82 ? For other currencies it was 0.625 for GBP, 0.7751937984 for EUR

The idea is that when you translate currencies the coefficient would be floating as the exchange rates change. Why then take constants?
 
Chiripaha:

Nikolai, it is very good that you are learning to program and create programmes. But the point is that you didn't exactly ask for help with a particular obscure case in the program, but you actually outlined the TOR for writing the program.

What you displayed, in my opinion, is metaphorically speaking in relation to robots, a pile of heterogeneous spare parts. It's not right at all.

So you can't point out a specific error here, as everything needs to be redone in a completely different way. - IMHO, I don't pretend to be more than that.

But that's no reason to get upset. Keep learning how to write. There, as they say, instead of you, of course, can "eat" (to do the job), but you yourself are not becoming well-fed from this (ie, do not learn). So go ahead. If one walks the other the way.

Try to write again with a different approach to the problem. - It worked for me.


Thanks for the critique. Tell me, is it realistic to implement?
 
NICK_R:
Thanks for the critique. Is it realistic to do this at all?

Of course it is. But it's not exactly a simple task. It's not very difficult, but it's not easy either. - It's just right for studying.
 
Chiripaha:

Thank you very much, Igor! I didn't know about the DC and the letter. It must be a mini-account - for the letter "m".

Do you know where the JPY has the coefficient of 82 ? the other currencies had GBP - 0.625, EUR - 0.7751937984

The idea is that when you convert currencies the coefficient would be floating as the exchange rates change. Why then take constants?

Sergey, those numbers don't mean anything to me, so I don't have an answer to that question.

And prefixes in symbol writing may or may not make any sense.

 
TarasBY:

Sergey, these numbers don't mean anything to me, so I have no answer to this question.

And prefixes in the writing of the symbol may or may not make any sense.

OK. Thank you!
 

Good afternoon colleagues!

Can you please tell me how to get away from the loop (highlighted in red in the code)? The indicator is slowing down terribly.

#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  DarkGray
#property  indicator_color2  PowderBlue
#property  indicator_width1  2

//---- basic fan indicator parameters

extern bool Show_AOLine_2=true;
extern int SlowEMA3=34;
extern int EMA=3;
extern bool Show_Volume=true;
extern double coaf=0.5;
//---- indicator buffers
double AOBuffer3[];
double ExtMapBuffer1[];

    double  price_up_start, price_up_end, AO_up;
    double  price_dn_start, price_dn_end, AO_dn;
    datetime time_up, time_dn, AO_time_up, AO_time_dn;
    double Vol_AO_up, Vol_AO_dn;
    int shift_up, shift_dn, dn_koaf, up_koaf, dn_koaf_round, up_koaf_round;
    
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- drawing settings
   
  string name_ind = "Awesome_super_volumes";
   IndicatorShortName("Awesome_super_volumes");
   
   
//---- AO_fan line 2 (basic)
   if(Show_AOLine_2 ==true){Show_AOLine_2=DRAW_LINE; }
   else 
    {Show_AOLine_2=DRAW_NONE; }
   SetIndexBuffer(0,AOBuffer3);
   SetIndexStyle(0,Show_AOLine_2);
   SetIndexLabel(0,"basic line");   

   SetIndexBuffer(1,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexLabel(1,"Volume");
   
  //---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
  
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=0; i<limit; i++)   // -------------------------------------------- Основной цикл
   {
     
 //---- Awesom + Volumes
     
AOBuffer3[i]=iMA(NULL,0,EMA,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,SlowEMA3,0,MODE_SMA,PRICE_MEDIAN,i);
if (Show_Volume==true)
{
double nSum = Volume[i]*Point*coaf;
   if (AOBuffer3[i]<=0)ExtMapBuffer1[i] = nSum;
   if (AOBuffer3[i]>0)ExtMapBuffer1[i] = -nSum;
double Vol_Arr[];
  if (AOBuffer3[i]<=0)Vol_Arr[i]=Volume[i]*Point*coaf;
  if (AOBuffer3[i]>0)Vol_Arr[i] = -Volume[i]*Point*coaf;
}

//----------------------------- Блок поиска значений -----------------------------------------//
 
 //-- Поиск Low & Time & Min_AO 
  if (AOBuffer3[i] < 0)
  {
 price_up_end = 0; AO_up = 0;  
 price_dn_start = Low[i]; if (price_dn_end == 0) price_dn_end = Low[i]; 
 if (price_dn_start <= price_dn_end) {price_dn_end = price_dn_start; time_dn = Time[i]; shift_dn = iBarShift(NULL, 0, time_dn);}
 if (AOBuffer3[i] <= AO_dn) {AO_dn = AOBuffer3[i]*0.2+AOBuffer3[i]; AO_time_dn = Time[i];}
 dn_koaf=dn_koaf_round;
 up_koaf_round++;
  }   
  
  //-- Поиск High & Time & Max_AO  
  if (AOBuffer3[i] > 0)
   {
  price_dn_end = 0; AO_dn = 0;  
  price_up_start = High[i];
  if (price_up_start >= price_up_end) {price_up_end = price_up_start; time_up = Time[i]; shift_up = iBarShift(NULL, 0, time_up);}
  if (AOBuffer3[i] >= AO_up) {AO_up = AOBuffer3[i]*0.2+AOBuffer3[i]; AO_time_up = Time[i];}
  up_koaf=up_koaf_round;
  dn_koaf_round++;
   }   
 //--------------------------------- Выставляем значения --------------------------------------------//
    
   Vol_AO_up = 0; Vol_AO_dn = 0;
  if (shift_up > shift_dn)
    {
 for (int dn_br = shift_dn; dn_br <= shift_up; dn_br++)            //-------------- Перебор значений внутри основного цикла
          {
    Vol_AO_up += Volume[dn_br]; 
    SetText("Awesome_super_volumes"+up_koaf, DoubleToStr(Vol_AO_up,0), AO_time_dn, AO_dn, Blue);
          }   
  }
 
 if (shift_dn > shift_up)
    {
 for (int up_br = shift_up; up_br <= shift_dn; up_br++)            //-------------- Еще один перебор значений внутри основного цикла
          {
    Vol_AO_dn += Volume[up_br]; 
    SetText("Awesome_super_volumes"+dn_koaf, DoubleToStr(Vol_AO_dn,0), AO_time_up, AO_up, Red);
          }   
    }
 } 
           
//---- done

   return(0);
  }
//+------------------------------------------------------------------+
void SetText(string name, string Vl, datetime t1, double p1, color c)
 {
  ObjectCreate(name,OBJ_TEXT,WindowFind("Awesome_super_volumes"),0,0,0,0);
  ObjectSetText(name, Vl, 6, "Arial Black", c);
  ObjectSet(name, OBJPROP_TIME1 , t1);
  ObjectSet(name, OBJPROP_PRICE1, p1);
  ObjectSet(name, OBJPROP_COLOR, c); 
  }

Thank you!


 
Fox_RM:

Good afternoon colleagues!

Can you please tell me how to get away from the loop (highlighted in red in the code)? The indicator is slowing down terribly.

Thank you!

Still, I will give you this, maybe a silly, idea. But maybe I'll come up with a more sensible one.

As far as the task is concerned you need for the final search the data on some bars, then on the first search write the data values into some array (or buffer - I'm not very good at it).

And after first search completes, take necessary values from this array (buffer) to get data for the 2nd search.

Just not particularly sure if this would help for speed. But I don't know much about causes of braking either. It is difficult for me to say something more qualified in this respect.

What could be the pros and cons. The minus is that in this case you estimate the situation on the bar not online, but after the fact, when the data are already kind of useless. But... this is offset by the fact that, in fact, when you recalculate the old data, you no longer need it online. And when current current data arrives, it will immediately be processed by the 2nd enumeration. So there should be no loss of relevance in this case. And plus - it will solve your task: to get rid of overshooting in overshooting. : ))

I may have overlooked something. Take my idea critically. Well, and the best critic is practice. You just have to write and double-check what and how will work. I think so.

 

There is practically no difference, just a slightly different process of getting the A and B control points. I've already tried it with arrays.

Then between A and B I would also have to loop through the bars. I don't see another way, that's why I'm asking.

Maybe somebody can give me a hint. Maybe there is something wrong with the logic of code writing?

 
Fox_RM:

There is practically no difference, just a slightly different process of getting the A and B control points. I've already tried it with arrays.

Then between A and B I would also have to loop through the bars. I don't see another way, that's why I'm asking.

Maybe somebody can give me a hint. Maybe there is something wrong with the logic of code writing?

Yes, exactly - we'll have to do a loop with the overflow anyway. So, there is no way to avoid it. And most likely the question should be posed differently - What causes the braking and how to get rid of it?
 
Fox_RM:

Good afternoon colleagues!

Can you please tell me how to get away from the loop (highlighted in red in the code)? The indicator is slowing down terribly.

Thank you!

You can group the indicator in this place - it will be a small optimization of the indicator:

if (Show_Volume==true)
{
double nSum = Volume[i]*Point*coaf;
   if (AOBuffer3[i]<=0)ExtMapBuffer1[i] = nSum;
   if (AOBuffer3[i]>0)ExtMapBuffer1[i] = -nSum;
double Vol_Arr[];
  if (AOBuffer3[i]<=0)Vol_Arr[i]=Volume[i]*Point*coaf;
  if (AOBuffer3[i]>0)Vol_Arr[i] = -Volume[i]*Point*coaf;
}

like this:

if (Show_Volume==true)
{
 double nSum = Volume[i]*Point*coaf; double Vol_Arr[];  // Не знаю в этом случае можно через запятую переменные прописывать? - double nSum = Volume[i]*Point*coaf, Vol_Arr[];

 if (AOBuffer3[i]<=0) {ExtMapBuffer1[i] =  nSum; Vol_Arr[i] =  Volume[i]*Point*coaf;}
 if (AOBuffer3[i]>0)  {ExtMapBuffer1[i] = -nSum; Vol_Arr[i] = -Volume[i]*Point*coaf;}
}

Here it is:

AO_dn = AOBuffer3[i]*0.2+AOBuffer3[i];
// и тут
AO_up = AOBuffer3[i]*0.2+AOBuffer3[i];

You can change it to:

AO_dn = AOBuffer3[i]*1.2;
     // и
AO_up = AOBuffer3[i]*1.2;

Then, you have "Texts" piling up in the indicator. Before you place new text, you have to delete the old ones. This can really slow down the indicator - maybe that's the reason. Since you get as many of these texts as there are ticks on the selected parameters.

If anyone tells me how best to implement this in the code - because I'm asking for similar coding help myself.

Reason: