Pinbar on MA + Validation
Forums › ProRealTime English forum › ProBuilder support › Pinbar on MA + Validation
- This topic has 4 replies, 2 voices, and was last updated 10 months ago by ChristosDG.
-
-
01/17/2024 at 8:48 AM #226450
Hello everyone,
I’m trying to build a detector for pinbars on 1 minute charts rebounding on H1 & D1 moving averages, pinbars followed by a validation candlestick (meaning that the following candlestick has to at least break the pinbar in its intended direction).
I’m confused… it doesn’t work that well…
Meaning by that that many pinbars on MA remain undetected.
Would you please have a look?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071// ParametersmyATR = AverageTrueRange[14](close[1])distance = 10*TICKSIZE// MAtimeframe(1 hour)MA20H1 = Average[20](close)MA50H1 = Average[50](close)MA200H1 = Average[200](close)timeframe(1 day)MA20D1 = Average[20](close)MA50D1 = Average[50](close)MA200D1 = Average[200](close)timeframe(1 minute)IF Close[1] > MA20H1 - distance AND Close[1] < MA20H1 THENresult = 2ELSIF Close[1] < MA20H1 + distance AND Close[1] > MA20H1 THENresult = 1ELSIF Close[1] > MA50H1 - distance AND Close[1] < MA50H1 THENresult = 2ELSIF Close[1] < MA50H1 + distance AND Close[1] > MA50H1 THENresult = 1ELSIF Close[1] > MA20D1 - distance AND Close[1] < MA20D1 THENresult = 2ELSIF Close[1] < MA20D1 + distance AND Close[1] > MA20D1 THENresult = 1ELSIF Close[1] > MA50D1 - distance AND Close[1] < MA50D1 THENresult = 2ELSIF Close[1] < MA50D1 + distance AND Close[1] > MA50D1 THENresult = 1ELSIF Close[1] > MA200H1 - distance AND Close[1] < MA200H1 THENresult = 2ELSIF Close[1] < MA200H1 + distance AND Close[1] > MA200H1 THENresult = 1ELSIF Close[1] > MA200D1 - distance AND Close[1] < MA200D1 THENresult = 2ELSIF Close[1] < MA200D1 + distance AND Close[1] > MA200D1 THENresult = 1ELSEresult = 0ENDIF// Pinbar + validation + MAIF result = 2 THENIF close[1] + myATR > close[0] + 3*TICKSIZE OR close[1] - myATR < close[0] - 3*TICKSIZE THENIF (high[1] - low[1]) > 2*abs(close[1] - open[1]) THENIF (close[1] < open[1]) AND (open[1] - low[1]) < 0.33*(high[1] - low[1]) OR (close[1] - low[1]) < 0.33*(high[1]-low[1]) AND open[0] < (high[1] - myATR) THENDRAWARROWDOWN(barindex[1],high[1]+6*TICKSIZE)coloured(255,10,10)ELSIF (close[1] < open[1]) AND (open[1] - low[1]) < 0.33*(high[1] - low[1]) OR (close[1] - low[1]) < 0.33*(high[1]-low[1]) AND open[0] > (high[1] - myATR) THENDRAWARROWDOWN(barindex[1],high[1]+6*TICKSIZE)coloured(255,10,10)ENDIFENDIFENDIFELSIF result = 1 THENIF close[1] + myATR > close[0] + 3*TICKSIZE OR close[1] - myATR < close[0] - 3*TICKSIZE THENIF (high[1] - low[1]) > 2*abs(close[1] - open[1]) THENIF (open[1] < close[1]) AND (high[1] - open[1]) < 0.33*(high[1] - low[1]) OR (high[1] - close[1]) < 0.33*(high[1]-low[1]) AND open[0] > (low[1] + myATR) THENDRAWARROWUP(barindex[1],low[1]-6*TICKSIZE)coloured(10,255,10)ELSIF (open[1] < close[1]) AND (high[1] - open[1]) < 0.33*(high[1] - low[1]) OR (high[1] - close[1]) < 0.33*(high[1]-low[1]) AND open[0] > (low[1] + myATR) THENDRAWARROWUP(barindex[1],low[1]-6*TICKSIZE)coloured(10,255,10)ENDIFENDIFENDIFENDIFRETURNThanks a bunch!
01/18/2024 at 10:33 AM #226501Hi,
There are many “if”, it is likely a pinbar you consider should have been detected is filtered away by the combination of ifs, the best way to proceed is to name your all conditions for each “if”, not just the ones in “timeframe(1mn)” but also these in “Pinbar + validation + MA”, for example c1=… , c2=… , and add use “if c1 then if c2 then…”, but you can choose more explicit variable names to know right away what each condition is about if you wish. Then you can add them to your return line, and display this indicator second version in a separate pane.
return c1 as “c1”, c2 as “c2”, etc…
This way, when you see a pinbar you consider should have been detected instead of filtered away, you can check exactly what condition isn’t met in the separate pane of conditions. From there, you can conclude whether it was in fact rightly undetected and no modifiction is needed, or if it’s an error to fix in the code not reflecting your desired criteria now knowing exactly what condition is at fault.
01/19/2024 at 2:11 AM #226562Thanks for the suggestion.
I made a few tweaks to the code.
And as to be able to test it correctly, I just use a small part of the code, instead of the whole thing (see below).
My main preoccupation for the moment is that, no matter what I input as “Average[XX](close)”, the rebound only happen on the MA 20 1 minute (where XX = 1200 periods = H1).
I don’t see what’s wrong in the code, really…
// If you wish to change the time unit, don’t forget to adjust the periods of the moving averages (according to the stockmarket’s open hours as well)
// Parameters
myATR = AverageTrueRange[14](close[1]) // Confirmation distance of the pattern from the highest / lowest of the pinbar (on the next candlestick)
distance = 6*PIPSIZE // Limit within which the pinbar must be contained (around each moving average)ma11 = Average[1200](close) // Moving average 20 (H1) in a 1 minute time unit (for markets open from 9h to 17h30)
// Patterns within MA distance
c01 = High[1] < ma11 + distance AND High[1] > ma11 // High contained above and in the defined limit around the MA
c02 = High[1] > ma11 – distance AND High[1] < ma11 // High contained below and in the defined limit around the MA
c03 = Close[1] < ma11 + distance AND Close[1] > ma11 // Close contained above and in the defined limit around the MA
c04 = Close[1] > ma11 – distance AND Close[1] < ma11 // Close contained below and in the defined limit around the MA
c05 = Low[1] < ma11 + distance AND Low[1] > ma11 // Low contained above and in the defined limit around the MA
c06 = Low[1] > ma11 – distance AND Low[1] < ma11 // Low contained below and in the defined limit around the MA
c07 = High[1] > Open[1] AND High[1] > Close[1] // High > Open & Close
c08 = Low[1] < Open[1] AND Low[1] < Close[1] // Low < Open & Close// MA – Only 1 MA on 3 kept / Only 1 pattern on 4 kept
IF c06 AND c03 AND c08 THEN
result = 1ENDIF
// Pinbar + validation + MA
IF result = 2 THEN
IF (high[1] – low[1]) > 2*abs(close[1] – open[1]) THEN
IF (close[1] < open[1]) AND (open[1] – low[1]) < 0.33*(high[1] – low[1]) OR (close[1] – low[1]) < 0.33*(high[1]-low[1]) AND open[0] < (high[1] – myATR) THEN
DRAWARROWDOWN(barindex[1],high[1]+6*TICKSIZE)coloured(255,10,10)
ELSIF (close[1] < open[1]) AND (open[1] – low[1]) < 0.33*(high[1] – low[1]) OR (close[1] – low[1]) < 0.33*(high[1]-low[1]) AND open[0] > (high[1] – myATR) THEN
DRAWARROWDOWN(barindex[1],high[1]+6*TICKSIZE)coloured(255,10,10)
ENDIF
ENDIF
ELSIF result = 1 THEN
IF (high[1] – low[1]) > 2*abs(close[1] – open[1]) THEN
IF (open[1] < close[1]) AND (high[1] – open[1]) < 0.33*(high[1] – low[1]) OR (high[1] – close[1]) < 0.33*(high[1]-low[1]) AND open[0] > (low[1] + myATR) THEN
DRAWARROWUP(barindex[1],low[1]-6*TICKSIZE)coloured(10,255,10)
ELSIF (open[1] < close[1]) AND (high[1] – open[1]) < 0.33*(high[1] – low[1]) OR (high[1] – close[1]) < 0.33*(high[1]-low[1]) AND open[0] > (low[1] + myATR) THEN
DRAWARROWUP(barindex[1],low[1]-6*TICKSIZE)coloured(10,255,10)
ENDIF
ENDIF
ENDIFRETURN
01/22/2024 at 1:43 AM #226691Reducing to the maximum…
Let’s have a look at the conditions here…
// Parameters
distance = 6*PIPSIZE // Limit within which the pinbar must be contained (around each moving average)
ma11 = Average[1200](close) // Moving average 20 (H1) in a 1 minute time unit (for markets open from 9h to 17h30)
// 1 OPHL position on 6
c01 = High[1] < ma11 + distance AND High[1] > ma11 // High contained above and in the defined limit around the MA
c02 = Close[1] < ma11 + distance AND Close[1] > ma11 // Close contained above and in the defined limit around the MA
c03 = Low[1] > ma11 – distance AND Low[1] < ma11 // Low contained below and in the defined limit around the MA
c04 = High[1] > Open[1] AND High[1] > Close[1] // High > Open & Close// MA
IF c01 AND c02 AND c03 AND c04 THEN
result = 1How can it provide such a selection?? (see picture)
01/22/2024 at 2:01 AM #226693Okay…
As a start, I forgot to integrate:
ELSE
result = 0
Which is maybe my only bad…
-
AuthorPosts
Find exclusive trading pro-tools on