RangeBar

Posted By: tradingest

RangeBar - 01/12/19 14:28

Hi guys,

whythe range bar is not costant?

Here I show you the difference between High and Low. Why is not costant? The code used below
Code:
var BarRange = 0.005;
//Range Bar
int bar(vars Open,vars High,vars Low,vars Close)
{
  if(Open[0] != Close[1]) {
    High[0] = max(Open[0],Close[1]);
    Low[0] = min(Open[0],Close[1]);
    Open[0] = Close[1];
  }
  if(High[0]-Low[0] >= BarRange)
    return 1;
  return 4;
}
function run()
{	
	set(PLOTNOW);
	StartDate = 20180601;
	EndDate = 2019;
	BarPeriod = 1;	
	asset("EUR/USD");

	plot("Range",priceHigh()-priceLow() ,NEW,RED);
	
}



thanks
Posted By: jrath

Re: RangeBar - 01/12/19 15:53

Your code is plotting the difference between price high and low for every bar. It varies.

Try this :

plot("Range",BarRange ,NEW,RED);

J
Posted By: tradingest

Re: RangeBar - 01/12/19 16:01

Originally Posted By: jrath
Your code is plotting the difference between price high and low for every bar. It varies.

Try this :

plot("Range",BarRange ,NEW,RED);

J


Yes, but for definition the difference between High and Low using the RangeBar should be always the same. I really wanted to check this but there's something wrong and I don't understand what.

Can you help me?
Posted By: jrath

Re: RangeBar - 01/12/19 16:40

Maybe :


Code:
var BarRange = 0.005;

//Range Bar
int checkBar(vars Open,vars High,vars Low,vars Close)
{
  if(Open[0] != Close[1]) {
    High[0] = max(Open[0],Close[1]);
    Low[0] = min(Open[0],Close[1]);
    Open[0] = Close[1];
  }
    
  if(High[0]-Low[0] >= BarRange)
    return 1;
  return 4;
}

function run()
{	
	set(PLOTNOW);
	StartDate = 2018;
	EndDate = 2019;
	BarPeriod = 1;	
	asset("EUR/USD");

	vars priceOpen = series(priceOpen());
	vars priceHigh = series(priceHigh());
	vars priceLow = series(priceLow());
	vars priceClose = series(priceClose());
		
	plot("Range",checkBar(priceOpen, priceHigh, priceLow, priceClose) ,NEW,RED);
	
}

© 2024 lite-C Forums