Hello All,
I have asked the forum a couple of questions over the years I have been using IG Index PRT and have always been met with helpfulness and creativity.
I now find myself with a strategy that works really well but requires sitting in front of the computer screen waiting for the dozen or so triggers each day as attempts to use alert services, including PRT’s own alerts didn’t pick up each trigger.
The strategy is based on the FTSE 5 minute chart and I have written and rewritten the code over 150 times and am questioning my own logic ability.
The simple strategy lends itself to automation but try as I might PRT doesn’t do what I thought it might and I can’t find documentation that explains why this happens.
With a FTSE 5 minute bar chart showing price and the PSAR indicator (see attached) starting at 08.00 GMT through to market close I am looking for the PSAR to cross over or cross under to signal the start of the strategy.
With the SAR going from red to green I am looking for the next bar to be green (updated on close) that is with close being higher than open.
With the SAR going from green to red The next bar needs to be red i.e. with the open price being higher than the close (likewise update on close).
The two other possibilities of green SAR and red bar as well as red SAR and green first bar on change do not qualify and the strategy will not start and we wait for the next SAR crossover.
Given that I get a RED SAR and RED BAR or a GREEN SAR and GREEN BAR the next step is to note threshold levels.
If the GREEN SAR has A GREEN BAR then the value of HIGH + 1 for that bar is noted – called it ‘loft’.
If the RED SAR has a RED BAR as then the value of LOW – 1 for that bar is noted – which I have called ‘dell’.
If subsequent bars do not exceed loft for GREEN/GREEN first bar or dell for a RED/RED first bar then nothing is done till next crossover and SAR/BAR.
If the loft value is met then a BUY is triggered with a TARGET of 10 and a STOP of 20.
If the dell value is met then a SELLSHORT is triggered with a TARGET of 10 and a STOP of 20.
If the TARGET is not met then the BUY or SELLSHORT trade is closed at the next crossover.
So far straightforward – but BUY/SELLSHORT/EXIT etc. happen in the next bar by which time I am looking to open a new SAR/BAR loft or dell value.
Using TIMEFRAME I looked for SAR crossover in 5 minute TF and setting loft/dell in 5 minute Uupdate On Close and then using 20 second or less TF for BUY/SELL or EXIT.
I can’t make it work !!!!!!!
Here’s a recent iteration of my code:
//FTSE SAR XOVER 5 min 20221110 1330
DEFPARAM CUMULATEORDERS = FALSE
DEFPARAM FLATBEFORE = 080000
DEFPARAM FLATAFTER = 160000
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 // OR exchange holidays here once working
dealtime = (time>=140000 AND time=<200000) AND not daysforbiddenEntry
contractsize = 1
//##################################################################
TIMEFRAME(3 minutes) // ##### 3-minutes bar OPEN #####
//##################################################################
IF dealtime THEN
change = 0
gchange = 0
rchange = 0
mysar = SAR[0.02,0.02,0.2]
greensar = close > mySAR
redsar = close < mySAR
gchange = redsar[1] AND greensar
rchange = greensar[1] AND redsar
change = (redsar[1] AND greensar) OR (greensar[1] AND redsar)
ENDIF
//##################################################################
TIMEFRAME(3 minutes,updateonclose) // ##### 3-minutes bar UOC #####
//##################################################################
IF dealtime THEN
IF gchange AND NOT ONMARKET AND open >= close THEN
loft = HIGH + 4
ENDIF
IF rchange AND NOT ONMARKET AND open =< close THEN
dell = LOW – 4
ENDIF
ENDIF
//##################################################################
TIMEFRAME(default) // #### timeframe to place order quickly e.g. 20 sec #####
//##################################################################
IF dealtime AND change AND ONMARKET THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
IF dealtime AND NOT ONMARKET THEN
IF gchange AND (HIGH >= loft) THEN
BUY contractsize CONTRACT AT MARKET
ENDIF
IF rchange AND (LOW =< dell) THEN
SELLSHORT contractsize CONTRACT AT MARKET
ENDIF
SET target $profit 40
SET stop ploss 80
ENDIF
GRAPH gchange coloured(0,255,0)
GRAPH rchange coloured(255,0,0)
GRAPH change coloured(0,0,255)
Any ideas please … I feel I should be able to do it but “I can’t see the wood for the trees” as the saying says.