What's wrong with this code?
I have a switch if turn on it will draw a vertical line and if the Symbol is changed the switch is turn Off and the line is deleted.
Thank you very much
ketma
var vMA1 = null;
var sSymbol1 = null;
var sSymbol2 = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("10MA");
setCursorLabelName("10MA", 0);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarThickness(2, 0);
setPlotType(PLOTTYPE_LINE, 0);
var fp1 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
fp1.setLowerLimit(1);
fp1.setDefault(10); //Edit this value to set a new default
var fp2 = new FunctionParameter("MA1Offset", FunctionParameter.NUMBER);
fp2.setDefault(0); //Edit this value to set a new default
var fp3 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
fp3.setName("MA1Source");
fp3.addOption("Close");
fp3.addOption("High");
fp3.addOption("Low");
fp3.addOption("Open");
fp3.addOption("HL/2");
fp3.addOption("HLC/3");
fp3.addOption("OHLC/4");
fp3.setDefault("Close"); //Edit this value to set a new default
var fp4 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
fp4.setName("MA1Type");
fp4.addOption("MAStudy.SIMPLE");
fp4.addOption("MAStudy.EXPONENTIAL");
fp4.addOption("MAStudy.WEIGHTED");
fp4.addOption("MAStudy.VOLUMEWEIGHTED");
fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp5 = new FunctionParameter("Vert", FunctionParameter.NUMBER);
fp5.setDefault(0); //Edit this value to set a new default
}
function main(MA1Length,MA1Offset,MA1Source,MA1Type,Vert) {
if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Offset, MA1Source, eval(MA1Type));
if (Vert == 1) {
if (sSymbol2 == null){
sSymbol2 = getSymbol();
}
sSymbol1 = getSymbol();
if (sSymbol1 == sSymbol2) {
drawLineRelative(-1, -100, -1, 100, PS_SOLID, 2, Color.grey, 0 );
} else {
Vert = 0;
removeLine( 0 );
}
}
return (vMA1.getValue(MAStudy.MA));
}
I have a switch if turn on it will draw a vertical line and if the Symbol is changed the switch is turn Off and the line is deleted.
Thank you very much
ketma
var vMA1 = null;
var sSymbol1 = null;
var sSymbol2 = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("10MA");
setCursorLabelName("10MA", 0);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarThickness(2, 0);
setPlotType(PLOTTYPE_LINE, 0);
var fp1 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
fp1.setLowerLimit(1);
fp1.setDefault(10); //Edit this value to set a new default
var fp2 = new FunctionParameter("MA1Offset", FunctionParameter.NUMBER);
fp2.setDefault(0); //Edit this value to set a new default
var fp3 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
fp3.setName("MA1Source");
fp3.addOption("Close");
fp3.addOption("High");
fp3.addOption("Low");
fp3.addOption("Open");
fp3.addOption("HL/2");
fp3.addOption("HLC/3");
fp3.addOption("OHLC/4");
fp3.setDefault("Close"); //Edit this value to set a new default
var fp4 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
fp4.setName("MA1Type");
fp4.addOption("MAStudy.SIMPLE");
fp4.addOption("MAStudy.EXPONENTIAL");
fp4.addOption("MAStudy.WEIGHTED");
fp4.addOption("MAStudy.VOLUMEWEIGHTED");
fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp5 = new FunctionParameter("Vert", FunctionParameter.NUMBER);
fp5.setDefault(0); //Edit this value to set a new default
}
function main(MA1Length,MA1Offset,MA1Source,MA1Type,Vert) {
if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Offset, MA1Source, eval(MA1Type));
if (Vert == 1) {
if (sSymbol2 == null){
sSymbol2 = getSymbol();
}
sSymbol1 = getSymbol();
if (sSymbol1 == sSymbol2) {
drawLineRelative(-1, -100, -1, 100, PS_SOLID, 2, Color.grey, 0 );
} else {
Vert = 0;
removeLine( 0 );
}
}
return (vMA1.getValue(MAStudy.MA));
}
Comment