Please, I need some help to merge the two formulas below (MACD + MOVTREND (Rafter) to work togheter setting the bars colors, blue (buy) and red (sell):
If MACD>0 and if(wt>wt_1)
setBarFgColor(Color.blue);
and
If MACD <0 and if(wt<wt_1)
setBarFgColor(Color.red);
/************************************************** *******
Alexis C. Montenegro © July 2003
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
************************************************** ********/
var vMACD = null;
function preMain() {
setStudyTitle("MACD");
setCursorLabelName("MACDHist",0);
setCursorLabelName("MACD",1);
setCursorLabelName("MACDSig",2);
setDefaultBarFgColor(Color.magenta,0);
setDefaultBarFgColor(Color.blue,1);
setDefaultBarFgColor(Color.red,2);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
setPlotType(PLOTTYPE_HISTOGRAM);
var fp1 = new FunctionParameter("Fast", FunctionParameter.NUMBER);
fp1.setLowerLimit(1);
fp1.setDefault(12); //Edit this value to set a new default
var fp2 = new FunctionParameter("Slow", FunctionParameter.NUMBER);
fp2.setLowerLimit(1);
fp2.setDefault(26); //Edit this value to set a new default
var fp3 = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
fp3.setLowerLimit(1);
fp3.setDefault(9); //Edit this value to set a new default
var fp4 = new FunctionParameter("Source", FunctionParameter.STRING);
fp4.setName("Source");
fp4.addOption("Close");
fp4.addOption("High");
fp4.addOption("Low");
fp4.addOption("Open");
fp4.addOption("HL/2");
fp4.addOption("HLC/3");
fp4.addOption("OHLC/4");
fp4.setDefault("Close"); //Edit this value to set a new default
var fp5 = new FunctionParameter("TypeOsc", FunctionParameter.BOOLEAN);
fp5.setName("SMA (Oscillator)");
fp5.setDefault(false); //Edit this value to set a new default
var fp5 = new FunctionParameter("TypeSig", FunctionParameter.BOOLEAN);
fp5.setName("SMA (Signal)");
fp5.setDefault(true); //Edit this value to set a new default
}
function main(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig) {
if (vMACD == null) vMACD = new MACDStudy(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig);
/*********************************************
Insert your code following this text block
Use vMACD.getValue(MACDStudy.HIST) and
vMACD.getValue(MACDStudy.MACD) and
vMACD.getValue(MACDStudy.SIGNAL) for your code
**********************************************/
return new Array (vMACD.getValue(MACDStudy.HIST),vMACD.getValue(MAC DStudy.MACD),vMACD.getValue(MACDStudy.SIGNAL));
}
PLUS
function preMain()
{
setStudyTitle("Movtrend");
setCursorLabelName("Movtrend", 0);
setDefaultBarFgColor(Color.white, 0);
setPlotType(PLOTTYPE_INSTANTCOLORLINE);
setDefaultBarThickness(2, 0);
setPriceStudy(true);
}
var wt = null;
var wt_1 = null;
function main(n) {
if(n == null)
n = 34;
var sum = 0;
var i = 0;
if(getBarState()==BARSTATE_NEWBAR){
wt_1 = wt;
}
for(i = n; i > 0; i--)
sum += (i - (n + 1) / 3) * close(i - n);
wt = 6 / (n * (n + 1)) * sum;
if(wt>wt_1)
setBarFgColor(Color.blue);
if(wt<wt_1)
setBarFgColor(Color.red);
return wt;
}
If MACD>0 and if(wt>wt_1)
setBarFgColor(Color.blue);
and
If MACD <0 and if(wt<wt_1)
setBarFgColor(Color.red);
/************************************************** *******
Alexis C. Montenegro © July 2003
Use and/or modify this code freely. If you redistribute it
please include this and/or any other comment blocks and a
description of any changes you make.
************************************************** ********/
var vMACD = null;
function preMain() {
setStudyTitle("MACD");
setCursorLabelName("MACDHist",0);
setCursorLabelName("MACD",1);
setCursorLabelName("MACDSig",2);
setDefaultBarFgColor(Color.magenta,0);
setDefaultBarFgColor(Color.blue,1);
setDefaultBarFgColor(Color.red,2);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
setPlotType(PLOTTYPE_HISTOGRAM);
var fp1 = new FunctionParameter("Fast", FunctionParameter.NUMBER);
fp1.setLowerLimit(1);
fp1.setDefault(12); //Edit this value to set a new default
var fp2 = new FunctionParameter("Slow", FunctionParameter.NUMBER);
fp2.setLowerLimit(1);
fp2.setDefault(26); //Edit this value to set a new default
var fp3 = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
fp3.setLowerLimit(1);
fp3.setDefault(9); //Edit this value to set a new default
var fp4 = new FunctionParameter("Source", FunctionParameter.STRING);
fp4.setName("Source");
fp4.addOption("Close");
fp4.addOption("High");
fp4.addOption("Low");
fp4.addOption("Open");
fp4.addOption("HL/2");
fp4.addOption("HLC/3");
fp4.addOption("OHLC/4");
fp4.setDefault("Close"); //Edit this value to set a new default
var fp5 = new FunctionParameter("TypeOsc", FunctionParameter.BOOLEAN);
fp5.setName("SMA (Oscillator)");
fp5.setDefault(false); //Edit this value to set a new default
var fp5 = new FunctionParameter("TypeSig", FunctionParameter.BOOLEAN);
fp5.setName("SMA (Signal)");
fp5.setDefault(true); //Edit this value to set a new default
}
function main(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig) {
if (vMACD == null) vMACD = new MACDStudy(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig);
/*********************************************
Insert your code following this text block
Use vMACD.getValue(MACDStudy.HIST) and
vMACD.getValue(MACDStudy.MACD) and
vMACD.getValue(MACDStudy.SIGNAL) for your code
**********************************************/
return new Array (vMACD.getValue(MACDStudy.HIST),vMACD.getValue(MAC DStudy.MACD),vMACD.getValue(MACDStudy.SIGNAL));
}
PLUS
function preMain()
{
setStudyTitle("Movtrend");
setCursorLabelName("Movtrend", 0);
setDefaultBarFgColor(Color.white, 0);
setPlotType(PLOTTYPE_INSTANTCOLORLINE);
setDefaultBarThickness(2, 0);
setPriceStudy(true);
}
var wt = null;
var wt_1 = null;
function main(n) {
if(n == null)
n = 34;
var sum = 0;
var i = 0;
if(getBarState()==BARSTATE_NEWBAR){
wt_1 = wt;
}
for(i = n; i > 0; i--)
sum += (i - (n + 1) / 3) * close(i - n);
wt = 6 / (n * (n + 1)) * sum;
if(wt>wt_1)
setBarFgColor(Color.blue);
if(wt<wt_1)
setBarFgColor(Color.red);
return wt;
}
Comment