[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 173

 
Ctmcn:

Can you tell me what the error means when compiling the EA?

\end_of_program' - unbalanced left parenthesis


Unbalanced left parenthesis.
 
Roll:

Unbalanced left bracket.

Oops... Found it. THANK YOU.
 

Here is a question.

Orders are opened as BUY/SELL STOP. Some become market orders, others are deleted.

For the last N-market orders (open and closed) we need to know if they were Buy or Sell.

My first thought is to search all orders from OrdersHistoryTotal() and OrdersTotal(), sort them by

and then sort them by OP_BUY and OP_SELL. But this is long and will slow down the processor wildly.

- Maybe there is some other, simpler variant?

Thank you!

 

Good afternoon.

Can anyone help?

I wrote my first simple indicator, it should calculate the average volatility for the past 2,3,4,and 5 days.

The indicator has six buffers,

SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,VolatBuffer0);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,VolatBuffer1);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,VolatBuffer2);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(3,VolatBuffer3);
   SetIndexStyle(4,DRAW_HISTOGRAM);
   SetIndexBuffer(4,VolatBuffer4);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,VolatBuffer5);

In its window on the chart normally draws only five vertical lines of volatility for 0 day, 1 day, average for 2 days, 3 days and 4 days.

The average volatility according to the sum of the 5 previous days is drawn as a broken line for 50 daily candles - that is how many candles are specified.

The content of buffers is calculated as follows: averaging for 5 days - in cycle (to draw a line for 50 days), other averaged data - out of cycle.

while(i>=0)
   {
    
   int day0= (High[i] - Low[i])/Point;
   int day1= (High[i+1] - Low[i+1])/Point;
   int day2= (High[i+2] - Low[i+2])/Point;
   int day3= (High[i+3] - Low[i+3])/Point;
   int day4= (High[i+4] - Low[i+4])/Point;
   int day5= (High[i+5] - Low[i+5])/Point;

        int D5_av = (day1+ day2+ day3+ day4+ day5) / 5;
       VolatBuffer5[i]=D5_av;
      i--;
        }
        day0= (High[0] - Low[0])/Point;
   day1= (High[1] - Low[1])/Point;
   day2= (High[2] - Low[2])/Point;
   day3= (High[3] - Low[3])/Point;
   day4= (High[4] - Low[4])/Point;
        
        int D4_av = (day1+ day2+ day3+ day4)/4;
        int D3_av = (day1+ day2+ day3)/3;
        int D2_av = (day1+ day2)/2;
        int D1_av = day1/1;
        int D0_av = day0/1;
        
        VolatBuffer0[0]=D0_av;
      VolatBuffer1[1]=D1_av;
      VolatBuffer2[2]=D2_av;
      VolatBuffer3[3]=D3_av;
      VolatBuffer4[4]=D4_av;
Comment("Волатильность. За 5 дн.= "+VolatBuffer5[5]+" За 4 дн.= "+VolatBuffer4[4]+" За 3 дн.= "+VolatBuffer3[3]+" За 2 дн.= "+VolatBuffer2[2]+" Вчера= "+VolatBuffer1[1]+" Сегодня= "+VolatBuffer0[0]);

The Coment line in the indicator, in which the contents of the buffers are entered, gives an absurdity on the screen:

Averaging for 5 days - no volatility greater than 194 pips for those days and correct results for other days.

Coment = " Volatility. For 5 days = 219.000000 For 4 days = 171.0000000 For 3 days = 189.00000 For 2 days = 187.00000 Yesterday = 194.00000 Today = 5 "

Zero-day "Today" clearly increases with the volatility of the current day

When calling these buffers to the Expert Advisor

int Volat0= iCustom(Symbol(), 1440, "Volat_Average_Gist",0,0);
      int Volat1= iCustom(Symbol(), 1440, "Volat_Average_Gist",1,0);
      int Volat2= iCustom(Symbol(), 1440, "Volat_Average_Gist",2,0);
      int Volat3= iCustom(Symbol(), 1440, "Volat_Average_Gist",3,0);
      int Volat4= iCustom(Symbol(), 1440, "Volat_Average_Gist",4,0);
      int Volat5= iCustom(Symbol(), 1440, "Volat_Average_Gist",5,0);

tester's Print line Outputs another absurdity - not correct, different from the Coment line, but similar to the truth, the average result for 5 days and the correct volatility of today's "Day Zero".

The rest gives a fixed absurd number.

The tester Print shows the Volatility in 5 days=181 In 4 days= 2147483647 In 3 days= 2147483647 In 2 days= 2147483647 Yesterday= 2147483647 Today= 5

For several days I cannot understand why different data is called to the Expert Advisor than that contained in the five indicator buffers, except for the "Day Zero" buffer?

 

Try substituting

VolatBuffer1[1]=D1_av;

to

VolatBuffer1[0]=D1_av;

and all other buffers as well.

 
Roger:

Try substituting

VolatBuffer1[1]=D1_av;

to

VolatBuffer1[0]=D1_av;

and all other buffers as well.

Thank you!

It worked. The Expert Advisor started to receive normal data.

In addition, there is an interesting effect - in the "Coment" line of the indicator

only 219 for 5 days will remain as it has been.

At the same time the Expert Advisor receives 181 instead of 219 as it should be.

Coment'' shows Volatility Over 5 days= 219.000000 Over 4 days= 2147483647 Over 3 days= 2147483647 Over 2 days= 2147483647 Yesterday= 2147483647 Today= 5

 
Roger:

Try substituting

VolatBuffer1[1]=D1_av;

to

VolatBuffer1[0]=D1_av;

and all other buffers as well.

I have found one more effect. All vertical lines in the indicator window are drawn on top of each other

The largest value covers all others. It is not essential for the Expert Advisor.

 
Vekker:

Good afternoon.

Can anyone help?

Wrote my first simple indicator - should count the average volatility for the past 2,3,4,and 5 days.

You can simplify things considerably by using ATR:

iATR(NULL, PERIOD_D1, Number_Of_Days, 1)
 
Roll:
Two scripts:

The question is no longer how to write the code, but at the level of an idea - is it possible to avoid multiple loops,

which puts a lot of load on the processor. For example, there was an idea to track the number of open STOP orders - if it has decreased by one, but the order has not been deleted => open a market order =>

its open time and type should be placed in an array. Something like this.

Any ideas are welcome.

Thanks!

 
chief2000:

You can simplify things considerably by using ATR:



Thank you! I'll try
Reason: