Hi all,
Im having some issues with a simple breakout system Im trying to code. The system works across 2 timeframes. We mark out the range of a 3 bar triangle on the daily and then trade the breakout on the H1.
Ive written the code which marks out the range and that seems to work nicely using the graphonprice function. However, the system fails to buy/sell every close above/below the range.
Can anyone spot what I’m doing wrong here?
Thanks in advance
Thally
// Cumulating positions deactivated
DEFPARAM CumulateOrders = False
// money management
ONCE Capital = 5000
ONCE Risk = 0.01
equity = Capital + StrategyProfit
maxrisk = round(equity*Risk)
// 3 bar triangle
timeframe(daily, updateonclose)
// Skip Sundays
IF OpenDayOfWeek = 0 THEN
myHigh = High[1] //store friday high if Sunday
ELSE
myHigh = High //else we store high
ENDIF
IF OpenDayOfWeek = 0 THEN
myLow = Low[1] //store friday high if Sunday
ELSE
myLow = Low //else we store high
ENDIF
// Mark out triangle
IF myHigh < myHigh[2] and myLow > myLow[2] THEN
BOhigh = myHigh
BOlow = myLow
ENDIF
graphonprice BOhigh COLOURED(100,149,237) AS "BOhigh"
graphonprice BOlow COLOURED(100,149,237) AS "BOlow"
timeframe(default)
// Stoploss and position size
StopLossL = abs(close - LOWEST[16](low))
PositionSizeL = abs(round((maxrisk/StopLossL)/PointValue)*pipsize)
StopLossS = abs(close - HIGHEST[16](high))
PositionSizeS = abs(round((maxrisk/StopLossS)/PointValue)*pipsize)
// Long
IF Not ONMARKET AND close > BOhigh AND close[1] < BOhigh THEN
BUY PositionSizeL PERPOINT AT MARKET
SET STOP LOSS StopLossL
ENDIF
// short
IF Not ONMARKET AND close < BOlow AND close[1] > BOlow THEN
SELLSHORT PositionSizeS PERPOINT AT MARKET
SET STOP LOSS StopLossS
ENDIF
Even if I just stick to the daily timeframe rather than dropping down to H1, its still not taking trades as it should. See how it only takes one break of the blue lines when it should take each one unless already in a trade.
Folks sorry for wasting your time. The issue was with the position size function and the starting capital. The rest of the logic works fine.
I’m please you have sorted it @Thally ,,, you can sleep better tonight also! 🙂
Cheers mate. Worth having a play with the indicator, it does a nice job of marking out areas of consolidation before expansion. Have good weekend.