issue with selecting a timeframe in an indicator..

 

Here is a small piece of code in an Indicator i am working on. I have become stuck with an issue. The following code relates to bars on current timeframe. I need (i) to be selective of the D1 timeframe only, reguardless of with timeframe is opened on the chart. Can anyone fix the issue for me. Thanks..

for(int i = MathMax(Bars-1-IndicatorCounted(),1);
i>=1; i--)
{
double ema = EMA(i);

 

for loop comes with 3 parameters like this

for (int i = x; i >= x; i++ ) 
 
qjol:

for loop comes with 3 parameters like this


Yea i think i have that as it is? how do i make it selective of (i) using D1 timeframe only, with the code i have posted

 
gavin:


Yea i think i have that as it is? how do i make it selective of (i) using D1 timeframe only, with the code i have posted


can you fix the code?

 

what do u trying to accomplish with the MathMax() function ?

c more about MathMax() & IndicatorCounted()

 

here is the rest of the code.. Close (i) each is getting the value from current timeframe. I want it to read the values of close (i) on the daily timeframe all the time....

if(Close[i] >= ema && ema2 >= ema )
{
SetEmaColor(1,i); // BLUE
}

 
gavin:

Here is a small piece of code in an Indicator i am working on. I have become stuck with an issue. The following code relates to bars on current timeframe. I need (i) to be selective of the D1 timeframe only, reguardless of with timeframe is opened on the chart. Can anyone fix the issue for me. Thanks..

Your indicator needs to update every bar. And do the loop properly.

//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- main loop
for(int shift= limit-1; shift >=0; shift--){
  int D1_bar = iBarShift(NULL, PERIOD_D1, Time[shift]);
  double EMA_D1=iMA(0, PERIOD_D1,0, MODE_EMA,PRICE_MEDIAN,D1_bar);
 
WHRoeder:

Your indicator needs to update every bar. And do the loop properly.



Thanks alot. I will get this in my code as see how i go. Cheers.

 
gavin:


Thanks alot. I will get this in my code as see how i go. Cheers.


Is this correct WhRoeder. Defining what counted bars is and Int limit...??

int counted_bars = (Bars-1-IndicatorCounted(),1);
int limit;

 

no

what is this (the red) int counted_bars = (Bars-1-IndicatorCounted(),1);