Little question. I use alerts and webhooks to automate entry into positions (bot). My bot works fine but I would like to add a nice feature to it.
I discovered this script which displays the important economic events to come (fomc meeting, PPI, CPI, etc.) and therefore it displays the strong volatilities to come which are not often easy to trade.
https://www.tradingview.com/script/HLYD ... -and-more/
I would therefore like to prohibit my bot from taking positions 5 hours before and 5 hours after an event (for example).
But my little pine skills are not enough and I can't create the necessary condition to be added to my trigger with the "and not" argument.
Do you have any advice for me to achieve this?
Thank you in advance for your answers :) and have a nice day
The source code :
Code: Select all
// @version=5
// Β© jdehorty
indicator('Economic Calendar Events', overlay=true, scale=scale.none, max_lines_count=500)
import jdehorty/EconomicCalendar/1 as calendar
// ==================
// ==== Settings ====
// ==================
color1 = color.red
color2 = color.orange
color3 = color.yellow
color4 = color.lime
color5 = color.aqua
color6 = color.fuchsia
color7 = color.silver
show_fomc_meetings = input.bool(defval = true, title = "π
FOMC", inline = "FOMC", group="βοΈ Settings", tooltip="The FOMC meets eight times a year to determine the course of monetary policy. The FOMC's decisions are announced in a press release at 2:15 p.m. ET on the day of the meeting. The press release is followed by a press conference at 2:30 p.m. ET. The FOMC's decisions are based on a review of economic and financial developments and its assessment of the likely effects of these developments on the economic outlook.")
c_fomcMeeting = input.color(color.new(color1, 50), title = "Color", group="βοΈ Settings", inline = "FOMC")
show_fomc_minutes = input.bool(defval = true, title = "π
FOMC Minutes", inline = "FOMCMinutes", group="βοΈ Settings", tooltip="The FOMC minutes are released three weeks after each FOMC meeting. The minutes provide a detailed account of the FOMC's discussion of economic and financial developments and its assessment of the likely effects of these developments on the economic outlook.")
c_fomcMinutes = input.color(color.new(color2, 50), title = "Color", group="βοΈ Settings", inline = "FOMCMinutes")
show_ppi = input.bool(defval = true, title = "π
Producer Price Index (PPI)", inline = "PPI", group="βοΈ Settings", tooltip="The Producer Price Index (PPI) measures changes in the price level of goods and services sold by domestic producers. The PPI is a weighted average of prices of a basket of goods and services, such as transportation, food, and medical care. The PPI is a leading indicator of CPI.")
c_ppi = input.color(color.new(color3, 50), title = "Color", group="βοΈ Settings", inline = "PPI")
show_cpi = input.bool(defval = true, title = "π
Consumer Price Index (CPI)", inline = "CPI", group="βοΈ Settings", tooltip="The Consumer Price Index (CPI) measures changes in the price level of goods and services purchased by households. The CPI is a weighted average of prices of a basket of consumer goods and services, such as transportation, food, and medical care. The CPI-U is the most widely used measure of inflation. The CPI-U is based on a sample of about 87,000 households and measures the change in the cost of a fixed market basket of goods and services purchased by urban consumers.")
c_cpi = input.color(color.new(color4, 50), title = "Color", group="βοΈ Settings", inline = "CPI")
show_csi = input.bool(defval = true, title = "π
Consumer Sentiment Index (CSI)", inline = "CSI", group="βοΈ Settings", tooltip="The University of Michigan's Consumer Sentiment Index (CSI) is a measure of consumer attitudes about the economy. The CSI is based on a monthly survey of 500 U.S. households. The index is based on consumers' assessment of present and future economic conditions. The CSI is a leading indicator of consumer spending, which accounts for about two-thirds of U.S. economic activity.")
c_csi = input.color(color.new(color5, 50), title = "Color", group="βοΈ Settings", inline = "CSI")
show_cci = input.bool(defval = true, title = "π
Consumer Confidence Index (CCI)", inline = "CCI", group="βοΈ Settings", tooltip="The Conference Board's Consumer Confidence Index (CCI) is a measure of consumer attitudes about the economy. The CCI is based on a monthly survey of 5,000 U.S. households. The index is based on consumers' assessment of present and future economic conditions. The CCI is a leading indicator of consumer spending, which accounts for about two-thirds of U.S. economic activity.")
c_cci = input.color(color.new(color6, 50), title = "Color", group="βοΈ Settings", inline = "CCI")
show_nfp = input.bool(defval = true, title = "π
Non-Farm Payroll (NFP)", inline = "NFP", group="βοΈ Settings", tooltip="The Non-Farm Payroll (NFP) is a measure of the change in the number of employed persons, excluding farm workers and government employees. The NFP is a leading indicator of consumer spending, which accounts for about two-thirds of U.S. economic activity.")
c_nfp = input.color(color.new(color7, 50), title = "Color", group="βοΈ Settings", inline = "NFP")
show_legend = input.bool(true, "Show Legend", group="βοΈ Settings", inline = "Legend", tooltip="Show the color legend for the economic calendar events.")
// =======================
// ==== Dates & Times ====
// =======================
getUnixTime(_eventArr, _index) =>
switch
timeframe.isdaily => array.get(_eventArr, _index) - timeframe.multiplier*86400000 // -n day(s)
timeframe.isweekly => array.get(_eventArr, _index) - timeframe.multiplier*604800000 // -n week(s)
timeframe.ismonthly => array.get(_eventArr, _index) - timeframe.multiplier*2592000000 // -n month(s)
timeframe.isminutes and timeframe.multiplier > 59 => array.get(_eventArr, _index) - timeframe.multiplier*60000 // -n minute(s)
=> array.get(_eventArr, _index)
if barstate.islastconfirmedhistory
// Note: An offset of -n units is needed to realign events with the timeframe in which they occurred
if show_fomc_meetings
fomcMeetingsArr = calendar.fomcMeetings()
for i = 0 to array.size(fomcMeetingsArr) - 1
unixTime = getUnixTime(fomcMeetingsArr, i)
line.new(x1=unixTime, y1=high, x2=unixTime, y2=low, extend=extend.both,color=c_fomcMeeting, width=2, xloc=xloc.bar_time)
if show_fomc_minutes
fomcMinutesArr = calendar.fomcMinutes()
for i = 0 to array.size(fomcMinutesArr) - 1
unixTime = getUnixTime(fomcMinutesArr, i)
line.new(x1=unixTime, y1=high, x2=unixTime, y2=low, extend=extend.both,color=c_fomcMinutes, width=2, xloc=xloc.bar_time)
if show_ppi
ppiArr = calendar.ppiReleases()
for i = 0 to array.size(ppiArr) - 1
unixTime = getUnixTime(ppiArr, i)
line.new(x1=unixTime, y1=high, x2=unixTime, y2=low, extend=extend.both,color=c_ppi, width=2, xloc=xloc.bar_time)
if show_cpi
cpiArr = calendar.cpiReleases()
for i = 0 to array.size(cpiArr) - 1
unixTime = getUnixTime(cpiArr, i)
line.new(x1=unixTime, y1=high, x2=unixTime, y2=low, extend=extend.both,color=c_cpi, width=2, xloc=xloc.bar_time)
if show_csi
csiArr = calendar.csiReleases()
for i = 0 to array.size(csiArr) - 1
unixTime = getUnixTime(csiArr, i)
line.new(x1=unixTime, y1=high, x2=unixTime, y2=low, extend=extend.both,color=c_csi, width=2, xloc=xloc.bar_time)
if show_cci
cciArr = calendar.cciReleases()
for i = 0 to array.size(cciArr) - 1
unixTime = getUnixTime(cciArr, i)
line.new(x1=unixTime, y1=high, x2=unixTime, y2=low, extend=extend.both,color=c_cci, width=2, xloc=xloc.bar_time)
if show_nfp
nfpArr = calendar.nfpReleases()
for i = 0 to array.size(nfpArr) - 1
unixTime = getUnixTime(nfpArr, i)
line.new(x1=unixTime, y1=high, x2=unixTime, y2=low, extend=extend.both,color=c_nfp, width=2, xloc=xloc.bar_time)
// ================
// ==== Legend ====
// ================
if show_legend
var tbl = table.new(position.top_right, columns=1, rows=8, frame_color=#151715, frame_width=1, border_width=2, border_color=color.new(color.black, 100))
units = timeframe.isminutes ? "m" : ""
table.cell(tbl, 0, 0, syminfo.ticker + ' | ' + str.tostring(timeframe.period) + units, text_halign=text.align_center, text_color=color.gray, text_size=size.normal)
table.cell(tbl, 0, 1, 'FOMC Meeting', text_halign=text.align_center, bgcolor=color.black, text_color=color1, text_size=size.small)
table.cell(tbl, 0, 2, 'FOMC Minutes', text_halign=text.align_center, bgcolor=color.black, text_color=color2, text_size=size.small)
table.cell(tbl, 0, 3, 'Producer Price Index (PPI)', text_halign=text.align_center, bgcolor=color.black, text_color=color3, text_size=size.small)
table.cell(tbl, 0, 4, 'Consumer Price Index (CPI)', text_halign=text.align_center, bgcolor=color.black, text_color=color4, text_size=size.small)
table.cell(tbl, 0, 5, 'Consumer Sentiment Index (CSI)', text_halign=text.align_center, bgcolor=color.black, text_color=color5, text_size=size.small)
table.cell(tbl, 0, 6, 'Consumer Confidence Index (CCI)', text_halign=text.align_center, bgcolor=color.black, text_color=color6, text_size=size.small)
table.cell(tbl, 0, 7, 'Non-Farm Payrolls (NFP)', text_halign=text.align_center, bgcolor=color.black, text_color=color7, text_size=size.small)