Is it possible to change the Heikin-ashi (smoothed) study into a price study where the price bars change color instead of it being a separate study under price ? Or maybe a background change as the candles change ?
Announcement
Collapse
No announcement yet.
Heikin-ashi (smoothed)price bar color
Collapse
X
-
here is my attempt ( needs help)
/************************************************** ***************
Provided By : eSignal. (c) Copyright 2003
EFS Formula : Heikin-Ashi
Version 2.0
9/13/2004
Notes:
* Non-price study
* Draws most recent 200 bars
* Formula Parameters
- Bullish Color Default: Green
- Bearish Color Default: Red
- Smoothing Default: None [None, T3, KAMA]
* 2.0 Added T3 and KAMA smoothing options per
http://warrants.bnpparibas.com/de/doc/WZ_0804.pdf (page 16)
************************************************** ***************/
function preMain() {
setColorPricebars(true);
setPriceStudy(true)
setStudyTitle("Heikin-Ashi w/ Smoothing ");
setCursorLabelName("HA-High", 0);
setCursorLabelName("HA-Low", 1);
setCursorLabelName("HA-Open", 2);
setCursorLabelName("HA-Close", 3);
setDefaultBarFgColor(Color.black, 0);
setDefaultBarFgColor(Color.black, 1);
setDefaultBarFgColor(Color.black, 2);
setDefaultBarFgColor(Color.black, 3);
setPlotType(PLOTTYPE_DOT, 0);
setPlotType(PLOTTYPE_DOT, 1);
setPlotType(PLOTTYPE_DOT, 2);
setPlotType(PLOTTYPE_DOT, 3);
setDefaultBarThickness(1, 0);
setDefaultBarThickness(1, 1);
setDefaultBarThickness(1, 2);
setDefaultBarThickness(1, 3);
setShowTitleParameters(false);
var fp1 = new FunctionParameter("cBull", FunctionParameter.COLOR);
fp1.setName("Bullish Candles");
fp1.setDefault(Color.lime);
var fp2 = new FunctionParameter("cBear", FunctionParameter.COLOR);
fp2.setName("Bearish Candles");
fp2.setDefault(Color.red);
var fp3 = new FunctionParameter("sSmooth", FunctionParameter.STRING);
fp3.setName("Smoothing");
fp3.addOption("None");
fp3.addOption("T3");
fp3.addOption("KAMA");
fp3.setDefault("T3");
var fp4 = new FunctionParameter("nT3Periods", FunctionParameter.NUMBER);
fp4.setName("T3 Periods");
fp4.setLowerLimit(1);
fp4.setDefault(3);
var fp5 = new FunctionParameter("vFactor", FunctionParameter.NUMBER);
fp5.setName("T3 V Factor");
fp5.setLowerLimit(0);
fp5.setDefault(0.5);
var fp6 = new FunctionParameter("nKAMAPeriods", FunctionParameter.NUMBER);
fp6.setName("KAMA Periods");
fp6.setLowerLimit(2);
fp6.setDefault(2);
}
var haClose = null;
var haOpen = null;
var haClose1 = null;
var haOpen1 = null;
var iCntr = 0;
// T3 vars
var b = null; // V Factor
var b2 = null;
var b3 = null;
var c1 = null;
var c2 = null;
var c3 = null;
var c4 = null;
var f1 = null;
var f2 = null;
var e1 = null;
var e2 = null;
var e3 = null;
var e4 = null;
var e5 = null;
var e6 = null;
var e1_1 = 0;
var e2_1 = 0;
var e3_1 = 0;
var e4_1 = 0;
var e5_1 = 0;
var e6_1 = 0;
var Price = null;
var bInit = false;
// KAMA vars
var nBarCounter = 0;
var aAMA = null;
var aFPArray = new Array();
var bInitialized = false;
var bPrimed = false;
function main(cBull, cBear, sSmooth, nT3Periods, vFactor, nKAMAPeriods) {
var nState = getBarState();
if (nState == BARSTATE_NEWBAR) {
if ((haClose == null || haOpen == null) && close(-1) != null) {
haClose = close(-1);
haOpen = open(-1);
}
haClose1 = haClose;
haOpen1 = haOpen;
iCntr += 1;
if (iCntr > 200) iCntr = 0;
}
if (haClose1 == null || haOpen1 == null) return;
haOpen = (haOpen1 + haClose1) / 2;
haClose = (open() + high() + low() + close()) / 4;
if (sSmooth == "T3") {
setStudyTitle("Heikin-Ashi w/ " + nT3Periods + "-Period T3 Smoothing ");
haClose = T3Avg(nT3Periods, vFactor, haClose);
} else if (sSmooth == "KAMA") {
setStudyTitle("Heikin-Ashi w/ " + nKAMAPeriods + "-Period KAMA Smoothing ");
haClose = KAMA(nKAMAPeriods, haClose);
} else {
setStudyTitle("Heikin-Ashi w/out Smoothing ");
}
if (haClose == null) return;
var haHigh = Math.max(high(), haOpen, haClose);
var haLow = Math.min(low(), haOpen, haClose);
//candlesticks
if (haClose > haOpen) vColor = cBull;
setPriceBarColor(Color.red);
else if (haClose < haOpen) vColor =cBear;
setPriceBarColor(Color.lime);
else if (1 == 1)
setPriceBarColor(Color.black);
drawLineRelative(0, haHigh, 0, haLow, PS_SOLID, 2, Color.white, "Shadow"+iCntr);
drawLineRelative(0, haOpen, 0, haClose, PS_SOLID, 7, vColor, "Body"+iCntr);
var retArray = new Array(4);
retArray[0] = haHigh.toFixed(2)*1;
retArray[1] = haLow.toFixed(2)*1;
retArray[2] = haOpen.toFixed(2)*1;
retArray[3] = haClose.toFixed(2)*1;
return retArray;
}
//*** T3 ****
function T3Avg(nPeriods, vFactor, vPrice) {
if (bInit == false) {
b = vFactor;
b2 = b * b;
b3 = b * b * b;
c1 = -b3;
c2 = 3 * b2 + 3 * b3;
c3 = -6 * b2 - 3 * b - 3 * b3;
c4 = 1 + 3 * b + b3 + 3 * b2;
f1 = 2 / (nPeriods + 1);
f2 = 1 - f1;
bInit = true;
}
if (getBarState() == BARSTATE_NEWBAR) {
e1_1 = e1;
e2_1 = e2;
e3_1 = e3;
e4_1 = e4;
e5_1 = e5;
e6_1 = e6;
}
e1 = f1 * vPrice + f2 * e1_1;
e2 = f1 * e1 + f2 * e2_1;
e3 = f1 * e2 + f2 * e3_1;
e4 = f1 * e3 + f2 * e4_1;
e5 = f1 * e4 + f2 * e5_1;
e6 = f1 * e5 + f2 * e6_1;
var T3Average = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3;
return T3Average;
}
//*** END of T3 Functions ****
//*** KAMA ****
function KAMA(Period, vClose) {
var x;
var nNoise;
var nSignal;
var nSmooth;
if (bInitialized == false) {
Period = Math.round(Period);
aAMA = new Array(Period);
for ( x=0; x<Period; x++ ) {
aAMA[x] = 0.0;
}
bInitialized = true;
}
if ( getBarState() == BARSTATE_NEWBAR ) {
aAMA.pop();
aAMA.unshift(0);
nBarCounter++;
}
if (nBarCounter<Period) return null;
if (bPrimed == false) {
aAMA[0] = (open(0)+close(0)) / 2 + ( ( (close(0)-open(0)) / (high(0)-low(0)) ) * Math.abs( (close(0)-open(0)) / 2) );
bPrimed = true;
return aAMA[0];
} else {
aAMA[0] = vClose;
}
nSignal = Math.abs( close(0) - close(-Period) );
x=0;
nNoise = 0;
while(x<Period) {
nNoise += Math.abs( close(-x)-close(-(x+1)) );
x++;
}
if ( nNoise==0 ) nNoise = 1.0;//added by ACM
nSmooth = Math.pow( ( nSignal/nNoise ) * ( 0.6667 - 0.0645 ) + 0.0645, 2 );
aAMA[0] = aAMA[1] + nSmooth * ( close(0) - aAMA[1] );
return aAMA[0];
}
//*** END of KAMA ****
-
colours
The attached should do what you asked.
Alex
Attached Files
Comment
Comment