variable assignment anomaly

 

I have a problem with assignments. In my code I have

higher = (high - close)*0.33;


the right side of the = operator has a value of 7.2 and the left has 0.99 after it is supposed to be initialized by the right side.

higher,high, and close are declared as doubles and the high and close are assigned as follows

if( (MarketInfo(Symbol(),MODE_DIGITS) == 2)||(MarketInfo(Symbol(),MODE_DIGITS) == 3) )
        {
         open = NormalizeDouble(Open[i+1]*multiplier,2);
         close = NormalizeDouble(Close[i+1]*multiplier,2);
         high = NormalizeDouble(High[i+1]*multiplier,2);
         low = NormalizeDouble(Low[i+1]*multiplier,2);
         
       }
       else
       {
         open = NormalizeDouble(Open[i+1]*multiplier,4);
         close = NormalizeDouble(Close[i+1]*multiplier,4);
         high = NormalizeDouble(High[i+1]*multiplier,4);
         low = NormalizeDouble(Low[i+1]*multiplier,4);
       }

multiplier is an int that multiplies the price so that (high - low) will give the difference of price in pips.


Does anyone have a clue why higher is not being assigned appropriately?

 
Try changing multiplier to a double and read up on type casting.
 
RaptorUK:
Try changing multiplier to a double and read up on type casting.

Shouldn't matter. For example...

   double d = 1.23456;
   int i = 2;
   double r = d * i;

r has the value 2.46912. I think the problem has to be something else, in the portion of the code which isn't included. (Among the things which aren't clear to me is why, if "multiplier" is being used to create a value in pips, then (a) it's the same multiplier for e.g. USDJPY and EURUSD, and (b) why some values are normalized to 2DP and others are normalized to 4DP given that a value in pips basically only has 1DP.)

 
  1. jeemba2012:
    I have a problem with assignments. In my code I have
    higher = (high - close)*0.33;
    the right side of the = operator has a value of 7.2 and the left has 0.99 after it is supposed to be initialized by the right side.
    I doubt what you say is true. Add a print statement after that line and you'll see why.
    Print("higher(",higher,") = (high(",high,") - close(",close,"))*0.33 = ",(high - close)*0.33);

  2. multiplier is an int that multiplies the price so that (high - low) will give the difference of price in pips.
    A) There is no problem with it being an int. B) There is no need for NormalizeDouble, EVER. Don't use it. The only time an adjustment is needed is when placing a pending order where price must be a multiple of ticksize (normalize will only round it to multiple of point.)
    double ts = MarketInfo(pair, MODE_TICKSIZE)
    size      = MathRound(size/ts)*ts;

 
WHRoeder:
  1. jeemba2012:
    I have a problem with assignments. In my code I have the right side of the = operator has a value of 7.2 and the left has 0.99 after it is supposed to be initialized by the right side.
    I doubt what you say is true. Add a print statement after that line and you'll see why.
  2. multiplier is an int that multiplies the price so that (high - low) will give the difference of price in pips.
    A) There is no problem with it being an int. B) There is no need for NormalizeDouble, EVER. Don't use it. The only time an adjustment is needed is when placing a pending order where price must be a multiple of ticksize (normalize will only round it to multiple of point.)

I used the code

Print("higher(",higher,") = (high(",high,") - low(",low,"))*0.33 = ",(high - low)*0.33);

and it still came out weird. see attachment

 
jeemba2012:

see attachment

What attachment ?
 

For some reason I dont know how to attach the pdf even though browsed it and opened it, but I copy and pasted from print out from my mt4


2011.12.02 11:40:35 PinBar GBPUSD,H4: higher(4.95) = (high(15538.3) - low(15494.1))*0.33 = 14.586

2011.12.02 11:40:35 PinBar GBPUSD,H4: higher(1.65) = (high(15608.8) - low(15540.8))*0.33 = 22.44
2011.12.02 11:40:35 PinBar GBPUSD,H4: higher(0.891) = (high(16144.3) - low(16110.2))*0.33 = 11.253
2011.12.02 11:40:35 PinBar GBPUSD,H4: higher(4.257) = (high(15988.4) - low(15937.6))*0.33 = 16.764
2011.12.02 11:40:35 PinBar GBPUSD,H4: higher(3.168) = (high(16053.3) - low(16016.8))*0.33 = 12.045
2011.12.02 11:40:35 PinBar GBPUSD,H4: higher(2.871) = (high(16201.2) - low(16167.4))*0.33 = 11.154
 

Where did you put that Print statement in relation to this line . . .

higher = (high - close)*0.33;

and why does this line have close and your print uses low ?

I think you need to show more code.

 

this one seems to work..

   int    multiplier;
   double open,
          close,
          high,
          low,
          higher,
          third=0.33;

    if( (MarketInfo(Symbol(),MODE_DIGITS) == 2)||(MarketInfo(Symbol(),MODE_DIGITS) == 3) )
        {
         multiplier=100;
         open = Open[i+1]*multiplier;
         close = Close[i+1]*multiplier;
         high = High[i+1]*multiplier;
         low = Low[i+1]*multiplier;
        }
       else
        {
         multiplier=10000;
         open = Open[i+1]*multiplier;
         close = Close[i+1]*multiplier;
         high = High[i+1]*multiplier;
         low = Low[i+1]*multiplier;
        }
   
   higher = NormalizeDouble((high - low)*third,0);   
   Print("high: ",high," low: ",low," (high - low)*0.33: ",((high-low)*third)," higher: ",higher);
Reason: