I have a code and want to have the colors shown on the chart if it is Long or Short (and have it work so I can back test it). Near the end of the code (colored purple) this line will not work,
Strategy.doLong("Long Signal", Strategy.CLOSE, Strategy.THISBAR);
can any one tell me why?
Here is the code (the part related to the function):
Strategy.doLong("Long Signal", Strategy.CLOSE, Strategy.THISBAR);
can any one tell me why?
Here is the code (the part related to the function):
Code:
function Calc_VWEMA(Length) { var nRes = 0; var nRes1 = 0; var nMAVolPrice = 0; var nMAVolPrice1 = 0; var nMAVol = 0; var nMAVol1 = 0; if (!bSecondInit) { xMAVolPrice = ema(Length, efsInternal("CalcVolPrice")); xMAVol = ema(Length, volume()); bSecondInit = true; } nMAVolPrice = xMAVolPrice.getValue(0); nMAVol = xMAVol.getValue(0); nMAVolPrice1 = xMAVolPrice.getValue(-1 ); nMAVol1 = xMAVol.getValue(-1); if (nMAVolPrice == null || nMAVol == null || nMAVol == 0) return; nRes = nMAVolPrice / nMAVol; nRes1 = nMAVolPrice1 / nMAVol1; if(nRes > nRes1) { if(!Strategy.isLong()) { debugPrintln(1,nRes," ",nRes1); //This line works, why does the next two lines not work? [color=purple]Strategy.doLong("Long Signal", Strategy.CLOSE, Strategy.THISBAR); setBarBgColor(Color.RGB(222,254,223))[/color]; // Light Green } } else { if(!Strategy.isShort()) { [color=purple]Strategy.doShort("Short Signal", Strategy.CLOSE, Strategy.THISBAR); setBarBgColor(Color.RGB(255,222,221))[/color]; // Light Red } } return nRes; }
Comment