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

 
borilunad:
Hi Allis! Print needs to be prescribed where there is no tick reading! I put in the print if there is an error, and if it opened, and so it is prescribed in the logbook that it opened, and only once!

Yes you are a Wizard)) Thank you!
 
Allis:

You are a magician)) Thank you!
Exactly, in programming I'm far from being a "Wizard", I'm just learning, but in some other branches, maybe!)) Thank you!
 

Good evening all. There is an indicator (upper in the figure) that draws its values (+1, 0, -1) on bar number 0, but the calculation is conducted by bar number 1. I need to write an indicator that would count the number of bars in each separate continuous block of +1 and -1 top indicator and the entire history (the average in the figure, the bar graph height in units corresponding to the number of bars).I have made an indicator (bottom in the figure), but it starts to be drawn only at the moment of installation in the window (blue vertical line).help who can!


Code

int start()
  {
    
    int i;
      
    for(i=1;i<Bars-34-1;i++)                                               
     {
      double AO_Sig_Sig_1 =iCustom(NULL,0,"AO_His_l-b_Signal-Signal_sploshnoy_PSR",0,i);                           
      double AO_Sig_Sig_2 = iCustom(NULL,0,"AO_His_l-b_Signal-Signal_sploshnoy_PSR",0,i+1);
      
                                  
      if((AO_Sig_Sig_1!=AO_Sig_Sig_2)) break;                                                                
     }
         
    i=i*(AO_Sig_Sig_1);         
               
    if(i>0)            
     {
      UpMapBuffer[0]=i;
     }
    else
     {
      UpMapBuffer[0]=0;
     } 
         
    if(i<0)         
     {
      DnMapBuffer[0]=i;
     }
    else
     {
      DnMapBuffer[0]=0;
     }          
                 
      
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
borilunad:

This is the remainder of the division! Look in the arithmetic steps and in your printer!

Put it in and you will only see the two results alternately:

 int x = MathRand() % 2;
  Print("x =",x);


I don't understand the logic. In the book I read:

If you want to calculate the remainder of division of variablea by variable band write the result to the variable ostatok, the assignment operator looks like this:

ostatok = a % b;

It turns out that in our case, whenMathRand() isdivided by 2, the value of x must be 0 or 1. Why should it be 0 or 1 all of a sudden? For example a random number 9 will appear. 9 % 2 = 4.5. The remainder of equals 4.
 
hoz:


Something I don't understand the logic of. In the book I read:

It turns out that in our case, whenMathRand() isdivided by 2, there should be a value of x equal to 0 or 1. Why should it be 0 or 1 all of a sudden? For example a random number 9 will appear. 9 % 2 = 4.5. The remainder of equals 4.

When something doesn't add up, it only takes a couple of clicks to answer...

P.S. ostatok = 9 % 2 = 1.

 
TarasBY:

When something doesn't add up, it only takes a couple of clicks to answer...

P.S. ostatok = 9 % 2 = 1.


Well, it's written:

"Division with a remainder(modulo division,finding the remainder of division,the remainder of division) is anarithmeticoperation resulting in twointegers:an incomplete quotient andthe remainder of the division of a whole number by anotherinteger."

9 : 2 = 4.5 These are double numbers.

If you cut off the fractional part, it's 4. Where did you get 1?

 
hoz:


There's something about the logic I don't understand. In the book I read:

It turns out that in our case, whenMathRand() isdivided by 2, the value of x must be 0 or 1. Why should it come out 0 or 1 all of a sudden? For example a random number 9 will appear. 9 % 2 = 4.5. The remainder of equals 4.

Victor, don't confuse int with double! Soint x = MathRand() % 2; gives 0 or 1! It cannot give 0.1 or 0.9, neither 1.1 nor 1.9, because decimals in int are rounded and less than 0.5 are discarded! And the % sign means the remainder of the division, not the division sign. The division sign is /.

I put your example with 9 and get a single result, 1, because there is no random:

  int x = 9 % 2;//MathRand()
  Print("x =",x);

You ask:

9 : 2 = 4.5 These are double numbers.

If you discard the fractional part, you get 4. Where did you get 1?

I answer: So 0.5 is rounded to 1!

What's interesting, when I put a point and zero (2.0) to 2, the compiler gave me an error saying that % requires only an integer!

So even if you put double x, it still comes out an integer int. Thank you, Victor, for your doubts! Thanks to them and to you I made an interesting research, which will broaden my possibilities of mathematical transformations! I owe you a glass (virtual)! :))

 
hoz:


Well, that's what it says:

"Division with a remainder(modulo division,finding the remainder of division,remainder of division) is anarithmeticoperation that results in twointegers:an incomplete quotient andthe remainder of the division of a whole number by anotherwhole number."

9 : 2 = 4.5 These are double numbers.

If you cut off the fractional part, it's 4. Where did you get 1?

What is the closest integer to 9 that is divisible by 2 without a remainder? Then subtract that number from the divisor (9). What did you get?

P.S. If you failed, you can print the result: Print ("ostatok = ", 9 % 2);

 

laveosa 07.03.2013 21:15

Hi. Can you tell me how to replace Symbol() with "EURUSD" in Ordersend() or what?

 
Mathemat:

laveosa 07.03.2013 21:15

Hello. Can you tell me how to replace Symbol() with "EURUSD" in Ordersend() or what?

NULL