I realize that this code is really basic, for some reason it doesn't work. The problem seems to be with the v variable, because I've used the other variables and they work, so I rem'd out un-needed code.
function preMain() {
setPriceStudy(true);
setStudyTitle("Bollinger Bands");
setCursorLabelName("UpperBB", 0 );
setCursorLabelName("MiddleBB", 1 );
setCursorLabelName("LowerBB", 2 );
setDefaultBarFgColor(Color.red, 0); // upper
setDefaultBarFgColor(Color.blue, 1); // middle
setDefaultBarFgColor(Color.green, 2); // lower
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
}
var studybb = new BollingerStudy(20, "Close", 2.0);
var studyma = new MAStudy(40, 0, "Close", MAStudy.SIMPLE);
function main() {
var vUpper = studybb.getValue(BollingerStudy.UPPER);
var vMiddle = studybb.getValue(BollingerStudy.BASIS);
var vLower = studybb.getValue(BollingerStudy.LOWER);
var v = studyma.getValue(MAStudy.MA);
if(Strategy.isLong()) setPriceBarColor(Color.lime);
if(Strategy.isShort()) setPriceBarColor(Color.red);
if(close() > v)
Strategy.doLong("Going Up", Strategy.LIMIT, Strategy.THISBAR, null, vLower);
if(close() < v)
Strategy.doShort("Going Down", Strategy.LIMIT, Strategy.THISBAR, null, vUpper);
return new Array(vUpper, vMiddle, vLower);
}
function preMain() {
setPriceStudy(true);
setStudyTitle("Bollinger Bands");
setCursorLabelName("UpperBB", 0 );
setCursorLabelName("MiddleBB", 1 );
setCursorLabelName("LowerBB", 2 );
setDefaultBarFgColor(Color.red, 0); // upper
setDefaultBarFgColor(Color.blue, 1); // middle
setDefaultBarFgColor(Color.green, 2); // lower
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
}
var studybb = new BollingerStudy(20, "Close", 2.0);
var studyma = new MAStudy(40, 0, "Close", MAStudy.SIMPLE);
function main() {
var vUpper = studybb.getValue(BollingerStudy.UPPER);
var vMiddle = studybb.getValue(BollingerStudy.BASIS);
var vLower = studybb.getValue(BollingerStudy.LOWER);
var v = studyma.getValue(MAStudy.MA);
if(Strategy.isLong()) setPriceBarColor(Color.lime);
if(Strategy.isShort()) setPriceBarColor(Color.red);
if(close() > v)
Strategy.doLong("Going Up", Strategy.LIMIT, Strategy.THISBAR, null, vLower);
if(close() < v)
Strategy.doShort("Going Down", Strategy.LIMIT, Strategy.THISBAR, null, vUpper);
return new Array(vUpper, vMiddle, vLower);
}
Comment