Hello
This is my first attempt at creating an automated strategy!
The idea of the strategy is to only take trades between 9:00-13:00 (London time). And to only take trades with the current trend.
I have been using a version of this when trading manually for the last couple of months.
I don’t know how to make the bot look at different time aspects,so this one is only made in 15 min.
When i trade it manually i take in consideration of the 200 MA on the daily and don’t take trades on the wrong side of the 200 MA, but i don’t know how to add that into the automated system.
It definitely needs some tweaking, maybe someone can make something good out if it!
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 090000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 130000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = Average[200](close)
c1 = (close > indicator1)
indicator2 = SAR[0.02,0.02,0.2]
c2 = (close > indicator2)
indicator3 = Average[100](close)
c3 = (close > indicator3)
indicator4 = Average[50](close)
c4 = (close > indicator4)
indicator5 = RSI[14](close)
c5 = (indicator5 > 40)
c6 = (close > DLow(0))
IF (c1 AND c2 AND c3 AND c4 AND c5 AND c6) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
indicator6 = Average[200](close)
c7 = (close < indicator6)
indicator7 = SAR[0.02,0.02,0.2]
c8 = (close < indicator7)
indicator8 = Average[100](close)
c9 = (close < indicator8)
indicator9 = Average[50](close)
c10 = (close < indicator9)
indicator10 = RSI[14](close)
c11 = (indicator10 < 60)
IF (c7 AND c8 AND c9 AND c10 AND c11) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 30
SET TARGET pPROFIT 60
At line 27
c12 = (close > average[200,0](close))
and add C12 to your conditions at line 28
the reverse at line 43:
c13 = (close < average[200,0](close))
and add C13 to your conditions at line 44.
changed the SL TP and got a better return without any big changes to drawdown or time in market.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 090000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 130000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = Average[200](close)
c1 = (close > indicator1)
indicator2 = SAR[0.02,0.02,0.2]
c2 = (close > indicator2)
indicator3 = Average[50](close)
c3 = (close > indicator3)
indicator4 = Average[20](close)
c4 = (close > indicator4)
indicator5 = RSI[14](close)
c5 = (indicator5 > 40)
c6 = (close > DLow(0))
c12 = (close > average[200,0](close))
IF (c1 AND c2 AND c3 AND c4 AND c5 AND c6 and c12) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to enter short positions
indicator6 = Average[200](close)
c7 = (close < indicator6)
indicator7 = SAR[0.02,0.02,0.2]
c8 = (close < indicator7)
indicator8 = Average[50](close)
c9 = (close < indicator8)
indicator9 = Average[20](close)
c10 = (close < indicator9)
indicator10 = RSI[14](close)
c11 = (indicator10 < 40)
c13 = (close < average[200,0](close))
IF (c7 AND c8 AND c9 AND c10 AND c11 and c13) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 30
SET TARGET pPROFIT 70
You could try adding a trailing stop.
For the trailing stop I suggest to use the code from lines 17 to 56 at this link https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/.
Thank you for the idea!
will try it and see if i can get drawdown down perhaps