Here is a strategy on the SP500, which in its raw version is already effective long and short. With similar settings the code is also effective on other indexes.
It is a mixture of gap close and mean reversion. We buy intraday below a low from the daily chart. We are selling above a high from the daily chart. The exit is the close of the previous day. So theoretically a gap closure. We exit open positions every evening and are flat overnight. A simple stoploss based on the daily range is also included in the algo. That’s all. Improvements and/or thoughts on this algo are always welcome.
//================================================
//SP500
//Spread 0.5
DEFPARAM CUMULATEORDERS = false
defparam preloadbars = 10000
//Risk Management
PositionSize = 5
//Max-Orders per Day///////////////////////////////////////
once maxOrdersL = 1
once maxOrdersS = 1
if intradayBarIndex = 0 then //reset orders count
ordersCountL = 0
ordersCountS = 0
endif
if longTriggered then //check if an order has opened in the current bar
ordersCountL = ordersCountL + 1
endif
if shortTriggered then //check if an order has opened in the current bar
ordersCountS = ordersCountS + 1
endif
///////////////////////////////////////
once TimeEx = 1
once TimeEx2 = 1
once Exit = 1
timeframe(1day,updateonclose)
myhigh = high
myclose= close
mylow = low
myopen = open
mylowX = lowest[3](low) //1-20
myhighX = highest[13](high)//1-20
timeframe(default)
area = myhigh-mylow
long = close < mylowX and ordersCountL < maxOrdersL //crosses over
short= close crosses under myhighX and ordersCountS < maxOrdersS
// trading window
ONCE BuyTime = 080000
ONCE SellTime = 210000
// position management
IF Time >= BuyTime AND Time <= SellTime THEN
If long Then
Buy PositionSize CONTRACTS AT market
SET STOP LOSS area*0.4
ENDIF
If short Then
sellshort PositionSize CONTRACTS AT market
SET STOP LOSS area*1
ENDIF
endif
graphOnPrice mylowX coloured("Red")
graphonprice myclose coloured("Black")
graphOnPrice myhighX coloured("green")
if longonmarket and close > myclose and Exit=1 then
sell at market
endif
if shortonmarket and close < myclose and Exit=1 then
exitshort at market
endif
//TimeEx
if (time >= 220000 and TimeEx=1)then
sell at market
exitshort at market
endif
if time >= 220000 and dayofweek=5 and TimeEx2=1 then
sell at market
exitshort at market
endif