Hi,
I am trying to automate a scalping strategy I have come across. I did not publish it in the strategy section since it is clearly not profitable (yet :p )
Any help is welcome as I would be happy to work together to make this strategy profitable.
The initial strategy being:
Setup: is for price to move above the lower or lower Bollinger Bands, RSI raise above the 70 line or below the 30 line and Stochastic raise above the 80 line or below the 20 line at the same time.
Long Entry: price to move below the upper Bollinger Bands( deviation 2 and 20 period), RSI (7 period ) raise above the 30 line and Stochastic > 80 at the same time.
Short Entry: price to move above the upper Bollinger Bands( deviation 2 and 20 period), RSI (7 period ) raise below the 70 line and Stochastic < 20 at the same time.
Exit: Use Trailing Stop.
As you can see, when backtesting most trades are winning but the few losses are too big. I am running out of ideas to optimize it and to mitigate losses. The code is
DEFPARAM PreLoadBars = 100000
DEFPARAM CumulateOrders = False
//DEFPARAM FlatBefore = 070000
//DEFPARAM FlatAfter = 230000
// *** tendance courte *****************
M8=average[4,7](close) // 11
Tm8h=M8>M8[1]
Tm8b=M8<M8[1]
//************** Indicators Setup ****************
BD = BollingerDown[20](close)
BU = BollingerUp[20](close)
RS = RSI[7](close)
ST = Stochastic[5,3](close)
//*********** Strategy ***************
If High[close] > BU AND High[1] > BU AND RS > 65 AND ST > 40 AND Tm8h THEN
SELL 1 contract at market
ENDIF
If Low[close] < BD AND Low[1] < BD AND RS < 35 AND ST < 20 AND Tm8b THEN
BUY 1 contract at market
ENDIF
SET STOP pLOSS 50
//********* trailing stop function *************
trailingstartL = 10 //LONG trailing will start @trailingstart points profit
trailingstartS = 10 //SHORT trailing will start @trailingstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
Distance = 0 * PipSize
// SL = 15 // STOP LOSS
//******************** reset the Trailing Stop value *************
IF NOT ONMARKET THEN
TS=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move
IF TS=0 AND close-tradeprice(1)>=trailingstartL*pipsize THEN
TS = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF TS>0 AND close-TS>=trailingstep*pipsize THEN
TS = TS+trailingstep*pipsize
ENDIF
ENDIF
//******************** manage short positions *********************
IF SHORTONMARKET THEN
//first step
IF TS=0 AND tradeprice(1)-close>=trailingstartS*pipsize THEN
TS = tradeprice(1)-trailingstep*pipsize
ENDIF
//next steps
IF TS>0 AND TS-close>=trailingstep*pipsize THEN
TS = TS-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF TS>0 THEN
IF LongOnMarket THEN
IF (close - Distance) > TS THEN
SELL AT TS STOP
ELSIF (close + Distance) < TS THEN
SELL AT TS LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnMarket THEN
IF (close - Distance) > TS THEN
EXITSHORT AT TS LIMIT
ELSIF (close + Distance) < TS THEN
EXITSHORT AT TS STOP
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
WimParticipant
Junior
Hi K.,
Some remarks to get the going better. First your current strategy is not taking any shorts! The command for going short in PRT is SELLSHORT. In line 23 you hope that SELL will do the trick, but no. SELL is for closing a BUY, SELLSHORT is for selling, to be closed later by EXITSHORT.
Next little problem: High[Close] in line 22 and Low[Close] in line 26 do something, but most likely not what you want. High[AnyNumber] gives the high of the candle AnyNumber back in time. With the CAC around 7200 this will give you the High and Low of about 7200 minutes ago. If you replace High[Close] and Low[Close] both by Close, you will get some results. If you drop the long trades and only keep the short trades you might even win some money with this strategy. In my experience lots of scalping strategies perform better as either long only or short only robot.
And then there are the long and short conditions in the IF . . . THEN in lines 22 and 26. The logic programmed with these conditions doesn’t correspond to the text above the code in which you explain the strategy. I leave that up to you to resolve or improve this part. Hope this will help a little, good luck.
JSParticipant
Senior
Oops, crossing comments…
Here are some notes about your system…
The system only opens long positions because you use Sell instead of SellShort…
High[Close] and Low[Close] is not possible…
The input in your system does not match the description…
Thanks guys for your feedbacks. I’ll work on it.