Hey everyone,
I am attempting to code a backtest of a strategy I have been developing, but after I hit the "Test" button, the dialog box that pops shows that no trades have been recorded. I am wondering where the problem might lie in my code. Here it is:
Thanks so much for your help!
Best,
Jake
I am attempting to code a backtest of a strategy I have been developing, but after I hit the "Test" button, the dialog box that pops shows that no trades have been recorded. I am wondering where the problem might lie in my code. Here it is:
PHP Code:
var study = null;
function preMain() {
setPriceStudy(true);
setColorPriceBars(true);
setDefaultPriceBarColor(Color.black);
}
function main() {
if(study == null) study = atr(3);
var ATR = study.getValue(0);
if(ATR == null)
return;
var N = ATR + .01;
var dailyHigh = high(0, inv("D"));
var dailyLow = low(0, inv("D"));
var dailyOpen = open(0, inv("D"));
var longPrice = dailyHigh + .02;
if(high(0) < dailyHigh && high(-1) < dailyHigh && high(-2) < dailyHigh && high(-3) < dailyHigh){
Strategy.doLong("Buying new high", Strategy.STOP, 400, longPrice);
if(Strategy.getPositionSize() == 400)
Strategy.setStop(longPrice - N);
if(Strategy.isLong() == true && N < .05 && Strategy.getPositionSize() == 400)
Strategy.doSell("Selling 1/4 position for 2R", Strategy.LIMIT, 100, longPrice + .10);
if(Strategy.getPositionSize() == 300) {
Strategy.clearStop();
Strategy.setStop(longPrice - N); }
if(Strategy.isLong() == true && N < .05 && Strategy.getPositionSize() == 300)
Strategy.doSell("Selling 1/4 position for 3R", Strategy.LIMIT, 100, longPrice + .10 + (2*N));
if(Strategy.getPositionSize() == 200) {
Strategy.clearStop();
Strategy.setStop(longPrice); }
if(Strategy.isLong() == true && N < .05 && Strategy.getPositionSize() == 200)
Strategy.doSell("Selling remaining position for 4R", Strategy.LIMIT, 200, longPrice + .10 + (4*N));
if(Strategy.isLong() == true && N >= .05 && Strategy.getPositionSize() == 400)
Strategy.doSell("Selling 1/4 position for 2R", Strategy.LIMIT, 100, longPrice + (2*N));
if(Strategy.getPositionSize() == 300)
Strategy.clearStop();
Strategy.setStop(longPrice - N);
if(Strategy.isLong() == true && N >= .05 && Strategy.getPositionSize() == 300)
Strategy.doSell("Selling 1/4 position for 3R", Strategy.LIMIT, 100, longPrice + (3*N));
if(Strategy.getPositionSize() == 200) {
Strategy.clearStop();
Strategy.setStop(longPrice); }
if(Strategy.isLong() == true && N >= .05 && Strategy.getPositionSize() == 200)
Strategy.doSell("Selling remaining position for 4R", Strategy.LIMIT, 200, longPrice + (4*N));
if(Strategy.getPositionSize() == 0)
Strategy.clearStop();
return ATR;
}
Best,
Jake
Comment