Hi, Sorry to post this in a way, I have tried to look it up in the support website, but the links appear to be broken.
I am attempting some position management, and I have the logic and everything working fine for the backtest (thanks to one of your great documents). I am now attempting to put some generic broker functions in for forward testing, but I am having trouble trading out of half the position, leaving a runner. The idea is to scalp for 10 tics, leave a runner on for the rest. I have it running in backtest as I say, but I guess I am struggling to structure that in Generic broker.
Any advive would be great, here is the buy/sell code below for long:
Buy:
Strategy.doLong("Going Long", Strategy.MARKET, Strategy.NEXTBAR, 2 );
vTarget=(close(0)+nScalp);
buyMarket( getSymbol(), 2 );
if ( nStop = (2.5 * xATR.getValue(-1)) < 0.0050 ){
nStop = close(0) - (2.5 * xATR.getValue(-1));
} else {
nStop=(close(0) -0.0050);
}
}
Sell:
if (close()< nStop){
Strategy.doSell("Close Long Stop", Strategy.STOP, Strategy.THISBAR, Strategy.ALL, nStop);
nStop=null;
vScalp=false;
closeAllPositions()
} else if (vScalp == false){
var nLot = Math.abs(Math.round(Strategy.getPositionSize()/2));
if (high(0) >= vTarget) {
vScalp=true;
Strategy.doSell("Close Long Scalp", Strategy.LIMIT, Strategy.THISBAR, nLot, vTarget);
sellLimit(getSymbol(), 1, vTarget);
}
Thanks a lot.
I am attempting some position management, and I have the logic and everything working fine for the backtest (thanks to one of your great documents). I am now attempting to put some generic broker functions in for forward testing, but I am having trouble trading out of half the position, leaving a runner. The idea is to scalp for 10 tics, leave a runner on for the rest. I have it running in backtest as I say, but I guess I am struggling to structure that in Generic broker.
Any advive would be great, here is the buy/sell code below for long:
Buy:
Strategy.doLong("Going Long", Strategy.MARKET, Strategy.NEXTBAR, 2 );
vTarget=(close(0)+nScalp);
buyMarket( getSymbol(), 2 );
if ( nStop = (2.5 * xATR.getValue(-1)) < 0.0050 ){
nStop = close(0) - (2.5 * xATR.getValue(-1));
} else {
nStop=(close(0) -0.0050);
}
}
Sell:
if (close()< nStop){
Strategy.doSell("Close Long Stop", Strategy.STOP, Strategy.THISBAR, Strategy.ALL, nStop);
nStop=null;
vScalp=false;
closeAllPositions()
} else if (vScalp == false){
var nLot = Math.abs(Math.round(Strategy.getPositionSize()/2));
if (high(0) >= vTarget) {
vScalp=true;
Strategy.doSell("Close Long Scalp", Strategy.LIMIT, Strategy.THISBAR, nLot, vTarget);
sellLimit(getSymbol(), 1, vTarget);
}
Thanks a lot.
Comment