Hello,
I try to write a very simple efs file just to learn programming.
The strategy is the next one:
* go long if lower bollinger band (2 STD) crossed
cover this long position as soon as
basis BB(2STD) crossed or lower BB(3STD) is also crossed
* go short if Upper BB (2 STD) crossed
cover this short position as soon as
basis BB(2STD) crossed or upper BB(3STD) is also crossed
I wrote the following program:
var vBollinger2 = new BollingerStudy(20, "Close", 2);
var vStop3 = new BollingerStudy(20, "Close", 3);
function preMain() {
setPriceStudy(true);
setStudyTitle("Bollinger Bands Piercing");
}
function main() {
if (close() < vBollinger2.getValue(BollingerStudy.LOWER))
{Strategy.doLong("Crossing Up",Strategy.CLOSE,Strategy.THISBAR);}
if (close() > vBollinger2.getValue(BollingerStudy.UPPER))
{Strategy.doShort("Crossing Down",Strategy.CLOSE,Strategy.THISBAR);}
if (Strategy.isLong()) { if (close() > vBollinger2.getValue(BollingerStudy.BASIS))
{Strategy.doSell("Close Long",Strategy.MARKET,Strategy.THISBAR);}}
if (Strategy.isLong()) { if (close() < vStop3.getValue(BollingerStudy.LOWER))
{Strategy.doSell("Close Long",Strategy.MARKET,Strategy.THISBAR);}}
if (Strategy.isShort()) { if (close() < vBollinger2.getValue(BollingerStudy.BASIS))
{Strategy.doCover("Close Short",Strategy.MARKET,Strategy.THISBAR);}}
if (Strategy.isShort()) { if (close() > vStop3.getValue(BollingerStudy.UPPER))
{Strategy.doCover("Close Short",Strategy.MARKET,Strategy.THISBAR);}}
}
but there is a bug in this program as the result of this strategy is that on each bar there is a Crossing Down & a Close short...
Do you see where is the problem?
Thanks
I try to write a very simple efs file just to learn programming.
The strategy is the next one:
* go long if lower bollinger band (2 STD) crossed
cover this long position as soon as
basis BB(2STD) crossed or lower BB(3STD) is also crossed
* go short if Upper BB (2 STD) crossed
cover this short position as soon as
basis BB(2STD) crossed or upper BB(3STD) is also crossed
I wrote the following program:
var vBollinger2 = new BollingerStudy(20, "Close", 2);
var vStop3 = new BollingerStudy(20, "Close", 3);
function preMain() {
setPriceStudy(true);
setStudyTitle("Bollinger Bands Piercing");
}
function main() {
if (close() < vBollinger2.getValue(BollingerStudy.LOWER))
{Strategy.doLong("Crossing Up",Strategy.CLOSE,Strategy.THISBAR);}
if (close() > vBollinger2.getValue(BollingerStudy.UPPER))
{Strategy.doShort("Crossing Down",Strategy.CLOSE,Strategy.THISBAR);}
if (Strategy.isLong()) { if (close() > vBollinger2.getValue(BollingerStudy.BASIS))
{Strategy.doSell("Close Long",Strategy.MARKET,Strategy.THISBAR);}}
if (Strategy.isLong()) { if (close() < vStop3.getValue(BollingerStudy.LOWER))
{Strategy.doSell("Close Long",Strategy.MARKET,Strategy.THISBAR);}}
if (Strategy.isShort()) { if (close() < vBollinger2.getValue(BollingerStudy.BASIS))
{Strategy.doCover("Close Short",Strategy.MARKET,Strategy.THISBAR);}}
if (Strategy.isShort()) { if (close() > vStop3.getValue(BollingerStudy.UPPER))
{Strategy.doCover("Close Short",Strategy.MARKET,Strategy.THISBAR);}}
}
but there is a bug in this program as the result of this strategy is that on each bar there is a Crossing Down & a Close short...
Do you see where is the problem?
Thanks
Comment