Economic Data Trading alerts - CPI, Interest rate, PPI, etc
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KareemFarid 

//@version=5
indicator("BETA - Economic Data Trading Strategy - CPI, Interest rate, PPI and more", shorttitle = "Economic Data Trading Strategy", overlay=true)

// Input for the location and economic data point to trade
location = input.string("US", "Location", options=["US", "EU", "JP"])
data_point = input.string("GDP", "Economic Data Point", options=["GDP", "CPI", "CCPI", "UR", "PMI", "PPI","RSMM", "IPMM", "IJC", "INTR"])


// Input for trade direction
trade_on_increase = input.string("Long", "Trade direction when the value increases", options=["Long", "Short", "None"])
trade_on_decrease = input.string("Short", "Trade direction when the value decreases", options=["Long", "Short", "None"])

// Input for multiple TP and SL levels
tp1 = input.float(1, "Take Profit Level 1 (%)") / 100
sl1 = input.float(0.5, "Stop Loss Level 1 (%)") / 100

// Request the economic data
economic_data = request.economic(location, data_point)

// Access the current and previous values
current_value =  economic_data
previous_value = economic_data[1]

// Define the long and short conditions based on the current and previous values
value_increased = current_value > previous_value
value_decreased = current_value < previous_value

long_condition = (trade_on_increase == "Long" and value_increased) or (trade_on_decrease == "Long" and value_decreased)
short_condition = (trade_on_increase == "Short" and value_increased) or (trade_on_decrease == "Short" and value_decreased)


// Plot long and short entries on the chart
plotshape(long_condition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(short_condition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)


alertcondition(long_condition, title="Long Entry Alert", message="Long Entry Signal")
alertcondition(short_condition, title="Short Entry Alert", message="Short Entry Signal")
