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

 

No, it won't beep all the time, it's "array out of range" when >=. Why?

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(rates_total<2) return(0);
     {
      int limit=rates_total-prev_calculated;
      if(limit>1) 
        {
         ArrayInitialize(BufferUP,EMPTY_VALUE);
         ArrayInitialize(BufferDN,EMPTY_VALUE);
        }
      for(int i=limit; i>=0; i--) 
        {
         if(TimeCurrent()>=Input1 || TimeCurrent()>=Input2 || TimeCurrent()>=Input3)
           {
            BufferUP[i]=low[i]-10*Point;// в этой строке array out of range in 'a1.mq4' (75,28)

            Alert("__",TimeCurrent());
           }
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
volyal:
Thank you. Just>= is not possible, there will be a constant signal, after the first date, you need to set the time range. How to set?

this is the second part of the question and the second part of the answer

When the signal (alert) triggers, you need to fix that the signal has already been applied, you need an additional condition:

 {
//---
   static bool alerton=true;
   A=1;B=2;
   if(rates_total<2) return(0);
     {
      int limit=rates_total-prev_calculated;
      if(limit>1)
        {
         ArrayInitialize(BufferUP,EMPTY_VALUE);
         ArrayInitialize(BufferDN,EMPTY_VALUE);
        }
      for(int i=limit; i>=0; i--)
        {
         if(alerton)
           {
            if(A>B)
              {
               if((TimeCurrent()>=Input1 || TimeCurrent()>=Input2 || TimeCurrent()>=Input3))
                 {
                  BufferUP[i]=low[i]-10*Point;
                  Alert("__",TimeCurrent());
                  alerton = false;
                 }
              }
           }
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }

You have in your code clear conditions for triggering of the alert. Usually indicators are asking to make one signal per bar, then you need to "bind" the time of bar to a variable that will store the time of alert triggering, i.e. I am talking about

static datetime alerton=0;

Search for ready examples, I think you'll understand it now.

 
Aleksey Vyazmikin:

If many signals are the same all at once, group them together and play them as one. Or collect them in arrays by signal type and play them slowly :)

Group them into an array and play them in a separate script - that's pretty clear, corresponds to your first tip.

But to group and play it as one, I don't quite understand. As one audio file?

How, for example, to group

if(Sobitie_1)

{
PlaySound("Symbol.wav");
PlaySound("Sobitie1.wav");
PlaySound("Period.wav");
}?


Like PlaySound("Symbol Sobitie1 Period.wav");? In this case, the number of files Symbol * Sobitie * Period=3*10*7=210. That's too much):

Besides, signals for playback come from indicators from different TFs. I do not know yet how to take it into account.

 
Algus:

Group it into an array and play it in a separate script - that's generally understandable, according to your first suggestion.

But to group and play as one, I don't quite understand. As one audio file?

How, for example, to group

if(Sobitie_1)

{
PlaySound("Symbol.wav");
PlaySound("Sobitie1.wav");
PlaySound("Period.wav");
}?


As PlaySound("Symbol Sobitie1 Period.wav");? In this case, the number of files Symbol * Sobitie * Period=3*10*7=210. That's a lot...):

Besides, signals for playback are coming from indicators from different TFs. I don't know how to take it into account yet.

I was talking about the frequency at which the signal comes in, ie, as I understand you have the same and not the same sound, while playing a sound is accumulated in a buffer (can be in the graphical accumulate) the queue to play, after play queue analyzed and discarded those sounds that came at the time of playing the file and have the same sound, ie do not carry the new information. I do not know the details of your melophone :).

 

Good afternoon!

Please help me with this misunderstanding:

I set a condition to open a position:

if(MathAbs(WPR1)<20.0)
        {
         if(MathAbs(WPR14)>44.0 && MathAbs(WPR14)<60.0 && op0<cl1) 
{ps2=true;ps1=false;ps3=false;ps4=false;ps5=false;ps6=false;ps7=false;ps8=false;Alert("условие ps2"); OpenSell();}
        }

And instead of one position with the flagps2, it opens two, with flagsps2 andps3. And no matter what I did, nothing changes. I checked all situations with alerts and nothing. What's up???? There seems to be nothing wrong, flags set different levels of TP. But all the same, I do not need an extra position.

Thank you.

 
novichok2018:

Good afternoon!

Please help me with this misunderstanding:

I set a condition to open a position:

And instead of one position with the flagps2, it opens two, with flagsps2 andps3. And no matter what I did, nothing changes. I checked all situations with alerts and nothing. What's up???? There seems to be nothing wrong, flags set different levels of TP. But all the same, I do not need an extra position.

Thanks.

In addition, the log says that first opensps3, thenps2.

 
novichok2018:

Good afternoon!

Please help me with this misunderstanding:

I set a condition to open a position:

And instead of one position with the flagps2, it opens two, with flagsps2 andps3. And no matter what I did, nothing changes. I checked all situations with alerts and nothing. What's up???? There seems to be nothing wrong, flags set different levels of TP. But all the same, I do not need an extra position.

Thank you.

Vovochka returns from school. Dad asks:

- What grade did you get today?

- I got a "D" in science.

- Why?

- The teacher shows me the tail of a bird and tells me to guess what kind of bird it is...

This daddy goes to school, opens the classroom door and points his ass in there.

- Who the hell is that...

...asks the teacher...

- Guess for yourself.


This is exactly your code...))))

 
Alexey Viktorov:

Vovochka comes home from school. Dad asks:

- What grade did you get today?

- I got a "D" in science.

- Why?

- The teacher shows you the tail of a bird and tells you to guess what kind of bird it is...

This daddy goes to school, opens the classroom door and points his ass in there.

- Who the hell is that...

...asks the teacher...

- Guess for yourself.


That's exactly your code... ))))

Fifth grader Ljoshenka doesn't come to the first classes to help, but to ruffle feathers.

That's exactly your answer.

 
novichok2018:

In addition, the logbook says it opensps3 first, thenps2.

That's it, I've figured it out. It turned out to be simple: In the alerts with the conditionps8 instead of 8 there was 3. And condition 8 is wider than condition 2 and is higher on the lines. Fixed it and narrowed it down, everything's OK.

But you shouldn't wag your tail, this thread is for newbies. A real expert without details should understand where the error is approximately, or at least ask leading questions, otherwise he should not answer at all, rather than flaunt pseudo-twirling.

 
Aleksey Vyazmikin:

I was talking about the frequency at which the signal comes in, i.e., as I understand you have the same and not the same sound, while playing the sound is accumulated in a buffer (you can in the graphic accumulate) queue to play, after playing the queue analyze and discard those sounds that came at the time of playing the file and have the same sound, ie, do not carry the new information. I do not know the details of what kind of melophone you have there :)

There is an indicator that stands on and all working TFs and currencies. I work in intraday, almost scalping, on 2-3 instruments. I use sound alerts not to miss any events and my eyes do not fall out at the end of the day.

In fact, there are 10-14 indicators addressing Windows in the activity. It turns out that we need to build the queue of different indicators that work independently. This is not a simple task for the terminal or its programming.

This is the kind of "music" we get):