Hi
Can someone please tell me what I'm doing wrong?
I have written an efs that marks an arrow when MA1 > MA2 & > PtY
I only want this to happen the first instance that this is true, not every time
I have managed to get it to work at MA crossover's but the same formula does not seem to work?
See efs below
Cheers all
var vSMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
var vSMA15 = new MAStudy(15, 0, "Close", MAStudy.SIMPLE);
var vUpTrend = null;
var vDownTrend = null;
var vLastAlert = -1;
var vValue = -1;
function preMain() {
setPriceStudy(true);
setStudyTitle("Print Value 2");
setCursorLabelName("5MA", 0);
setCursorLabelName("15MA", 1);
setCursorLabelName("Target1", 2);
setCursorLabelName("Target2", 3);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.maroon, 0);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarFgColor(Color.teal, 1);
setDefaultBarFgColor(Color.lime, 3);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
setPlotType(PLOTTYPE_FLATLINES, 2);
setDefaultBarFgColor(Color.red, 3);
setComputeOnClose(true)
}
debugClear()
function main() {
if (
myVar = sma( 5 ));
x = myVar + 2.5;
y = myVar -2.5;
{if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && (vValue != 1))
onAction3()}
{if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && (vValue != 2))
onAction4()}
{if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) < vDownTrend &&
(vLastAlert != 1)) drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.blue, Shape.BOTTOM);
vLastAlert = 1}
{if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) > vUpTrend &&
(vLastAlert != 2)) drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.purple, Shape.TOP);
vLastAlert = 2}
return new Array(
vSMA5.getValue(MAStudy.MA),
vSMA15.getValue(MAStudy.MA)
);
}
//{{Action_3
function onAction3() {
drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.BOTTOM);
debugPrintln("y= " + y);
drawLineRelative(0, (y), +25, (y), PS_SOLID, 2, Color.red, getValue("RawTime") + "xdownpt");
vDownTrend = y; debugPrintln("DownTrend = " + vDownTrend);
vValue = 1;
}
//}}Action_3
//{{Action_4
function onAction4() {
drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.RGB(0,255,0), Shape.TOP);
debugPrintln("x= " + x);
drawLineRelative(0, (x), +25, (x), PS_SOLID, 2, Color.green, getValue("RawTime") + "xuppt");
vUpTrend = x; debugPrintln("UpTrend = " + vUpTrend);
vValue = 2;}
//{{Action_4
Can someone please tell me what I'm doing wrong?
I have written an efs that marks an arrow when MA1 > MA2 & > PtY
I only want this to happen the first instance that this is true, not every time
I have managed to get it to work at MA crossover's but the same formula does not seem to work?
See efs below
Cheers all
var vSMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
var vSMA15 = new MAStudy(15, 0, "Close", MAStudy.SIMPLE);
var vUpTrend = null;
var vDownTrend = null;
var vLastAlert = -1;
var vValue = -1;
function preMain() {
setPriceStudy(true);
setStudyTitle("Print Value 2");
setCursorLabelName("5MA", 0);
setCursorLabelName("15MA", 1);
setCursorLabelName("Target1", 2);
setCursorLabelName("Target2", 3);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.maroon, 0);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarFgColor(Color.teal, 1);
setDefaultBarFgColor(Color.lime, 3);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
setPlotType(PLOTTYPE_FLATLINES, 2);
setDefaultBarFgColor(Color.red, 3);
setComputeOnClose(true)
}
debugClear()
function main() {
if (
myVar = sma( 5 ));
x = myVar + 2.5;
y = myVar -2.5;
{if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && (vValue != 1))
onAction3()}
{if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && (vValue != 2))
onAction4()}
{if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) < vDownTrend &&
(vLastAlert != 1)) drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.blue, Shape.BOTTOM);
vLastAlert = 1}
{if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) && vSMA5.getValue(MAStudy.MA) > vUpTrend &&
(vLastAlert != 2)) drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.purple, Shape.TOP);
vLastAlert = 2}
return new Array(
vSMA5.getValue(MAStudy.MA),
vSMA15.getValue(MAStudy.MA)
);
}
//{{Action_3
function onAction3() {
drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.BOTTOM);
debugPrintln("y= " + y);
drawLineRelative(0, (y), +25, (y), PS_SOLID, 2, Color.red, getValue("RawTime") + "xdownpt");
vDownTrend = y; debugPrintln("DownTrend = " + vDownTrend);
vValue = 1;
}
//}}Action_3
//{{Action_4
function onAction4() {
drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.RGB(0,255,0), Shape.TOP);
debugPrintln("x= " + x);
drawLineRelative(0, (x), +25, (x), PS_SOLID, 2, Color.green, getValue("RawTime") + "xuppt");
vUpTrend = x; debugPrintln("UpTrend = " + vUpTrend);
vValue = 2;}
//{{Action_4
Comment