Harmonic Patterns – ZigZag Strategy -Code Review
Forums › ProRealTime English forum › ProOrder support › Harmonic Patterns – ZigZag Strategy -Code Review
- This topic has 0 replies, 1 voice, and was last updated 4 years ago by boonet.
Tagged: harmonic, harmonic patterns, patterns, zig zag, zigzag
Viewing 1 post (of 1 total)
-
-
10/01/2020 at 12:18 AM #146034
Hi all,
Quite an unusual request for code review here.
I tried to replicate a script which works very well on TV platform.
Though I understand the highlevel algo, I am unable to understand rational behind each step in the code. Mainly the exit criterias.
I have done my best with my rookie PRT coding knowledge to replicate the same.
I request you to please check the following –
- Is the code conversion correct?
- Are there any better ways to make the code concise?
- Why does the trade close within 1 candle?
Things to note –
- Zigzag indicator is not supported in ProOrder to had to code it ( not sure if that’s correct )
- Entry and exist criterias are based on Fibo levels.
Harmonic Pattern Code - V1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221DefParam cumulateOrders = trueisUp = close >=openisDown = close <=open//directionif isUp[1] and isDown thendirection = -1elsif isDown[1] and isUp thendirection = 1//else//direction = direction[1]endif//zigzagif isUp[1] and isDown and direction[1] <> -1 thenzigzagF = high[2]elsif isDown[1] and isUp and direction[1] <> 1 thenzigzagF = low[2]endifx = zigzagF[4]a = zigzagF[3]b = zigzagF[2]c = zigzagF[1]d = zigzagF[0]xab = (abs(b-a)/abs(x-a))xad = (abs(a-d)/abs(x-a))abc = (abs(b-c)/abs(a-b))bcd = (abs(c-d)/abs(b-c))bc = d < csc = d > c// isBATBatxab = xab >= 0.382 and xab <= 0.5Batabc = abc >= 0.382 and abc <= 0.886Batbcd = bcd >= 1.618 and bcd <= 2.618Batxad = xad <= 0.618 and xad <= 1.000 // 0.886isBat = Batxab and Batabc and Batbcd and Batxad// isAntiBatAntiBatxab = xab >= 0.500 and xab <= 0.886 // 0.618AntiBatabc = abc >= 1.000 and abc <= 2.618 // 1.13 --> 2.618AntiBatbcd = bcd >= 1.618 and bcd <= 2.618 // 2.0 --> 2.618AntiBatxad = xad >= 0.886 and xad <= 1.000 // 1.13isAntiBat = AntiBatxab and AntiBatabc and AntiBatbcd and AntiBatxad// isAltBatAltBatxab = xab <= 0.382AltBatabc = abc >= 0.382 and abc <= 0.886AltBatbcd = bcd >= 2.0 and bcd <= 3.618AltBatxad = xad <= 1.13isAltBat = AltBatxab and AltBatabc and AltBatbcd and AltBatxad// isButterflyButterflyxab = xab <= 0.786Butterflyabc = abc >= 0.382 and abc <= 0.886Butterflybcd = bcd >= 1.618 and bcd <= 2.618Butterflyxad = xad >= 1.27 and xad <= 1.618isButterfly = Butterflyxab and Butterflyabc and Butterflybcd and Butterflyxad// isAntiButterflyAntiButterflyxab = xab >= 0.236 and xab <= 0.886 // 0.382 - 0.618AntiButterflyabc = abc >= 1.130 and abc <= 2.618 // 1.130 - 2.618AntiButterflybcd = bcd >= 1.000 and bcd <= 1.382 // 1.27AntiButterflyxad = xad >= 0.500 and xad <= 0.886 // 0.618 - 0.786isAntiButterfly = AntiButterflyxab and AntiButterflyabc and AntiButterflybcd and AntiButterflyxad// isABCDABCDabc = abc >= 0.382 and abc <= 0.886ABCDbcd = bcd >= 1.13 and bcd <= 2.618isABCD = ABCDabc and ABCDbcd// isGartleyGartleyxab = xab >= 0.5 and xab <= 0.618 // 0.618Gartleyabc = abc >= 0.382 and abc <= 0.886Gartleybcd = bcd >= 1.13 and bcd <= 2.618Gartleyxad = xad >= 0.75 and xad <= 0.875 // 0.786isGartley = Gartleyxab and Gartleyabc and Gartleybcd and Gartleyxad// isAntiGartleyAntiGartleyxab = xab >= 0.500 and xab <= 0.886 // 0.618 -> 0.786AntiGartleyabc = abc >= 1.000 and abc <= 2.618 // 1.130 -> 2.618AntiGartleybcd = bcd >= 1.500 and bcd <= 5.000 // 1.618AntiGartleyxad = xad >= 1.000 and xad <= 5.000 // 1.272isAntiGartley = AntiGartleyxab and AntiGartleyabc and AntiGartleybcd and AntiGartleyxad// isCrabCrabxab = xab >= 0.500 and xab <= 0.875 // 0.886Crababc = abc >= 0.382 and abc <= 0.886Crabbcd = bcd >= 2.000 and bcd <= 5.000 // 3.618Crabxad = xad >= 1.382 and xad <= 5.000 // 1.618isCrab = Crabxab and Crababc and Crabbcd and Crabxad// isAntiCrabAntiCrabxab = xab >= 0.250 and xab <= 0.500 // 0.276 -> 0.446AntiCrababc = abc >= 1.130 and abc <= 2.618 // 1.130 -> 2.618AntiCrabbcd = bcd >= 1.618 and bcd <= 2.618 // 1.618 -> 2.618AntiCrabxad = xad >= 0.500 and xad <= 0.750 // 0.618isAntiCrab = AntiCrabxab and AntiCrababc and AntiCrabbcd and AntiCrabxad// isSharkSharkxab = xab >= 0.500 and xab <= 0.875 // 0.5 --> 0.886Sharkabc = abc >= 1.130 and abc <= 1.618 //Sharkbcd = bcd >= 1.270 and bcd <= 2.240 //Sharkxad = xad >= 0.886 and xad <= 1.130 // 0.886 --> 1.13isShark = Sharkxab and Sharkabc and Sharkbcd and Sharkxad// isAntiSharkAntiSharkxab = xab >= 0.382 and xab <= 0.875 // 0.446 --> 0.618AntiSharkabc = abc >= 0.500 and abc <= 1.000 // 0.618 --> 0.886AntiSharkbcd = bcd >= 1.250 and bcd <= 2.618 // 1.618 --> 2.618AntiSharkxad = xad >= 0.500 and xad <= 1.250 // 1.130 --> 1.130isAntiShark = AntiSharkxab and AntiSharkabc and AntiSharkbcd and AntiSharkxad// is5oFive0xab = xab >= 1.13 and xab <= 1.618Five0abc = abc >= 1.618 and abc <= 2.24Five0bcd = bcd >= 0.5 and bcd <= 0.625 // 0.5Five0xad = xad >= 0.0 and xad <= 0.236 // negative?is5o = Five0xab and Five0abc and Five0bcd and Five0xad// isWolfWolfxab = xab >= 1.27 and xab <= 1.618Wolfabc = abc >= 0 and abc <= 5Wolfbcd = bcd >= 1.27 and bcd <= 1.618Wolfxad = xad >= 0.0 and xad <= 5isWolf = Wolfxab and Wolfabc and Wolfbcd and Wolfxad// isHnSHnSxab = xab >= 2.0 and xab <= 10HnSabc = abc >= 0.90 and abc <= 1.1HnSbcd = bcd >= 0.236 and bcd <= 0.88HnSxad = xad >= 0.90 and xad <= 1.1isHnS = HnSxab and HnSabc and HnSbcd and HnSxad// isConTriaContriaxab = xab >= 0.382 and xab <= 0.618Contriaabc = abc >= 0.382 and abc <= 0.618Contriabcd = bcd >= 0.382 and bcd <= 0.618Contriaxad = xad >= 0.236 and xad <= 0.764isConTria = Contriaxab and Contriaabc and Contriabcd and Contriaxad// isExpTriaExpTriaxab = xab >= 1.236 and xab <= 1.618ExpTriaabc = abc >= 1.000 and abc <= 1.618ExpTriabcd = bcd >= 1.236 and bcd <= 2.000ExpTriaxad = xad >= 2.000 and xad <= 2.236isExpTria = ExpTriaxab and ExpTriaabc and ExpTriabcd and ExpTriaxadallPatterns = isBAT or isAntiBat or isAltBat or isButterfly or isAntiButterfly or isABCD or isGartley or isAntiGartley or isCrab or isAntiCrab or isShark or isAntiShark or is5o or isWolf or isHnS or isConTria or isExpTriabullish = allPatterns and bcbearish = allPatterns and sctargetewrate = 0.236targettprate = 0.618targetslrate = 0.236//fib calculationfibrange = abs(d-c)if sc thenflastfibew = d-(fibrange*targetewrate)flastfibtp = d-(fibrange*targettprate)flastfibsl = d-(fibrange*targetslrate)elseflastfibew = d+(fibrange*targetewrate)flastfibtp = d+(fibrange*targettprate)flastfibsl = d+(fibrange*targetslrate)endif//targetbuyentry = bullish and close <= flastfibewtargetbuyclose = high >= flastfibtp or low <= flastfibsltargetselentry = bearish and close >= flastfibewtargetselclose = low <= flastfibtp or high >= flastfibsl//// Conditions to enter long positionsIF NOT LongOnMarket AND targetbuyentry THENBUY 1 CONTRACTS AT MARKETSET STOP %Loss 2ENDIF// Conditions to exit long positionsIf LongOnMarket AND targetbuyclose THENSELL AT MARKETENDIF//// Conditions to enter short positionsIF NOT ShortOnMarket AND targetselentry THENSELLSHORT 1 CONTRACTS AT MARKETSET STOP %Loss 2ENDIF//// Conditions to exit short positionsIF ShortOnMarket AND targetselclose THENEXITSHORT AT MARKETENDIF -
AuthorPosts
Viewing 1 post (of 1 total)
Find exclusive trading pro-tools on
Similar topics: