Hello everyone,
Thank you for accompanying me in my trading for the past 4 years. Today, it’s my turn to share my code with you!
For a few weeks now, I’ve been getting back into the market profile to improve my strategy decision-making.
As I’m on IG cfd, I don’t have access to the tool. So when I asked around, I understood that the Initial Balance IB was relatively important for the key zones of the day.
By looking around various sources I understand that the market profile is used in M30 but then the choice of the half-hour taken for the IB differs; some take the M30 candle of the preopening, others that of the openening.
For my part, I chose openning, but it’s modifiable in the code.
Nothing crazy, but I plot my IB M30 at 9 a.m. for the dax (to be modified for the US) in blue with the upper and lower bounds extended to the far right.
I put a variable n = number of rectangles (equal to the IB) above and below the IB with half-rights to visualize my key levels.
If you wish to adapt it, everything is modifiable:
To be changed according to which market you’re trading:
start = 093000 //dax if we’re in M30 and want to have the Initial Balance (IB) on the 9 a.m. candle, we set it to 9:30 a.m. because we “draw on last bar only”.
end = 100000 //dax
//start = 160000 //US if trading in the US, activate these times and deactivate those of the dax
//end = 163000 //US
Number of rectangles corresponding to IB :
n = 5 //number of rectangles above and below IB
If you want to see the current day, other days or all days, but it quickly becomes unreadable :
for y = i-1 to i-1 do //put i-1 for the previous day’s IB, i-1 to i for the previous day’s IB and the day, 1 to i for all days etc…
Don’t hesitate to give me feedback, and if anyone has a code to add the TPO, I’d love to hear from you 😉
defparam drawonlastbaronly=true
start = 093000 //dax si on est en M30 et qu'on veut avoir l'Initial Balance (IB) sur la bougie de 9h on met 9h30 car on "draw on last bar only"
end = 100000 //dax
//start = 160000 //US si trading US, activer ces horaires là et désactiver ceux du dax
//end = 163000 //US
tc = time>=start and time<end
n = 5 //nombre de rectangles au dessus et en dessous de l'IB
if tc and not tc[1] then
i=i+1
$x1[i]=barindex
$y1[i]=low
$y2[i]=high
hh=high
ll=low
endif
if tc then
$x2[i]=barindex
ll=min(ll,low)
hh=max(hh,high)
$y1[i]=ll
$y2[i]=hh
endif
if islastbarupdate and isset($x1[2]) then
for y = i-1 to i-1 do //mettre i-1 pour L'IB de la veille, i-1 to i pour l'IB de la veille et la journeé, 1 to i pour tous les jours etc...
for a=1 to n-1 do
for b=1 to n do
drawrectangle($x1[y]-1,$y1[y],$x2[y]+1,$y2[y])coloured(0,255,255,150)bordercolor(0,0,255) //Initial balance
drawrectangle($x1[y]-1,$y2[y],$x2[y]+1,$y2[y]+$y2[y]-$y1[y])coloured(255,0,255,150)bordercolor(0,0,255) //IB+1
drawrectangle($x1[y]-1,$y1[y],$x2[y]+1,$y1[y]-($y2[y]-$y1[y]))coloured(255,0,255,150)bordercolor(0,0,255) //IB-1
drawrectangle($x1[y]-1,$y2[y]+ a*($y2[y]-$y1[y]),$x2[y]+1,$y2[y]+(a+1)*($y2[y]-$y1[y]))coloured(255,0,255,150)bordercolor(0,0,255)
drawrectangle($x1[y]-1,$y1[y]-a*($y2[y]-$y1[y]),$x2[y]+1,$y1[y]-(a+1)*($y2[y]-$y1[y]))coloured(255,0,255,150)bordercolor(0,0,255)
DRAWRAY ($x1[i-1],$y1[i-1],$x1[i-1]+10,$y1[i-1])COLOURED (0,255,255,150) style(line,3) //borne haute IB
DRAWRAY ($x2[i-1],$y2[i-1],$x2[i-1]+10,$y2[i-1])COLOURED (0,255,255,150) style(line,3) //borne basse IB
DRAWRAY($x1[i-1],$y2[i-1]+b*($y2[i-1]-$y1[i-1]),$x1[i-1]+10,$y2[i-1]+b*($y2[i-1]-$y1[i-1]))COLOURED (255,50,0,150) style(line,3)
DRAWRAY($x1[i-1],$y1[i-1]-b*($y2[i-1]-$y1[i-1]),$x1[i-1]+10,$y1[i-1]-b*($y2[i-1]-$y1[i-1]))COLOURED (255,50,0,150) style(line,3)
next
next
next
endif
return //