Indicator calculation?

 

Hi People

Can anyone have a look at this indicator code, it shows the daily WAIST level.

If i code it with this setup the waist is correct

double OPEN = iOpen(NULL,1440,1);

double CLOSE = iClose(NULL,1440,1);

double WAIST = (OPEN + CLOSE)/2;

If i code it this way it reads 5 to 10 pips out depending on the previous days range.

if(Open > YesterdayOpen)

YesterdayOpen = Open;

//----

if(Close < YesterdayClose)

YesterdayClose=Close;

if (TimeDay(Time)!= TimeDay(Time))

{

WBuffer = EMPTY_VALUE;

WAIST = ( YesterdayOpen + Close ) / 2;

I can not see where the problem is - it is probably something real obvious but i just can not see it at present, any help would be greatly appreciated.

Now i need to do it the 2nd way so that i can have it showing up on the previous days as a trading history.

Here is the code

daily_waist.mq4

cja

Files:
 
YesterdayClose = Open;

YesterdayOpen = Open;

Is that correct?

 
ralph.ronnquist:
YesterdayClose = Open;

YesterdayOpen = Open;

Is that correct?

I believe that is correct as i have compared this piece of code in other pivot daily open indicators and they all have this line of code? however i could be wrong - i stand to be corrected.

cja

 

Ok. Well, I have no idea about the logic, but obviously "YesterdayClose" is not of any use whatsoever.... Hmm, let's see... the line

WBuffer = EMPTY_VALUE;

[/PHP]

has the effect of killing "all" older indications, where "all" only means those that the indicator is invoked for... not sure why... then there is some peculiar(?) exception for indicating on Mondays or Tuesdays(?)

If I understood your objective correctly, I might suggest you replace the for-loop with the following:

[PHP]for (int i=limit; i>=0; i--) {

int d = i * Period() / 1440; // Day bar index.

WBuffer = (iOpen(NULL,PERIOD_D1,d+1)+iClose(NULL,PERIOD_D1,d+1))/2;

}

That is, kind of that a bar on this chart is indicated by considering the "waist" in regards to the day-chart bar that this bar is placed in. Maybe?

 
ralph.ronnquist:
Ok. Well, I have no idea about the logic, but obviously "YesterdayClose" is not of any use whatsoever.... Hmm, let's see... the line
WBuffer = EMPTY_VALUE;

[/PHP]

has the effect of killing "all" older indications, where "all" only means those that the indicator is invoked for... not sure why... then there is some peculiar(?) exception for indicating on Mondays or Tuesdays(?)

If I understood your objective correctly, I might suggest you replace the for-loop with the following:

[PHP]for (int i=limit; i>=0; i--) {

int d = i * Period() / 1440; // Day bar index.

WBuffer = (iOpen(NULL,PERIOD_D1,d+1)+iClose(NULL,PERIOD_D1,d+1))/2;

}
That is, kind of that a bar on this chart is indicated by considering the "waist" in regards to the day-chart bar that this bar is placed in. Maybe?

WBuffer = EMPTY_VALUE; This line of code takes the joining line out of the historical lines and leaves them as individual daily lines.

 
cja:
WBuffer = EMPTY_VALUE; This line of code takes the joining line out of the historical lines and leaves them as individual daily lines.

Right, of course; that's "a good thing", yes... so that should be dropped back into the loop.. making it:

for (int i=limit; i>=0; i--) {

int d = i * Period() / PERIOD_D1; // Day bar index.

WBuffer = (iOpen(NULL,PERIOD_D1,d+1)+iClose(NULL,PERIOD_D1,d+1))/2;

if (TimeDay(Time) != TimeDay(Time))

WBuffer = EMPTY_VALUE;

}

... what about the "Monday fiddling"?

Reason: