DislikedAll,
I have made some ammendments to Comokes work to now include the trailing stop, and from what I can see (on Euro Futures for 2005), it appears to be a nice strategy as tkimble has indeed been saying. This is tested without money management which can only enhance it as tkimble has correctly stated.
My backtest confirmed everything he has been saying, and the drawdown appears to suit me anyway.
Of course, this is my data that it has been tested on, and would like input from anybody out there to see how they get on with the code. (e-sig of course), and in different markets.
tkimble - I hope this helps, I can of course add/change things within this code, and would be happy to. But thanks for your information so far.
If anybody can find fault in my logic, please shout, nobody is infallable.
Its below, I have used tkimbles revised rules for keeping out of some of the whip:
var nStop=0;
function preMain() {
setPriceStudy(true);
setColorPriceBars(true);
setStudyTitle("Forex Factory");
setShowTitleParameters(false);
}
var nStop = 0;
var nLimit = 0;
var nStopDiff = 0.005;
var nLimitDiff = 0.02;
var tickDiff = 0.0005;
function main() {
//if in one not already, enter a long trade
if(!Strategy.isLong()) {
if(close() > (sma(9, high()) + tickDiff) && rsi(45) > 50 ){
Strategy.doLong("Going Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
nLimit = close() + (nLimitDiff);
nStop = close(-1) - (nStopDiff);
}
}
//if not in one already, enter a short trade
if(!Strategy.isShort()) {
if(close() < (sma(9, low()) - tickDiff) && rsi(45)< 50 ) {
Strategy.doShort("Going Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
nLimit = close() - (nLimitDiff);
nStop = close(-1) + (nStopDiff);
}
}
//set the bar colours - green for long, red for short, black for neutral
if (Strategy.isInTrade()) {
if(Strategy.isLong()) {
if (close(-2)<close(-1)){
nStop += (close(-1)-close(-2));
}
setBarBgColor(Color.teal)
setPriceBarColor(Color.lime);
if (close()< nStop){
Strategy.doSell("Close Long Stop", Strategy.STOP, Strategy.THISBAR, Strategy.ALL, nStop);
}
if (close() > nLimit){
Strategy.doSell("Close Long Target", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nLimit);
}
}
if(Strategy.isShort()) {
if (close(-2)>close(-1)){
nStop -= (close(-2)-close(-1));
}
setPriceBarColor(Color.red);
setBarBgColor(Color.lightgrey);
if (close()> nStop){
Strategy.doCover("Close Short Stop", Strategy.STOP, Strategy.THISBAR, Strategy.ALL, nStop);
}
if (close() < nLimit){
Strategy.doCover("Close Short Target", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nLimit);
}
}
}
return 0;
}Ignored
cheers,
Paul