ATR Candlestick / ATR Bar Indicator

 

Coloring bars based on ATR

Linda Raschke uses a bar color study that is based on average true range. ATR indicator.

I have found it to be useful. How would one go about creating the following in Meta Trader 4?

Time Frame:

Any

Currency Pair:

Any

:: Bar Coloring criteria ::

If a bar moves a certain units of ATRs of the lowest low the bar turns green and if it moves a certain units of ATRs of the high it turns red.

Apply 20 period ATR, which means we are calculating data from last 20 closed bars.

If 1 candlestick trading range becomes big and jumps up to 2.5 ATR then color that bar.

If it is a bearish bar then color is Red.

If it is a bullish bar then color is Green.

Here is the code which does not work in Meta Trader 4 and also it needs some correction.

var vATR14 = new ATRStudy(14);

var vDonchian = new DonchianStudy(20, 0);

var vLastAlert = -1;

function preMain() {

setPriceStudy(true);

setStudyTitle("corona");

setColorPriceBars(true);

}

function main() {

setPriceBarColor(Color.blue);

if (

high() >= vDonchian.getValue(DonchianStudy.UPPER, -1)+2*vATR14.getValue(ATRStudy.ATR)

) onAction1();

if (

low() <= vDonchian.getValue(DonchianStudy.LOWER, -1)-2*vATR14.getValue(ATRStudy.ATR)

) onAction2();

return null;

}

function onAction1() {

setPriceBarColor(Color.red);

vLastAlert = 1;

}

function onAction2() {

setPriceBarColor(Color.lime);

vLastAlert = 2;

}

I hope New Digital or Coder Guru or any other want to help me out on this.

Best Wishes,

Dave

================

 
davidjohny:
Coloring bars based on ATR

Linda Raschke uses a bar color study that is based on average true range. ATR indicator.

I have found it to be useful. How would one go about creating the following in Meta Trader 4?

Time Frame:

Any

Currency Pair:

Any

:: Bar Coloring criteria ::

If a bar moves a certain units of ATRs of the lowest low the bar turns green and if it moves a certain units of ATRs of the high it turns red.

Apply 20 period ATR, which means we are calculating data from last 20 closed bars.

If 1 candlestick trading range becomes big and jumps up to 2.5 ATR then color that bar.

If it is a bearish bar then color is Red.

If it is a bullish bar then color is Green.

Here is the code which does not work in Meta Trader 4 and also it needs some correction.

var vATR14 = new ATRStudy(14);

var vDonchian = new DonchianStudy(20, 0);

var vLastAlert = -1;

function preMain() {

setPriceStudy(true);

setStudyTitle("corona");

setColorPriceBars(true);

}

function main() {

setPriceBarColor(Color.blue);

if (

high() >= vDonchian.getValue(DonchianStudy.UPPER, -1)+2*vATR14.getValue(ATRStudy.ATR)

) onAction1();

if (

low() <= vDonchian.getValue(DonchianStudy.LOWER, -1)-2*vATR14.getValue(ATRStudy.ATR)

) onAction2();

return null;

}

function onAction1() {

setPriceBarColor(Color.red);

vLastAlert = 1;

}

function onAction2() {

setPriceBarColor(Color.lime);

vLastAlert = 2;

}

I hope New Digital or Coder Guru or any other want to help me out on this.

Best Wishes,

Dave

================

This is an indicator that works like the code you attached. As far as I see Atr multiplier of 2 is a bit too much (you almost never get a break of either of the channel bands) so used default 1 for it and added an option with which you can modify Atr multiplier to some a bit more moderate one in order to get clear channel break outs.

According to your code on breaks of upper of lower band action1 or action2 should be taken but that I leave to the ones that use it : either as a counter trend or a breakout should be treated like a trend confirmation (from the example looks more like a counter trend one - with modest take profit targets it seems like a reasonable choice)

______________________

PS: AtrMultiplier 0 makes this indicator a classical Donchian channel indicator

 
Files:
 
Nice indicator. I've been wanting something like this for a while. Hoping to use it to help with my exits