Please – Translation of Order Blocks from TV
Forums › ProRealTime English forum › ProBuilder support › Please – Translation of Order Blocks from TV
- This topic has 21 replies, 5 voices, and was last updated 2 years ago by foxxcrypto.
-
-
09/08/2022 at 9:58 AM #20034709/08/2022 at 11:01 AM #20035309/08/2022 at 11:20 AM #20035509/10/2022 at 11:27 AM #200472
Dear Nicols,
Thanks to you, we are very close to the original version of TradingView. I made the following modifications:
- added the bullish part
- Line 6 OBXXXMitigation changed from close to close[1] as per original code
- Line 50 cleanup, I changed “j = 0 to plot–1″ with “plot-1 downto 0”
- Line 54 changed “2” with “1”
- Line 64 drawing, I changed “j = 0 to plot–1 ” with “plot-1 downto 0”
The new code as follows:
Order Blocks v3.1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145// Sonarlabs - Order Block Finder// converted from TradingView// Lower the sensitivity to show more order blocks. A higher sensitivity will show less order blocksdefparam drawonlastbaronly=truesens = 28once obcreatedbear = 0once obcreatedbull = 0once crossindexbear = 0once crossindexbull = 0// Custom Rate of Change (ROC) calculation. This is to calculate high momentum moves in the market.pc = ((open - open[4]) / open[4]) * 100// -----------------sens = sens/100 //ExponentialAverage[8](pc) //sens/100OBBullMitigation = close[1]OBBearMitigation = close[1]// If the ROC crossover our Sensitivty input - Then create a Bearish Order Block// Sensitivty is negative as this is a Bearish OBif pc crosses under -sens thenobcreatedbear = 1crossindexbear = barindexendif// If the ROC crossover our Sensitivty input - Then create a Bullish Order Blockif pc crosses over sens thenobcreatedbull = 1crossindexbull = barindexendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Calculation////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -------------------------------// Bearish OB Creation// -------------------------------// Check if we should create a OB. Also check if we haven't created an OB in the last 5 candles.if obcreatedbear and (crossindexbear - crossindexbear[1]) > 5 thenlastgreen = 0hhighest = 0// Loop through the most recent candles and find the first GREEN (Bullish) candle. We will place our OB here.for i = 4 to 15if close[i] > open[i] thenlastgreen = i//populate the arrays of order block to draw them later$left[plot]= barindex[lastgreen]$top[plot]=high[lastgreen]$bottom[plot]=low[lastgreen]$right[plot]=barindex[lastgreen]plot=plot+1 //increase the array column for next databreakendifnextendif// -------------------------------// Bullish OB Creation// -------------------------------// Check if we should create a OB, Also check if we haven't created an OB in the last 5 candles.if obcreatedbull and (crossindexbull - crossindexbull[1]) > 5 thenlastred = 0hhighest = 0// Loop through the most recent candles and find the first RED (Beaarish) candle. We will place our OB here.for ibull = 4 to 15if close[ibull] < open[ibull] thenlastred = ibull//populate the arrays of order block to draw them later$leftbull[plotbull]= barindex[lastred]$topbull[plotbull]=high[lastred]$bottombull[plotbull]=low[lastred]$rightbull[plotbull]=barindex[lastred]plotbull=plotbull+1 //increase the array column for next databreakendifnextendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Cleanup////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Clean up Bearish OB boxesif plot>0 thenfor j = plot-1 downto 0 //0 to plot-1// If the two last closes are above the high of the bearish OB - Remove the OBif $left[j]>0 then //check if the zone still existitop = $top[j]breakout = summation[max(1,barindex-$left[j])](OBBearMitigation>itop)>=1 //2if breakout then$left[j]=0endifendifnextendif// Clean up Bullish OB boxesif plotbull>0 thenfor jbull = plotbull-1 downto 0 //0 to plotbull-1// If the two last closes are below the low of the bullish OB - Remove the OBif $leftbull[jbull]>0 then //check if the zone still existibot = $bottombull[jbull]breakoutbull = summation[max(1,barindex-$leftbull[jbull])](OBBullMitigation<ibot)>=1 //2if breakoutbull then$leftbull[jbull]=0endifendifnextendif////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Drawing////////////////////////////////////////////////////////////////////////////////////////////////////////////////if islastbarupdate then//plot the Bearish boxesif plot>0 then //islastbarupdate andfor j = plot-1 downto 0 //0 to plot-1if $left[j]>0 thendrawrectangle($left[j],$top[j],barindex,$bottom[j]) coloured("red",30)bordercolor("red",30) //bordercolor("green",85) //coloured(80,108,211,50) bordercolor(80,108,211,50)endifnextendif//plot the Bullish boxesif plotbull>0 then //islastbarupdate andfor jbull = plotbull-1 downto 0 //0 to plotbull-1if $leftbull[jbull]>0 thendrawrectangle($leftbull[jbull],$bottombull[jbull],barindex,$topbull[jbull]) coloured("green",30)bordercolor("green",30)//bordercolor("red",85) //coloured(100,196,172,50) bordercolor(100,196,172,50)//drawrectangle(barindex, $bottombull[jbull],$leftbull[jbull],$topbull[jbull]) coloured("red",85)//bordercolor("red",85) //coloured(100,196,172,50) bordercolor(100,196,172,50)endifnextendifendifreturnBelow the test on PRT (IB) and TV on S&P500 Cash Daily and S&P500 Futures 09 H4. We have the same recent order blocks, but some of them have not been deleted on PRT.
Thank you very much for your valuable help.
Do you want to publish it in the library or do you want me to do it?
09/12/2022 at 9:28 AM #200598Thanks for your effort completing the code. Yes, you can push it into the scripts library, many thanks. Let me do once you have done so please 🙂
Some zones are not erased because price has not breached them right? In the original code there was a switch to check Highs/Lows or just Closes, the differences might be located in this particular condition?
1 user thanked author for this post.
09/12/2022 at 2:55 PM #200625Thank you Nicolas. I posted it on the Liberary. However, I couldn’t add the itf file. The “Add Attachments” button doesn’t work.
For the Block Orders which are not deleted, I think they are minimal in number and don’t prevent the user to see the big picture: Zones where he needs to pay attention. I’m personnaly happy with the end result.
I hope we will have time and energy to convert the Polynomial Regression code that I shared in a seperate post https://www.prorealcode.com/topic/polynomial-regression-indicator/#post-199892 with multiple loops and Arrays, which by the way I’m using on TradingView as my main entry filter. This would really be a plus for the PRC/PRT Community and avoid the back and forth PRT – TradingView.
A Big Thank you Nicolas.
10/24/2022 at 7:45 PM #202991Hi Nicolas,
i tried to run the code but it does not draw anything, do you have any ideas, i have version v11.1 – 1.8.0_202
thank you
-
AuthorPosts