Bonjour à tous,
Est-ce que quelqu’un aurait le temps et la gentillesse de pouvoir convertir un indicateur TradingView pour PRT.
C’est un indicateur 2 en 1, il y a un AMDx (Accumulation Manipulation Distribution) cela trace des rectangles à heure fixe. De même pour le second qui est un indicateur OPR, cela trace un rectangle de telle heure à heure, en prenant en compte par exemple le plus haut et le plus bas des bougies de 15h00 et 15h01.
Je vous poste le code et des captures.
je vous remercie beaucoup par avance.
/@version=5
indicator("OPR", overlay=true)
// --- Paramètres personnalisables --- //
inputHour = input.int(15, "Heure de la bougie (heure de Paris)", minval=0, maxval=23) // Heure cible que tu peux ajuster (heure de Paris)
inputMinute = input.int(32, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
endHour = 18 // Heure de fin fixe (23h59 heure de Paris)
endMinute = 48
inputHour1 = input.int(09, "Heure de la bougie (heure de Paris)", minval=0, maxval=23) // Heure cible que tu peux ajuster (heure de Paris)
inputMinute1 = input.int(29, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
endHour1 = 15 // Heure de fin fixe (23h59 heure de Paris)
endMinute1 = 31
inputHour2 = input.int(18, "Heure de la bougie (heure de Paris)", minval=0, maxval=23) // Heure cible que tu peux ajuster (heure de Paris)
inputMinute2 = input.int(49, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
endHour2 = 19 // Heure de fin fixe (23h59 heure de Paris)
endMinute2 = 30
inputHour3 = input.int(19, "Heure de la bougie (heure de Paris)", minval=0, maxval=23) // Heure cible que tu peux ajuster (heure de Paris)
inputMinute3 = input.int(30, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
endHour3 = 23 // Heure de fin fixe (23h59 heure de Paris)
endMinute3 = 59
// --- Fuseau horaire (GMT+2) --- //
gmt_offset_hours = -7
// Calculer l'heure UTC à partir de l'heure de Paris
hour_utc = (hour - gmt_offset_hours + 24) % 24 // Ajuste l'heure en UTC (évite les valeurs négatives en ajoutant 24)
// Convertir les heures d'entrée en minutes depuis minuit (heure de Paris)
target_minutes = inputHour * 60 + inputMinute
end_minutes = endHour * 60 + endMinute
target_minutes1 = inputHour1 * 60 + inputMinute1
end_minutes1 = endHour1 * 60 + endMinute1
target_minutes2 = inputHour2 * 60 + inputMinute2
end_minutes2 = endHour2 * 60 + endMinute2
target_minutes3 = inputHour3 * 60 + inputMinute3
end_minutes3 = endHour3 * 60 + endMinute3
// --- Variables pour stocker les plus hauts et plus bas de la bougie cible --- //
var float opr_high = na
var float opr_low = na
var int opr_day = na // Stocker le jour pour chaque rectangle
var box opr_box = na // Variable pour tracer le rectangle
var float opr_high1 = na
var float opr_low1 = na
var int opr_day1 = na // Stocker le jour pour chaque rectangle
var box opr_box1 = na // Variable pour tracer le rectangle
var float opr_high2 = na
var float opr_low2 = na
var int opr_day2 = na // Stocker le jour pour chaque rectangle
var box opr_box2 = na // Variable pour tracer le rectangle
var float opr_high3 = na
var float opr_low3 = na
var int opr_day3 = na // Stocker le jour pour chaque rectangle
var box opr_box3 = na // Variable pour tracer le rectangle
// Calcul des minutes depuis minuit pour la bougie actuelle (en UTC)
current_minutes = hour_utc * 60 + minute
current_minutes1 = hour_utc * 60 + minute
current_minutes2 = hour_utc * 60 + minute
current_minutes3 = hour_utc * 60 + minute
// Détection de la bougie cible (heure de Paris définie par l'utilisateur, convertie en UTC)
is_target_candle = (hour_utc == inputHour and minute == inputMinute)
is_target_candle1 = (hour_utc == inputHour1 and minute == inputMinute1)
is_target_candle2 = (hour_utc == inputHour2 and minute == inputMinute2)
is_target_candle3 = (hour_utc == inputHour3 and minute == inputMinute3)
// Si la bougie est celle définie (ex : 16h25 heure de Paris), on stocke le plus haut et le plus bas
if (is_target_candle)
opr_high := high
opr_low := low
opr_day := dayofmonth // On enregistre le jour où la bougie cible est trouvée
//
if (is_target_candle1)
opr_high1 := high
opr_low1 := low
opr_day1 := dayofmonth // On enregistre le jour où la bougie cible est trouvée
//
if (is_target_candle2)
opr_high2 := high
opr_low2 := low
opr_day2 := dayofmonth // On enregistre le jour où la bougie cible est trouvée
//
if (is_target_candle3)
opr_high3 := high
opr_low3 := low
opr_day3 := dayofmonth // On enregistre le jour où la bougie cible est trouvée
// Si on est après la bougie cible et avant 23h59 heure de Paris, on trace le rectangle
is_after_target = (current_minutes >= target_minutes) and (current_minutes <= end_minutes)
is_after_target1 = (current_minutes1 >= target_minutes1) and (current_minutes1 <= end_minutes1)
is_after_target2 = (current_minutes2 >= target_minutes2) and (current_minutes2 <= end_minutes2)
is_after_target3 = (current_minutes3 >= target_minutes3) and (current_minutes3 <= end_minutes3)
if (is_after_target and not na(opr_high) and not na(opr_low) and opr_day == dayofmonth)
if na(opr_box)
// Création du rectangle
opr_box := box.new(left=bar_index, top=opr_high, right=bar_index, bottom=opr_low, border_color=color.orange, bgcolor=color.new(color.orange, 85))
else
// Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
box.set_right(opr_box, bar_index)
//
if (is_after_target1 and not na(opr_high1) and not na(opr_low1) and opr_day1 == dayofmonth)
if na(opr_box1)
// Création du rectangle
opr_box1 := box.new(left=bar_index, top=opr_high1, right=bar_index, bottom=opr_low1, border_color=#E9C9B1, bgcolor=color.new(#E9C9B1, 80))
else
// Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
box.set_right(opr_box1, bar_index)
//
if (is_after_target2 and not na(opr_high2) and not na(opr_low2) and opr_day2 == dayofmonth)
if na(opr_box2)
// Création du rectangle
opr_box2 := box.new(left=bar_index, top=opr_high2, right=bar_index, bottom=opr_low2, border_color=color.green, bgcolor=color.new(#A5D152, 85))
else
// Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
box.set_right(opr_box2, bar_index)
//
if (is_after_target3 and not na(opr_high3) and not na(opr_low3) and opr_day3 == dayofmonth)
if na(opr_box3)
// Création du rectangle
opr_box3 := box.new(left=bar_index, top=opr_high3, right=bar_index, bottom=opr_low3, border_color=#425320, bgcolor=color.new(#425320, 85))
else
// Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
box.set_right(opr_box3, bar_index)
// Réinitialisation des variables pour le jour suivant
if (dayofmonth != opr_day)
opr_high := na
opr_low := na
opr_day := na
opr_box := na // On réinitialise le rectangle pour le jour suivant
//
if (dayofmonth != opr_day1)
opr_high1 := na
opr_low1 := na
opr_day1 := na
opr_box1 := na // On réinitialise le rectangle pour le jour suivant
//
if (dayofmonth != opr_day2)
opr_high2 := na
opr_low2 := na
opr_day2 := na
opr_box2 := na // On réinitialise le rectangle pour le jour suivant
//
if (dayofmonth != opr_day3)
opr_high3 := na
opr_low3 := na
opr_day3 := na
opr_box3 := na // On réinitialise le rectangle pour le jour suivant
//------------//---------------//----------------//-----------------//----------------//-----------------//----------
// Input settings for the session box colors, border width, and transparency
colorA = input.color(color.new(color.red, 80), title="Color for Session A and Vertical Lines")
colorM = input.color(color.new(color.green, 80), title="Color for Session M and Vertical Lines")
colorD = input.color(color.new(color.blue, 80), title="Color for Session D and Vertical Lines")
colorX = input.color(color.new(color.yellow, 80), title="Color for Session X and Vertical Lines")
borderWidth = input.int(1, title="Border Width", minval=1, maxval=5)
transparency = input.int(80, title="Transparency", minval=0, maxval=100)
// Input to choose between AMDX and XAMD sessions
sessionType = input.string("AMDX", title="Choose Session Type", options=["AMDX", "XAMD"])
// Input to choose the drawing style
drawingStyle = input.string("Box", title="Drawing Style", options=["Box", "Line"])
// Input to enable or disable vertical dashed lines
showVerticalLines = input.bool(true, title="Show Vertical Lines")
showVerticalTimeLabels = input.bool(true, title="Show Vertical Time Labels")
// Input to choose vertical line style
verticalLineStyle = input.string("Dashed", title="Vertical Line Style", options=["Solid", "Dotted", "Dashed"])
// Convert vertical line style input to line style
var line_style = line.style_solid
if verticalLineStyle == "Dotted"
line_style := line.style_dotted
else if verticalLineStyle == "Dashed"
line_style := line.style_dashed
// Input for session time label transparency
timeLabelTransparency = input.int(80, title="Time Label Transparency", minval=0, maxval=100)
// Define the session start and end times based on the selected session type in UTC-4
var int startTimeA = na
var int endTimeA = na
var int startTimeM = na
var int endTimeM = na
var int startTimeD = na
var int endTimeD = na
var int startTimeX = na
var int endTimeX = na
if sessionType == "AMDX"
startTimeA := timestamp("GMT-4", year, month, dayofmonth - 1, 18, 00)
endTimeA := timestamp("GMT-4", year, month, dayofmonth, 3, 00)
startTimeM := timestamp("GMT-4", year, month, dayofmonth, 3, 00)
endTimeM := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
startTimeD := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
endTimeD := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
startTimeX := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
endTimeX := timestamp("GMT-4", year, month, dayofmonth, 18, 00)
else
startTimeX := timestamp("GMT-4", year, month, dayofmonth - 1, 18, 00)
endTimeX := timestamp("GMT-4", year, month, dayofmonth, 0, 00)
startTimeA := timestamp("GMT-4", year, month, dayofmonth, 0, 00)
endTimeA := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
startTimeM := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
endTimeM := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
startTimeD := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
endTimeD := timestamp("GMT-4", year, month, dayofmonth, 18, 00)
// Function to format time for labels
format_time(ts) =>
hourx = hour(ts, "GMT-4")
minutex = minute(ts, "GMT-4")
secondx = second(ts, "GMT-4")
str.tostring(hour, "00") + ":" + str.tostring(minute, "00") + ":" + str.tostring(second, "00")
// Function to draw session boxes or vertical lines and labels
drawSession(sessionStartTime, sessionEndTime, color, transparency, labelText) =>
var float sessionLow = na
var float sessionHigh = na
var box sessionBox = na
var label sessionLabel = na
if (time >= sessionStartTime and time < sessionEndTime)
sessionLow := na(sessionLow) ? low : math.min(low, sessionLow)
sessionHigh := na(sessionHigh) ? high : math.max(high, sessionHigh)
else if (time == sessionEndTime)
// Ensure the last bar of the session is included in the high/low calculation
sessionLow := na(sessionLow) ? low : math.min(low, sessionLow)
sessionHigh := na(sessionHigh) ? high : math.max(high, sessionHigh)
if (not na(sessionLow) and not na(sessionHigh))
if drawingStyle == "Box"
// Draw the session box
sessionBox := box.new(left=sessionStartTime, top=sessionHigh, right=sessionEndTime, bottom=sessionLow, xloc=xloc.bar_time, border_color=color, border_width=borderWidth, bgcolor=color.new(color, 92))
// Draw the session label
midTime = (sessionStartTime + sessionEndTime) / 2
sessionLabel := label.new(midTime, sessionHigh, text=labelText, xloc=xloc.bar_time, yloc=yloc.abovebar, color=color.new(color.black, 75), textcolor=color.new(color.yellow, 0), style=label.style_label_center)
// Draw the session label
sessionLabel := label.new(sessionStartTime, high, xloc=xloc.bar_time, yloc=yloc.abovebar, color=color.new(color.black, 100), textcolor=color.new(color.white, 0), style=label.style_label_center)
sessionLow := na
sessionHigh := na
// Draw boxes and vertical dashed lines for the specified sessions
drawSession(startTimeA, endTimeA, colorA, transparency, "A")
drawSession(startTimeM, endTimeM, colorM, transparency, "M")
drawSession(startTimeD, endTimeD, colorD, transparency, "D")
drawSession(startTimeX, endTimeX, colorX, transparency, "X")