Hi
I have been trying to code a SAR entry with no success.
What I am after is after a set entry time the next change in SAR colour we enter a trade.
Eg at 0800 SAR is green and so no orders at that point. On the next reverse (red) we go short and vice a versa.
Is it then possible on the next reverse to enter as well? So for above SAR turns green and we go long.
So just the initial SAR colour is ignored at the start time of the algo
Many thanks for any guidance
There you go:
DEFPARAM CumulateOrders = FALSE
MySAR = SAR[0.02,0.02,0.2]
Green = close > MySAR
Red = close < MySAR
Change = (Green AND Red[1]) OR (Green[1] AND Red)
MyTime = 080000
IF MyTime = 080000 THEN
Change = 0
ENDIF
// LONG
IF Change AND Green AND Not LongOnMarket THEN
BUY 1 Contract AT Market
ENDIF
// SHORT
IF Change AND Red AND Not ShortOnMarket THEN
SELLSHORT 1 Contract AT Market
ENDIF
Change from red to green (and vice-versa) with Parabolic SAR can be detected with Close CROSSES OVER or Close CROSSES UNDER.
Hello,
I have tried at length to develop another step to the SAR entry and have had no luck.
I am hoping fresh eyes could suggest a way forward :-
On a five minute timeframe I want to detect a change (crossover) in the SAR from Red to Green or vice versa … then in the bar of the change I want to be able to detect if the bar is the same colour as the SAR upon close (otherwise, say green SAE and red bar, it is ignored).
If it is the same colour I want to store the ‘HIGH’ value of the bar if it is green or the LOW value of the bar if ithe bar and SAR are red.
Over the following bars – until the next crossover – I want to check the ‘CLOSE’ of the bars to check if they are higher than the ‘HIGH’ if the bar of the crossover (if green) or lower than the ‘LOW’ of the first bar after the crossover if it was red (only one transaction – either BUY or SELLSHORT per inter SAR crossover).
If higher then I would like to BUY a contract as quickly as possible and correspondingly if lower than the stored low I would like to SELLSHORT a contract. When this happens there should be not be any further transactions till the after next crossover.
I hope this makes sense as I have spent days, if not weeks, playing around with MTF and ARRAYS to try and make it return a consistent result and have failed.
Thank you in anticipation,
Joe
There you go:
// MySystemSAR
//
// https://www.prorealcode.com/topic/sar-entry/
//
ONCE Read = 1
ONCE Green = 1
ONCE ChangePrice = 0
Bullish = close > open
Bearish = close < open
MySAR = SAR[0.02,0.02,0.2]
IF Red THEN
Green = close CROSSES OVER MySAR
IF Green THEN
Red = 0
ChangePrice = 0
IF Bullish AND Not OnMarket THEN
ChangePrice = high
ENDIF
ENDIF
ENDIF
IF Green THEN
Red = close CROSSES UNDER MySAR
IF Red THEN
Green = 0
ChangePrice = 0
IF Bearish AND Not OnMarket THEN
ChangePrice = low
ENDIF
ENDIF
ENDIF
IF ChangePrice <> 0 AND Not OnMarket THEN
IF Green AND close > ChangePrice THEN
BUY 1 CONTRACT AT MARKET
ChangePrice = 0
ENDIF
IF Red AND close < ChangePrice THEN
SELLSHORT 1 CONTRACT AT MARKET
ChangePrice = 0
ENDIF
END IF
SET TARGET pPROFIT 300
SET STOP pLOSS 100
graphonprice ChangePrice
Thank You,
I can see that was focussing on the crossover too much … very elegant code!
Thank you again,
Joe