Hi All,
First time post for me. I wouldn’t turn to this forum unless I had tried everything myself first. I have created an algo that reflects my current strategy. It’s not a ‘World Beating’ strategy by any means.
As you will see by the code – I’m probably less than a rookie and have pieced this together with a base level code from the ‘builder’ and slowly added and tweaked it to fit my individual needs from others (JuanJ, Nicholas). But I guess that’s the point of the network! 😀
It tests well, and hits my current personal targets when backtesting, but when I have unleashed it, it hasn’t yet made a trade. Of course, this could be due to the parameters not being met, but when I then backtest, it shows trades being made that were not reflected in real time when the algo was on.
I wondered if I could have an eye cast to double check I hadn’t done anything silly. It seems to have not yet made a trade, since I added the breakeven addition (created by the infamous Nicholas). It’s likely due to me not including it properly.
Hugely appreciate any guidance.
Best Tom
// 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 = 000000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 240000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
If dayofweek >= 5 and hour > 22 Then
If longonmarket Then
Sell at market
ElsIf shortonmarket Then
Exitshort at market
EndIf
EndIf
AA = period
ATR = AverageTrueRange[2](close)
//Breakeven functionality
startBreakeven = 30//pips to gain before breakeven functionality
PointsToKeep = 5 //pips to keep in profit above or below entry price when breakeven is activated
// Conditions to enter long positions
indicator1 = Average[100](close)
c1 = (close > indicator1)
indicator2 = RSI[2](close)
c2 = (indicator2 > 70)
indicator3 = Average[AA](close)+1.618*std[AA](close)
c3 = (close[1] > indicator3)
indicator4 = Average[AA](close)+1.618*std[AA](close)
c4 = (close > indicator4)
c5 = (open > open[2])
IF (c1 AND c2 AND c3 AND c4 AND c5) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY 5 CONTRACT AT MARKET
SET STOP pTRAILING 50
ENDIF
// Conditions to enter long positions #2
indicator5 = Average[100](close)
c6 = (close < indicator5)
indicator6 = RSI[2](close)
c7 = (indicator6 > 50)
indicator7 = Average[AA](close)-1.618*std[AA](close)
c8 = (close[1] < indicator7)
indicator8 = Average[AA](close)-1.618*std[AA](close)
c9 = (close > indicator8)
IF c6 AND c7 AND c8 AND c9 THEN
BUY 5 CONTRACT AT MARKET
SET STOP pTRAILING 50
ENDIF
IF NOT ONMARKET THEN
breakevenLevel=0
Endif
IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
ENDIF
IF breakevenLevel>0 THEN
SELL AT breakevenLevel STOP
ENDIF
// Conditions to exit long positions
indicator9 = Average[AA](close)+1.618*std[AA](close)
c10 = (close[2] > indicator9)
indicator10 = Average[AA](close)+1.618*std[AA](close)
c11 = (close[1] > indicator10)
indicator11 = Average[AA](close)+1.618*std[AA](close)
c12 = (close < indicator11)
indicator12 = Average[AA](close)+1.618*std[AA](close)
c13 = (high[1] > indicator12)
indicator13 = Average[AA](close)+1.618*std[AA](close)
c14 = (high < indicator13)
IF c10 AND c11 AND c12 AND c13 AND c14 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator10 = Average[100](close)
c11 = (close > indicator10)
indicator11 = RSI[2](close)
c12 = (indicator11 < 50)
indicator12 = Average[AA](close)+1.618*std[AA](close)
c13 = (close[1] > indicator12)
indicator13 = Average[AA](close)+1.618*std[AA](close)
c14 = (close < indicator13)
IF (c11 AND c12 AND c13 AND c14) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
SELLSHORT 5 CONTRACT AT MARKET
SET STOP pTRAILING 50
ENDIF
//Conditions to enter short positions #2
indicator14 = Average[100](close)
c15 = (close < indicator14)
indicator15 = RSI[2](close)
c16 = (indicator15 < 40)
indicator16 = Average[AA](close)-1.618*std[AA](close)
c17 = (close[1] < indicator16)
indicator17 = Average[AA](close)-1.618*std[AA](close)
c18 = (close < indicator17)
c19 = (open < open[2])
IF c15 AND c16 AND c17 AND c18 AND c19 THEN
SELLSHORT 5 CONTRACT AT MARKET
SET STOP pTRAILING 50
ENDIF
IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN
//calculate the breakevenLevel
breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
ENDIF
//place the new stop orders on market at breakevenLevel
IF breakevenLevel>0 THEN
EXITSHORT AT breakevenLevel STOP
ENDIF
// Conditions to exit short positions
indicator14 = Average[AA](close)-1.618*std[AA](close)
c15 = (close[2] < indicator14)
indicator15 = Average[AA](close)-1.618*std[AA](close)
c16 = (close[1] < indicator15)
indicator16 = Average[AA](close)-1.618*std[AA](close)
c17 = (low[2] < indicator16)
indicator17 = Average[AA](close)-1.618*std[AA](close)
c18 = (low[1] > indicator17)
IF c15 AND c16 AND c17 AND c18 THEN
EXITSHORT AT MARKET
ENDIF
If (indicator2 > 95) Then
Sell at market
ElsIf ((close > close[1] + ATR) or SHORTONMARKET) and indicator2 < 5 Then
Exitshort at market
EndIf
What is AA period used please?
How many maximum contracts do you allowed in ProOrder when launching the strategy?
Hi Nicholas,
Thanks for coming back so quickly – real pleasure to get your support.
AA is the variable label I use for the bollinger band period – I run an optimisation from 1 to 100 to understand the best n period for that pair.
I do a maximum of 2 contracts currently – I plucked it from the air tbh.
I hope I explained that clearly.
Tom
Your code is taking 5 Contracts so you need to set maximum when you start the Algo in ProOrder to at least 5 (I would set to 10 to allow for a switch in direction)
Thanks GraHal – Seems so obvious in hindsight! 😀 I’ll give it a go….
That’s why I asked in the first place 😉