Smart money indicator (using Arrays)
Forums › ProRealTime English forum › ProBuilder support › Smart money indicator (using Arrays)
- This topic has 17 replies, 6 voices, and was last updated 1 year ago by JC_Bywan.
-
-
07/23/2023 at 6:00 AM #218018
Just a suggestion monochrome, not sure of the programming challenge though. How about we only draw if the distance between previous and current low or high is > say 30 points (variable can be used dependingon instrument). Most of the time markets are ranging and with high spread and stop loss, trades doesn’t make sense anyway.
Regardless of timeframe, this strategy will avoid Cluttor on chart with prior calc done before drawing , and provide a clear see through area worth to trade in anticipation of fill?
Sl can be higher or lower of current or previous bars and target is the high or low identified!
I tried loading with only 500 bars and its manageable
07/23/2023 at 9:56 AM #218027We can add a minimum distance before detection to reduce the noise. Personally I like to see all the gaps.
It will still be slow when backtesting. When I get time I’ll see if I can recode it so there’s a set limit of arrays and rearrange as roberto and Peter suggested. I need to search the forum for prev examples of such code.123MinDistance = 5*pipsizeIf high > max(high[1],high[2]) and (high - max(high[1],high[2])) > mindistance thenNot tested as replying from phone.
09/21/2023 at 3:12 PM #221395Hi,
in case you are still using this and would still want to gain a bit of speed, I had a look at it as part of my late unread summer posts. By the way as Roberto said above, many needed help. This topic came the day after I had to be offline for a few weeks for personal reasons and I thank Nicolas and Roberto for their offline support during these few weeks, and even now as I still have to be offline sometimes.
Basically, your loop ends up being very big with gapsindex continuously growing, but as importantly, you do lots of unnecessary calculations inside it, you can avoid most of them (perhaps all, would require a closer look) with the if statements structure modified as follows.
Also, this is a drawonlastbaronly=true code, so why would you keep graphic commands done on any bar not being the last one? At code launch you wouldn’t see any of the graphics asked during previous bars of history anyway as only the latest graphic output would appear, but you would still “pay” the time spent on executing the graphics commands (done many more times than you see it written because of the loop avg size multiplied by the number of bars the loop is executed). An “if islastbarupdate” can reduce this by not spending time on graphics not displayed. All together, early test show time reduced by more than 2 when applying these modifications on code from post #217882:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798DEFPARAM DrawOnLastBarOnly = trueDEFPARAM CalculateOnLastBars = 2000ONCE GapsIndex = 0// Identify and store high gapsIF High > Max(High[1], High[2]) THEN$HighGapsTop[GapsIndex] = High$HighGapsBottom[GapsIndex] = Max(High[1], High[2])$GapStartHigh[GapsIndex] = BarIndex$HighGapStatus[GapsIndex] = 0$GapEndHigh[GapsIndex] = barindex$GapFilledHigh[GapsIndex] = 0GapsIndex = GapsIndex + 1ENDIF// Identify and store low gapsIF Low < Min(Low[1], Low[2]) THEN$LowGapsTop[GapsIndex] = Min(Low[1], Low[2])$LowGapsBottom[GapsIndex] = Low$GapStartLow[GapsIndex] = BarIndex$LowGapStatus[GapsIndex] = 0$GapEndLow[GapsIndex] = barindex$GapFilledLow[GapsIndex] = 0GapsIndex = GapsIndex + 1ENDIF// GAP status// 0 for not filled// 1 for filled upwards (High crosses over $HighGapsTop[i] and Low < $HighGapsBottom[i])// 2 for filled downwards (Low crosses under $HighGapsBottom[i] and High > $HighGapsTop[i])// 3 for partially filled upwards (High > $HighGapsBottom[i] and High < $HighGapsTop[i])// 4 for partially filled downwards (Low > $HighGapsBottom[i] and Low < $HighGapsTop[i])// 5 for filled upwards (Low crosses under $LowGapsBottom[i] and High > $LowGapsTop[i])// 6 for filled downwards (High crosses over $LowGapsTop[i] and Low < $LowGapsBottom[i])// 7 for partially filled upwards (Low > $LowGapsBottom[i] and Low < $LowGapsTop[i])// 8 for partially filled downwards (High > $LowGapsBottom[i] and High < $LowGapsTop[i])// Loop over all identified gaps and draw rectangles if they have not been filledFOR i = 1 TO GapsIndex-1 DO// High gapsif $GapFilledHigh[i]=0 thenIF High > $HighGapsTop[i] AND Low < $HighGapsBottom[i] THEN // Gap Status 1$GapFilledHigh[i] = 1$HighGapStatus[i] = 1$GapEndHigh[i] = BarIndexELSIF Low < $HighGapsBottom[i] AND High > $HighGapsTop[i] THEN // Gap Status 2$GapFilledHigh[i] = 1$HighGapStatus[i] = 2$GapEndHigh[i] = BarIndexELSIF High > $HighGapsBottom[i] AND High < $HighGapsTop[i] THEN // Gap Status 3$HighGapsBottom[i] = high$HighGapStatus[i] = 3ELSIF Low > $HighGapsBottom[i] AND Low < $HighGapsTop[i] THEN // Gap Status 4$HighGapsTop[i] = low$HighGapStatus[i] = 4ENDIFendif// Low gapsif $GapFilledLow[i]=0 thenIF Low < $LowGapsBottom[i] AND High > $LowGapsTop[i] THEN // Gap Status 5$LowGapStatus[i] = 5$GapEndLow[i] = BarIndex$GapFilledLow[i] = 1ELSIF High > $LowGapsTop[i] AND Low < $LowGapsBottom[i] THEN // Gap Status 6$LowGapStatus[i] = 6$GapEndLow[i] = BarIndex$GapFilledLow[i] = 1ELSIF Low > $LowGapsBottom[i] AND Low < $LowGapsTop[i] THEN // Gap Status 7$LowGapsTop[i] = low$LowGapStatus[i] = 7ELSIF High > $LowGapsBottom[i] AND High < $LowGapsTop[i] THEN // Gap Status 8$LowGapsBottom[i] = high$LowGapStatus[i] = 8ENDIFendifNEXTif islastbarupdate thenFOR i = 1 TO GapsIndex-1 DOIF $HighGapStatus[i] <> 0 thenif $GapFilledHigh[i] = 1 THENDRAWRECTANGLE($GapStartHigh[i], $HighGapsTop[i], $GapEndHigh[i], $HighGapsBottom[i]) coloured("red", 20) bordercolor("black", 20)ELSeDRAWRECTANGLE($GapStartHigh[i], $HighGapsTop[i], barindex, $HighGapsBottom[i]) coloured("red", 20) bordercolor("black", 20)ENDIFendifIF $LowGapStatus[i] <> 0 thenif $GapFilledLow[i] = 1 THENDRAWRECTANGLE($GapStartLow[i], $LowGapsTop[i], $GapEndLow[i], $LowGapsBottom[i]) coloured("blue", 20) bordercolor("black", 20)elseDRAWRECTANGLE($GapStartLow[i], $LowGapsTop[i], barindex, $LowGapsBottom[i]) coloured("blue", 20) bordercolor("black", 20)ENDIFendifNEXTendifRETURN -
AuthorPosts