I am new to the forum and to EFS, so apologies if this is very basic. All help is sincerely appreciated!
I am using a simple moving average, long and short strategy. The problem is that when I make any parameter changes on the LONG side, i.e say I change the 'close' from (-1) to (-2), I don't see any changes in the chart when the old study is removed and the new study is applied. For that matter, even if I change the 'close' to 'open', I don't see any changes to the resultant chart when the new study is applied. However, if I comment out, the SHORT part of the code, then all changes I make are taking effect.
What am I doing wrong?
.....I have commented the different parts for LONG and SHORT side of the code for your reference....
function preMain() {
setPriceStudy(true);
setStudyTitle("Back Test: Simple Moving Average");
setCursorLabelName("SMA", 0);
setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
}
// Global Variables
var xSMA = null;
var bInit = false; // initialization flag
function main() {
if (getCurrentBarIndex() == 0) return;
if(bInit == false) {
xSMA = sma(13);
bInit = true;
}
var nSma = xSMA.getValue(-1);
if(nSma == null) return;
// LONG Trade Signal
if (Strategy.isLong() == false && close (-1) >= nSma ) {
Strategy.doLong("Long Signal", Strategy.MARKET, Strategy.THISBAR);
} else if (Strategy.isLong() == true && close(-1) < nSma ) { // Long Exit Signal
Strategy.doSell("Long Exit Signal", Strategy.MARKET, Strategy.THISBAR);
}
// SHORT Trade Signal
if (Strategy.isShort() == false && close(-1) <= nSma) {
Strategy.doShort("Short Signal", Strategy.MARKET, Strategy.THISBAR);
} else if (Strategy.isShort() == true && close(-1) > nSma) { // Short Exit Signal
Strategy.doLong("Short Exit Signal", Strategy.MARKET, Strategy.THISBAR);
}
if(Strategy.isLong()) {
setBarBgColor(Color.darkgreen);
}else if(Strategy.isShort()) {
setBarBgColor(Color.grey);
}
return xSMA.getValue(0);
}
I am using a simple moving average, long and short strategy. The problem is that when I make any parameter changes on the LONG side, i.e say I change the 'close' from (-1) to (-2), I don't see any changes in the chart when the old study is removed and the new study is applied. For that matter, even if I change the 'close' to 'open', I don't see any changes to the resultant chart when the new study is applied. However, if I comment out, the SHORT part of the code, then all changes I make are taking effect.
What am I doing wrong?
.....I have commented the different parts for LONG and SHORT side of the code for your reference....
function preMain() {
setPriceStudy(true);
setStudyTitle("Back Test: Simple Moving Average");
setCursorLabelName("SMA", 0);
setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
}
// Global Variables
var xSMA = null;
var bInit = false; // initialization flag
function main() {
if (getCurrentBarIndex() == 0) return;
if(bInit == false) {
xSMA = sma(13);
bInit = true;
}
var nSma = xSMA.getValue(-1);
if(nSma == null) return;
// LONG Trade Signal
if (Strategy.isLong() == false && close (-1) >= nSma ) {
Strategy.doLong("Long Signal", Strategy.MARKET, Strategy.THISBAR);
} else if (Strategy.isLong() == true && close(-1) < nSma ) { // Long Exit Signal
Strategy.doSell("Long Exit Signal", Strategy.MARKET, Strategy.THISBAR);
}
// SHORT Trade Signal
if (Strategy.isShort() == false && close(-1) <= nSma) {
Strategy.doShort("Short Signal", Strategy.MARKET, Strategy.THISBAR);
} else if (Strategy.isShort() == true && close(-1) > nSma) { // Short Exit Signal
Strategy.doLong("Short Exit Signal", Strategy.MARKET, Strategy.THISBAR);
}
if(Strategy.isLong()) {
setBarBgColor(Color.darkgreen);
}else if(Strategy.isShort()) {
setBarBgColor(Color.grey);
}
return xSMA.getValue(0);
}
Comment