Gap Fill Indicator
Forums › ProRealTime English forum › ProBuilder support › Gap Fill Indicator
- This topic has 15 replies, 6 voices, and was last updated 1 year ago by rob.es.
-
-
10/13/2022 at 11:47 AM #202454
I want to visually highlight a gap until it is filled.
So far, I came up with the following code (see the attached screenshot for the result of this code).
What I want to achieve is that the lines that indicate the gap reach until the candle that fully fills this gap (or else continue to go on until the gap is fully filled). How can this be done?
So far I have hardcoded the length of the line to 10 bars; but that is obviously either too long or too short.
Thank you so much for your help. Greetings!
123456789101112131415161718192021222324// Calculate average rangeAverageHIGH = AVERAGE[20](HIGH)AverageLOW = AVERAGE[20](LOW)AverageRANGE = AverageHIGH - AverageLOW// Find bullish gapsIF LOW > HIGH[1] AND (LOW - HIGH[1]) > 0.35 * AverageRANGE THENgapfillzoneHIGH = LOWgapfillzoneLOW = HIGH[1]a = BARINDEX-1DRAWSEGMENT(a,gapfillzoneHIGH,BARINDEX+10,gapfillzoneHIGH) COLOURED(0,255,0)DRAWSEGMENT(a,gapfillzoneLOW,BARINDEX+10,gapfillzoneLOW) COLOURED(255,0,0)ENDIF// Find bearish gapsIF HIGH < LOW[1] AND (LOW[1] - HIGH) > 0.35 * AverageRANGE THENgapfillzoneHIGH = HIGHgapfillzoneLOW = LOW[1]a = BARINDEX-1DRAWSEGMENT(a,gapfillzoneLOW,BARINDEX+10,gapfillzoneLOW) COLOURED(0,255,0)DRAWSEGMENT(a,gapfillzoneHIGH,BARINDEX+10,gapfillzoneHIGH) COLOURED(255,0,0)ENDIFRETURN10/13/2022 at 4:27 PM #202484You need to store gap prices in an array, then check, each bar, if any of them has been filled or not and, when they have, set them to 0 (and maybe shift all array elements one place, but it’s not mandatory) to skip checking them again.
1 user thanked author for this post.
10/13/2022 at 6:14 PM #202501Dear Roberto,
Thank you for your reply. However, I could not find anything about arrays in the ProRealTime programming guides. Have you got any advice where I can learn about how to implement the solution you have layed out in your answer?
10/13/2022 at 11:42 PM #202509Searching this forum for ARRAY will return many links.
A guide can be found here :
https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/
1 user thanked author for this post.
10/14/2022 at 6:40 PM #202581Dear Roberto,
I searched the whole forum, and I tried many things, but I couldn’t wrap my head around it. The lines created would always point backwards.
I know it might be much to ask, but could you show me how to formulate your approach into code?
Greetings,
Nils
10/14/2022 at 7:13 PM #202586It will take some time to code it. I will make it as soon as possible 🙂
1 user thanked author for this post.
10/17/2022 at 9:01 AM #20266011/04/2022 at 6:28 PM #203551There you go:
GAP Monitoring till Filled123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146// GAP Monitoring till Filled//// https://www.prorealcode.com/topic/gap-fill-indicator///DEFPARAM DrawOnLastBarOnly = True////ONCE GapLineSize = 4//ONCE GapDepth = 0.35//ONCE t155 = 135ONCE t255 = 255ONCE Elements = 10ONCE UPwards = 1ONCE DOWNwards = -1//IF BarIndex = 0 THENFOR i = 0 TO Elements$Gap[i] = 0$Gap2[i] = 0$Direction[i] = 0$BarID[i] = 0NEXTENDIF//// Calculate average rangeAverageHIGH = AVERAGE[20](HIGH)AverageLOW = AVERAGE[20](LOW)AverageRANGE = AverageHIGH - AverageLOW//IF BarIndex <= 9999999 THEN//// check whether any previous gap has been filled//FOR i = 1 TO ElementsIF $Direction[i] = UPwards THEN //bearish gapsIF high[1] < $Gap[i] AND high >= $Gap[i] THENFOR j = i TO Elements - 1// move next element to the current position (so it's overwritten)$Gap[j] = $Gap[j + 1]$Gap2[j] = $Gap2[j + 1]$Direction[j] = $Direction[j + 1]$BarID[j] = $BarID[j + 1]// clear the next element$Gap[j + 1] = 0$Gap2[j + 1] = 0$Direction[j + 1] = 0$BarID[j + 1] = 0NEXT$Gap[Elements] = 0$Gap2[Elements] = 0$Direction[Elements] = 0$BarID[Elements] = 0ENDIFELSIF $Direction[i] = DOWNwards THEN //bullish gapsIF low[1] > $Gap[i] AND low <= $Gap[i] THENFOR j = i TO Elements - 1// move next element to the current position (so it's overwritten)$Gap[j] = $Gap[j + 1]$Gap2[j] = $Gap2[j + 1]$Direction[j] = $Direction[j + 1]$BarID[j] = $BarID[j + 1]// clear the next element$Gap[j + 1] = 0$Gap2[j + 1] = 0$Direction[j + 1] = 0$BarID[j + 1] = 0NEXT$Gap[Elements] = 0$Gap2[Elements] = 0$Direction[Elements] = 0$BarID[Elements] = 0ENDIFENDIFNEXT//// Detect new Gaps//// Find bullish gapsIF LOW > HIGH[1] AND (LOW - HIGH[1]) > GapDepth * AverageRANGE THENgapfillzoneHIGH = LOWgapfillzoneLOW = HIGH[1]a = BARINDEX-1// make room for one more array element, if neededIF $Gap[Elements] <> 0 THENElements = Elements + 1$Gap[Elements] = 0$Gap2[Elements] = 0$Direction[Elements] = 0$BarIDE[Elements] = 0ENDIF// store the new element in the first available slotFOR i = 1 TO ElementsIF $Gap[i] = 0 THEN$Gap[i] = gapfillzoneLOW$Gap2[i] = gapfillzoneHIGH$Direction[i] = DOWNwards$BarID[i] = abreakENDIFNEXTENDIF//// Find bearish gapsIF HIGH < LOW[1] AND (LOW[1] - HIGH) > GapDepth * AverageRANGE THENgapfillzoneHIGH = HIGHgapfillzoneLOW = LOW[1]a = BARINDEX-1// make room for one more array element, if neededIF $Gap[Elements] <> 0 THENElements = Elements + 1$Gap[Elements] = 0$Gap2[Elements] = 0$Direction[Elements] = 0$BarID[Elements] = 0ENDIF// store the new element in the first available slotFOR i = 1 TO ElementsIF $Gap[i] = 0 THEN$Gap[i] = gapfillzoneLOW$Gap2[i] = gapfillzoneHIGH$Direction[i] = UPwards$BarID[i] = abreakENDIFNEXTENDIF////ENDIF//// draw lines//FOR i = 1 TO ElementsIF $Gap[i] <> 0 THENa = $BarID[i]x = $Gap[i] //gapfillzoneLOWy = $Gap2[i] //gapfillzoneHIGHIF $Direction[i] = DOWNwards THENDRAWSEGMENT(a,y,a+GapLineSize,y) COLOURED("Green",t155) style(Line,2)DRAWSEGMENT(a,x,a+GapLineSize,x) COLOURED("Green",t255) style(Line,2)ELSIF $Direction[i] = UPwards THENDRAWSEGMENT(a,x,a+GapLineSize,x) COLOURED("Red",t155) style(Line,2)DRAWSEGMENT(a,y,a+GapLineSize,y) COLOURED("Red",t255) style(Line,2)ENDIFENDIFNEXT//RETURNthe properties have two settings:
- GapLineSize is the line length (in bars) to be plotted into the future
- GapDepth is the size of the minimum GAP (multiplier of the average range).
3 users thanked author for this post.
11/24/2022 at 8:31 AM #20472311/24/2022 at 8:41 AM #204725How to add an indicator on price: https://www.prorealcode.com/blog/video-tutorials/how-to-add-an-indicator-on-price-prorealtime/
1 user thanked author for this post.
11/24/2022 at 8:48 AM #20472611/24/2022 at 10:13 AM #204754Adding an indicator to the price window works for me both on v11 and on v12. The indicator has to exist in the list first. So when you create it first time around and it isn’t in the list yet, it appears below, you save it, then it’s in the list, and then once it is in the list you can do as the video.
Did you mean you get a panel below each time, having tried several times, or did you mean you only did it once for creation when it is not in the list yet and can’t do as the video? If even when trying again picking it from the list, it doesn’t work, then there might be a problem specific to your platform, and you would need to send a technical report from your platform to PRT (CTRL+M). It works for me on v12, so can’t reproduce the problem and help further as fellow user.
1 user thanked author for this post.
11/24/2022 at 10:34 AM #204755I have downloaded the GAP-Monitoring-till-Filled.itf from robertogozzi message above dated 11/04/2022 at 6:28 PM.
I then imported the itf file and it is in the list.
When I tried to install in the price panel a new panel was created at the bottom.
I don’t have the problem with other indicators
11/24/2022 at 11:02 AM #204760Ok, there might be a problem here indeed, I started from scratch again, imported it rather than create and copy-paste, but it didn’t change. The only real difference I could think of, is that I had added it as “favorite” (the yellow star next to it) to avoid scrolling down the indicators list to find it. So just in case, I tried without adding it as favorite, and indeed it made a difference, I am now having the same issue too, when not favorite it doesn’t get added to price, but when added as favorite first, it does.
Good enough for me to highlight it as a v12 bug to Nicolas. In the meantime, you can try adding it as a favorite in case it helps temporarily in your platform too, until they see if they can replicate the issue, and fix it.
1 user thanked author for this post.
11/24/2022 at 11:23 AM #204761 -
AuthorPosts
Find exclusive trading pro-tools on