Ihighest & Lowest return strange values?!

 

Hi,

I am writing an EA that will use 50% of the previous 3 day range.

E.G - If today is Thursday it will find the center value of Mon-Wed range and if its Friday then Tue-Thursday's range etc.

I would like to be able to run this EA on smaller timeframes but still want it reading the 3 day range... i thought the following code would return this but doesnt :-(

Can anyone tell me why? I have tried just running the Ihighest function and then printing the returned value and it doesn't match the relevant high.... why would this be?

Thanks in advance for any assistance

HighestV = High[iHighest( NULL, PERIOD_D1, MODE_HIGH, 3, 1)];
LowestV = Low[iLowest( NULL, PERIOD_D1, MODE_LOW, 3, 1)];
BalancePoint = (LowestV+((HighestV - LowestV)/2));
Print("Balance.......(",BalancePoint,")");  

 
marty087:

Hi,

I am writing an EA that will use 50% of the previous 3 day range.

E.G - If today is Thursday it will find the center value of Mon-Wed range and if its Friday then Tue-Thursday's range etc.

I would like to be able to run this EA on smaller timeframes but still want it reading the 3 day range... i thought the following code would return this but doesnt :-(

Can anyone tell me why? I have tried just running the Ihighest function and then printing the returned value and it doesn't match the relevant high.... why would this be?

Thanks in advance for any assistance

HighestV , LowestV  and BalancePoint are double? If are int, not work
 
marty087:

Hi,

I am writing an EA that will use 50% of the previous 3 day range.

E.G - If today is Thursday it will find the center value of Mon-Wed range and if its Friday then Tue-Thursday's range etc.

I would like to be able to run this EA on smaller timeframes but still want it reading the 3 day range... i thought the following code would return this but doesnt :-(

High and Low work relative to the current chart . . if you run this on H1 and iHighest returns 2 then you will get the high value for the bar number 2 on H1 . . .

Use this instead, iHigh & iLow then you can specify the TimeFrame

 
pannek:


Hi Pannek,

You are absolutly right to pick up on that, i forgot to mention that i am running this on the aussie SPI whcih has no decimal place though. Thats why the int. Thanks for the response.

 
RaptorUK:

High and Low work relative to the current chart . . if you run this on H1 and iHighest returns 2 then you will get the high value for the bar number 2 on H1 . . .

Use this instead, iHigh & iLow then you can specify the TimeFrame


Thanks Raptor, now i understand. Much appreciated.
 
RaptorUK:

High and Low work relative to the current chart . . if you run this on H1 and iHighest returns 2 then you will get the high value for the bar number 2 on H1 . . .

Use this instead, iHigh & iLow then you can specify the TimeFrame

Hi Raptor,

I spoke to soon... I must be missing something.... I tried changing the High to iHigh and now it tells me when i try to compile that a [ is expected,,,

What am i doing wrong?

 
marty087:

What am i doing wrong?

Did you read the Documentation on iHigh and iLow ? click the links in my post . . & show your code that doesn't work . . .
 
HighestV = High[iHighest( NULL, PERIOD_D1, MODE_HIGH, 3, 1)];

iHighest returns the highest D1 bar (for the last 3 days)

High[x] return the highest price for the chart bar x.

Oil and water, don't mix.

int    iHiD1    = iHighest( NULL, PERIOD_D1, MODE_HIGH, 3, 1);
double HighestV = iHigh(NULL, PERIOD_D1, iHiD1);
or, convert to the chart
datetime Today     = iTime(NULL, PERIOD_D1, 0),
         FourDays  = iTime(NULL, PERIOD_D1, 3);
int      iBod      = iBarShift(NULL,0, Today),    // Beginning of the day.
         iFour     = iBarShift(NULL,0, FourDays), // First bar 4 days ago.
         iYesterday= iBod + 1,                    // Last bar of yesterday.
         n3days    = iFour - iYesterday + 1,      // Bars inclusive.
int      iHigh     = iHighest( NULL,0, MODE_HIGH, n3days, iYesterday); // Chart index
double   HighestV  = High[iHigh];                                      // Chart high
 
int BalancePoint(double C)
{   
   int    iHiD1    = iHighest( NULL, PERIOD_D1, MODE_HIGH, 3, 1);
   double HighestV = iHigh(NULL, PERIOD_D1, iHiD1);
   int    iLoD1    = iLowest( NULL, PERIOD_D1, MODE_HIGH, 3, 1);
   double LowestV  = iLow(NULL, PERIOD_D1, iHiD1);
   double Bal = (LowestV+((HighestV - LowestV)/2));
   Print("Balance.......(",Bal,")"); 
   if (C > Bal){return (Above);}
   if (C < Bal){return (Below);}
   return(0);  
}

Sorry about the late reply guys.

Thanks for your help.

Based on both of your suggestions this is what i have so far.... unfortunately still it is not producing the correct result when testing on a 4hr time frame....

The "C" is the Close of the precvious bar from the main program.... The function works correctly in that it returns above and below, but the balance line seems to vary from occasionally correct to maybe a full days range off the mark,,,,

If you have any suggestions that would be greatly appreciated.

Thanks again!

 

Why are you using the Bar number for the Highest bar to get the value for the lowest bar ?

double LowestV  = iLow(NULL, PERIOD_D1,  iHiD1  );

You need to learn how to find copy & paste errors . . . we all make them :-)

 
yep. Also
double Bal = (LowestV+((HighestV - LowestV)/2));
double Bal = (LowestV+HighestV)/2); // Same thing w/ less roundoff error.