Hi,
I'm getting a syntax error on the else if logic in "stop loss/profit exit" part of the the following code. I dont understand why? I'm sure its very simple!
Thanks
I'm getting a syntax error on the else if logic in "stop loss/profit exit" part of the the following code. I dont understand why? I'm sure its very simple!
PHP Code:
var vDonch = null;
var vDonchExit = null;
var nNewTrade;
var nSignal;
var nTradeEntryPrice;
var nStopLevel;
var atrLevel;
var inTrade;
function preMain() {
setPriceStudy(true);
setStudyTitle("Donchian");
setCursorLabelName("Upper", 0);
setCursorLabelName("Lower", 1);
setColorPriceBars(true);
setDefaultBarFgColor (Color. blue, 0);
setDefaultBarFgColor (Color. red, 1);
setDefaultBarThickness(1, 0);
setDefaultBarThickness(1, 1);
setDefaultPriceBarColor(Color.black);
}
function main() {
if (vDonch == null) vDonch = new DonchianStudy (20,0);
if (vDonch2 == null) vDonch2 = new DonchianStudy (10,0);
// identify entry price
if (Strategy.isInTrade() == true && (nNewTrade == 1)) {
nTradeEntryPrice = open();
nNewTrade = 0;
atrLevel = atr(20);
if (Strategy.isLong() == true) setPriceBarColor(Color.green);
if (Strategy.isShort() == true) setPriceBarColor(Color.red);
}
//stop loss/profit exit
if (Strategy.isLong() == true && (Strategy.isInTrade() == true));
if (low() <= (nTradeEntryPrice - nStopLevel)); {
Strategy.doSell("Stop Sell", Strategy.LIMIT, Strategy,THISBAR, Strategy.ALL,nStopLevel);
inTrade = 0;
}
else if (low() <= vDonch2.getValue(DonchianStudy.LOWER, -1)) {
var longExit = vDonch2.getValue(DonchianStudy.LOWER, -1));
if (open() < longExit) longExit = open();
Strategy.doSell("10 day low",Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,longExit);
inTrade = 0;
}
if (Strategy.isShort() == true && (Strategy.isInTrade() == true));
if (high() >= (nTradeEntryPrice + nStopLevel)); {
Strategy.doCover("Cover",Strategy.LIMIT, Strategy,THISBAR,Strategy.ALL,nStopLevel);
inTrade = 0;
}
else if (high() >= vDonch2.getValue(DonchianStudy.UPPER, -1)) {
var shortExit = vDonch2.getValue(DonchianStudy.UPPER, -1));
if (open() > shortExit) shortExit = open();
Strategy.doSell("10 day low",Strategy.LIMIT,Strategy.THISBAR,Strategy.ALL,shortExit);
inTrade = 0;
}
//identify entry signal
if inTrade == 0;
if high() >= vDonch.getValue(DonchianStudy.UPPER, -1)) {
nNewTrade = 1;
nSignal = 1;
nStopLevel = nTradeEntryPrice - (atrLevel * 2);
}
if inTrade == 0;
if low() <= vDonch.getValue(DonchianStudy.LOWER, -1)) {
nNewTrade = 1;
nSignal = -1;
nStopLevel = nTradeEntryPrice + (atrLevel * 2);
}
//execute trade
if(nNewTrade == 1) && (nSignal > 0) {
Strategy.doLong("Long", Strategy.MARKET, Strategy.NEXTBAR);
inTrade = 1;
}
if(nNewTrade == 1) && (nSignal < 0) {
Strategy.doShort("Short", Strategy.MARKET, Strategy.NEXTBAR);
inTrade = 1;
}
return new Array
(vDonch.getValue (DonchianStudy.UPPER),
vDonch.getValue (DonchianStudy.LOWER),
vDonch2.getValue (DonchianStudy.UPPER),
vDonch2.getValue (DonchianStudy.LOWER));
}
Comment