Good morning,
I would like to have an help from you. I translated this code from easy language. It runs and I could test it, but since I relayed the function "strategy.dolong" with "buyatmarket", the code doesn't read the exit rules and, if the initial condition is still true, it buys again.
What it doesn't work in this manner? How I should modify the code with the generic broker function? Could you make an example?
I paste only the incriminated part for the long version.
Thanks.
Enrico
var vSMA40 = new MAStudy(40, 0, "Close", MAStudy.SIMPLE);
function main() {
var Dev = StdDev(40);
if ((Strategy.isLong() == false) &&
close() >= vSMA40.getValue(MAStudy.MA) + 2*Dev)
{
// Long entry
Strategy.doLong("Enterlong", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
}
else if (Strategy.isLong() == true && close() < vSMA40.getValue(MAStudy.MA))
{
// Long exit
Strategy.doSell("Exitlong", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
drawShapeRelative(0, high() + (high() - low())/4,
}
I would like to have an help from you. I translated this code from easy language. It runs and I could test it, but since I relayed the function "strategy.dolong" with "buyatmarket", the code doesn't read the exit rules and, if the initial condition is still true, it buys again.
What it doesn't work in this manner? How I should modify the code with the generic broker function? Could you make an example?
I paste only the incriminated part for the long version.
Thanks.
Enrico
var vSMA40 = new MAStudy(40, 0, "Close", MAStudy.SIMPLE);
function main() {
var Dev = StdDev(40);
if ((Strategy.isLong() == false) &&
close() >= vSMA40.getValue(MAStudy.MA) + 2*Dev)
{
// Long entry
Strategy.doLong("Enterlong", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
}
else if (Strategy.isLong() == true && close() < vSMA40.getValue(MAStudy.MA))
{
// Long exit
Strategy.doSell("Exitlong", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
drawShapeRelative(0, high() + (high() - low())/4,
}
Comment