Smart money indicator (using Arrays)

Viewing 3 posts - 16 through 18 (of 18 total)
  • Author
    Posts
  • #218018 quote
    amitoverseas40
    Participant
    Junior

    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

    #218027 quote
    Monochrome
    Participant
    Senior

    We 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.

     

    MinDistance = 5*pipsize 
    
    If high > max(high[1],high[2]) and (high - max(high[1],high[2])) > mindistance then

    Not tested as replying from phone.

    #221395 quote
    JC_Bywan
    Moderator
    Master

    Hi,

    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:

    DEFPARAM DrawOnLastBarOnly = true
    DEFPARAM CalculateOnLastBars = 2000
    
    ONCE GapsIndex = 0
    
    // Identify and store high gaps
    IF 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] = 0
    GapsIndex = GapsIndex + 1
    ENDIF
    
    // Identify and store low gaps
    IF 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] = 0
    GapsIndex = GapsIndex + 1
    ENDIF
    
    // 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 filled
    
    FOR i = 1 TO GapsIndex-1 DO
    // High gaps
    if $GapFilledHigh[i]=0 then
    IF High > $HighGapsTop[i] AND Low < $HighGapsBottom[i] THEN // Gap Status 1
    $GapFilledHigh[i] = 1
    $HighGapStatus[i] = 1
    $GapEndHigh[i] = BarIndex
    ELSIF Low < $HighGapsBottom[i] AND High > $HighGapsTop[i] THEN // Gap Status 2
    $GapFilledHigh[i] = 1
    $HighGapStatus[i] = 2
    $GapEndHigh[i] = BarIndex
    ELSIF High > $HighGapsBottom[i] AND High < $HighGapsTop[i] THEN // Gap Status 3
    $HighGapsBottom[i] = high
    $HighGapStatus[i] = 3
    ELSIF Low > $HighGapsBottom[i] AND Low < $HighGapsTop[i] THEN // Gap Status 4
    $HighGapsTop[i] = low
    $HighGapStatus[i] = 4
    ENDIF
    endif
    // Low gaps
    if $GapFilledLow[i]=0 then
    IF Low < $LowGapsBottom[i] AND High > $LowGapsTop[i] THEN // Gap Status 5
    $LowGapStatus[i] = 5
    $GapEndLow[i] = BarIndex
    $GapFilledLow[i] = 1
    ELSIF High > $LowGapsTop[i] AND Low < $LowGapsBottom[i] THEN // Gap Status 6
    $LowGapStatus[i] = 6
    $GapEndLow[i] = BarIndex
    $GapFilledLow[i] = 1
    ELSIF Low > $LowGapsBottom[i] AND Low < $LowGapsTop[i] THEN // Gap Status 7
    $LowGapsTop[i] = low
    $LowGapStatus[i] = 7
    ELSIF High > $LowGapsBottom[i] AND High < $LowGapsTop[i] THEN // Gap Status 8
    $LowGapsBottom[i] = high
    $LowGapStatus[i] = 8
    ENDIF
    endif
    NEXT
    if islastbarupdate then
    FOR i = 1 TO GapsIndex-1 DO
    IF $HighGapStatus[i] <> 0 then
    if $GapFilledHigh[i] = 1 THEN
    DRAWRECTANGLE($GapStartHigh[i], $HighGapsTop[i], $GapEndHigh[i], $HighGapsBottom[i]) coloured("red", 20) bordercolor("black", 20)
    ELSe
    DRAWRECTANGLE($GapStartHigh[i], $HighGapsTop[i], barindex, $HighGapsBottom[i]) coloured("red", 20) bordercolor("black", 20)
    ENDIF
    endif
    IF $LowGapStatus[i] <> 0 then
    if $GapFilledLow[i] = 1 THEN
    DRAWRECTANGLE($GapStartLow[i], $LowGapsTop[i], $GapEndLow[i], $LowGapsBottom[i]) coloured("blue", 20) bordercolor("black", 20)
    else
    DRAWRECTANGLE($GapStartLow[i], $LowGapsTop[i], barindex, $LowGapsBottom[i]) coloured("blue", 20) bordercolor("black", 20)
    ENDIF
    endif
    NEXT
    endif
    
    RETURN
Viewing 3 posts - 16 through 18 (of 18 total)
  • You must be logged in to reply to this topic.

Smart money indicator (using Arrays)


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Monochrome @monochrome Participant
Summary

This topic contains 17 replies,
has 6 voices, and was last updated by JC_Bywan
2 years, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/17/2023
Status: Active
Attachments: 6 files
Logo Logo
Loading...