M15 SP500 LowBuyHighSell Strategy
Forums › ProRealTime English forum › ProOrder support › M15 SP500 LowBuyHighSell Strategy
- This topic has 46 replies, 11 voices, and was last updated 11 months ago by nonetheless.
-
-
11/09/2023 at 1:18 AM #223398
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.M15 SP500 LBHS123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384//================================================//SP500//Spread 0.5DEFPARAM CUMULATEORDERS = falsedefparam preloadbars = 10000//Risk ManagementPositionSize = 5//Max-Orders per Day///////////////////////////////////////once maxOrdersL = 1once maxOrdersS = 1if intradayBarIndex = 0 then //reset orders countordersCountL = 0ordersCountS = 0endifif longTriggered then //check if an order has opened in the current barordersCountL = ordersCountL + 1endifif shortTriggered then //check if an order has opened in the current barordersCountS = ordersCountS + 1endif///////////////////////////////////////once TimeEx = 1once TimeEx2 = 1once Exit = 1timeframe(1day,updateonclose)myhigh = highmyclose= closemylow = lowmyopen = openmylowX = lowest[3](low) //1-20myhighX = highest[13](high)//1-20timeframe(default)area = myhigh-mylowlong = close < mylowX and ordersCountL < maxOrdersL //crosses overshort= close crosses under myhighX and ordersCountS < maxOrdersS// trading windowONCE BuyTime = 080000ONCE SellTime = 210000// position managementIF Time >= BuyTime AND Time <= SellTime THENIf long ThenBuy PositionSize CONTRACTS AT marketSET STOP LOSS area*0.4ENDIFIf short Thensellshort PositionSize CONTRACTS AT marketSET STOP LOSS area*1ENDIFendifgraphOnPrice mylowX coloured("Red")graphonprice myclose coloured("Black")graphOnPrice myhighX coloured("green")if longonmarket and close > myclose and Exit=1 thensell at marketendifif shortonmarket and close < myclose and Exit=1 thenexitshort at marketendif//TimeExif (time >= 220000 and TimeEx=1)thensell at marketexitshort at marketendifif time >= 220000 and dayofweek=5 and TimeEx2=1 thensell at marketexitshort at marketendif5 users thanked author for this post.
11/09/2023 at 8:51 AM #22340211/09/2023 at 9:15 AM #223403Feel free to make improvements to the code and adjust the time. If you set TimeEx to 0 in line 29, the result changes only minimally. In theory, you even get money if you hold the SP500 overnight. It is a short-term strategy. Little time on market. There are not many positions that are held overnight. I also tried to add another exit with a bigger profit. But this variant works very reliably. And that’s what I wanted. Short time on the market and “reliability”.
11/09/2023 at 9:17 AM #22340411/09/2023 at 9:30 AM #223407As a matter of interest then … what time are overnight fees triggered in Germany?
I’m just interrested if it is 22:00 same as UK even though Germany is currently UTC+1 and UK is currently UTC?
I can’t see German IG website to find out, maybe you can?
Whenever I have checked on UK IG re overnight fees it awlays says 22:00 so I guess it is 22:00 all year round regardless of the hour going forward or back (as now).
Maybe UTC+1 countries are the same at 22:00 all year round … anybody can answer?
End of hijacking your thread 🙂
Your strategy shows a good equity curve on DJI 1 Hour timeframe (no changes except minus 1 hour for UK on the UTC +1 times and I use spread = 5 for DJI when backtesting).
11/09/2023 at 9:36 AM #22340911/09/2023 at 9:49 AM #223410good equity curve on DJI 1 Hour timeframe
I forget how I work is not same as most … above is only over 10k bars.
Nearly blows the Account (£100k) at pos size = 1 over 100k bars so no point me posting an equity curve for 10K bars?
11/09/2023 at 10:13 AM #22341211/09/2023 at 10:54 AM #22341811/09/2023 at 2:36 PM #223435When backtesting u need to allow for varying spreads throughout the day, testing on 0.5 spread when spread can be 2 until US open wont give accurate results.
Can have some drawdown… would need some time to look more closely, but spreads can make a significant difference in strategy success when testing….
11/09/2023 at 5:05 PM #223445Hi Phoentzs, interesting code. I rewrote the code in the simplest form and added only a certain percentage to the exit. Up to 50k the results are similar, then are better.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667//SP "lowBuy-highSell" v2 15m [spread 0.5] //TS by Phoentzs//https://www.prorealcode.com/topic/m15-sp500-lowbuyhighsell-strategy///*********************************************************************************defParam cumulateOrders = falsedefParam preLoadBars = 10000defParam flatAfter = 220000cTime = time >= 080000 and time <= 210000positionSize = 5//-----------------------------------------------------------------------once maxOrdersL = 1 //max-Orders per Dayonce maxOrdersS = 1if intradayBarIndex = 0 then //reset orders countordersCountL = 0ordersCountS = 0endifif longTriggered then //check if an order has opened in the current barordersCountL = ordersCountL + 1endifif shortTriggered then //check if an order has opened in the current barordersCountS = ordersCountS + 1endif//------------------------------------------------------------timeframe(1 day, updateOnClose)//*********************************periodL = 3periodS = 13multiplierL = 0.4multiplierS = 1//*********************************dailyHigh = highdailyClose = closedailyLow = lowdailyOpen = opendailyLowX = lowest[periodL](low)dailyHighX = highest[periodS](high)areaDaily = dailyHigh - dailyLow//--------------------------------------------------------------timeframe(15 minutes)cLong = close < dailylowXcShort = close crosses under dailyHighXif cTime and cLong and ordersCountL < maxOrdersL thenbuy positionSize contracts at marketset stop loss areaDaily * multiplierLendifif longOnMarket and close > dailyClose and positionPerf*100 > 0.1 then // exit: gain > 0.1%sell at marketendif//----------------------if cTime and cShort and ordersCountS < maxOrdersS thensellshort positionSize contracts at marketset stop loss areaDaily * multiplierSendifif shortOnMarket and close < dailyClose and positionPerf*100 > 0.3 then // exit: gain > 0.3%exitShort at marketendif//---------------------------------------------------------------------------------------graphOnPrice dailyLowX coloured("red")graphonprice dailyClose coloured("black")graphOnPrice dailyHighX coloured("green")//---------------once equity = 0once performanceLastMonth = 0if month <> month[1] thenperformanceLastMonth = strategyProfit - equityequity = strategyProfitendifgraph performanceLastMonth11/09/2023 at 5:25 PM #22344811/11/2023 at 3:13 PM #22353911/11/2023 at 11:35 PM #223558Es ist wichtig, sich daran zu erinnern, dass wir hier über das SP500 sprechen. Vor fünf Jahren lag diese noch bei rund 2000 Punkten, die Volatilität war also sicherlich deutlich geringer. Wir arbeiten auf einen Lückenschluss hin, der auch heute noch manchmal nur wenige Punkte umfasst. Aber es scheint sicher, dass die Bewegung sehr oft auftreten wird, und wir können uns dieses Prinzip zunutze machen. Selbst wenn wir “highest and lowest” im Code auf “1” setzen, funktioniert das System trotzdem. Lediglich der Drawdown nimmt leicht zu und die Kurve ist etwas zackig. Probieren Sie das System an der Nasdaq aus… 😉
1 user thanked author for this post.
11/12/2023 at 5:21 PM #223612Test with a spread of 0.6 as this is the minimum at IG and the maximum is 1.4
Added buy and sell conditions1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768//SP "lowBuy-highSell" v2 15m [spread 0.5] //TS by Phoentzs//https://www.prorealcode.com/topic/m15-sp500-lowbuyhighsell-strategy///*********************************************************************************defParam cumulateOrders = falsedefParam preLoadBars = 10000defParam flatAfter = 220000cTime = time >= 080000 and time <= 210000positionSize = 1//-----------------------------------------------------------------------once maxOrdersL = 1 //max-Orders per Dayonce maxOrdersS = 1if intradayBarIndex = 0 then //reset orders countordersCountL = 0ordersCountS = 0endifif longTriggered then //check if an order has opened in the current barordersCountL = ordersCountL + 1endifif shortTriggered then //check if an order has opened in the current barordersCountS = ordersCountS + 1endif//------------------------------------------------------------timeframe(1 day, updateOnClose)//*********************************periodL = 3periodS = 13multiplierL = 0.4multiplierS = 1//*********************************dailyHigh = highdailyClose = closedailyLow = lowdailyOpen = opendailyLowX = lowest[periodL](low)dailyHighX = highest[periodS](high)areaDaily = dailyHigh - dailyLow//--------------------------------------------------------------timeframe(15 minutes)cLong = close < dailylowX and open>low and high>close and close-open>10cShort = close crosses under dailyHighX and high>open and close>lowif cTime and cLong and ordersCountL < maxOrdersL thenbuy positionSize contracts at marketset stop loss areaDaily * multiplierLendifif longOnMarket and close > dailyClose and positionPerf*100 > 0.1 then // exit: gain > 0.1%sell at marketendif//----------------------if cTime and cShort and ordersCountS < maxOrdersS thensellshort positionSize contracts at marketset stop loss areaDaily * multiplierSendifif shortOnMarket and close < dailyClose and positionPerf*100 > 0.3 then // exit: gain > 0.3%exitShort at marketendif//---------------------------------------------------------------------------------------graphOnPrice dailyLowX coloured("red")graphonprice dailyClose coloured("black")graphOnPrice dailyHighX coloured("green")//---------------once equity = 0once performanceLastMonth = 0if month <> month[1] thenperformanceLastMonth = strategyProfit - equityequity = strategyProfitendifgraph performanceLastMonth1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on