//@version=4
study("Custom MA Crossover Indicator with 100 Point Target", shorttitle="MA Crossover w/ 100pt Target", overlay=true)
// User-defined input for moving averages
shortMA = input(10, minval=1, title="Short MA Period")
longMA = input(100, minval=1, title="Long MA Period")
target_1 = input(50, minval=1, title="Target_1")
target_2 = input(100, minval=1, title="Target_2")
// User-defined input for the start and end times with default values
startTimeInput = input(12, title="Start Time for Session(UTC, in hours)", minval=0, maxval=23)
endTimeInput = input(17, title="End Time Session (UTC, in hours)", minval=0, maxval=23)
// Convert the input hours to minutes from midnight
startTime = startTimeInput * 60
endTime = endTimeInput * 60
// Function to convert the current exchange time to UTC time in minutes
toUTCTime(exchangeTime) =>
exchangeTimeInMinutes = exchangeTime / 60000
// Adjust for UTC time
utcTime = exchangeTimeInMinutes % 1440
utcTime
// Get the current time in UTC in minutes from midnight
utcTime = toUTCTime(time)
// Check if the current UTC time is within any of the allowed timeframes
//isAllowedTimeAsia = (utcTime >= startTimeAsia and utcTime < endTimeAsia)
isAllowedTime = (utcTime >= startTime and utcTime < endTime)
// Apply yellow background color during the allowed time range
bgcolor(isAllowedTime ? color.yellow : na, transp=90)
// Calculating moving averages
shortMAValue = sma(close, shortMA)
longMAValue = sma(close, longMA)
// Plotting the MAs
plot(shortMAValue, title="Short MA", color=color.blue)
plot(longMAValue, title="Long MA", color=color.red)
// Tracking buy and sell signals
var float buyEntryPrice_1 = na
var float buyEntryPrice_2 = na
var float sellEntryPrice_1 = na
var float sellEntryPrice_2 = na
// Logic for Buy and Sell signals
buySignal = crossover(shortMAValue, longMAValue) and isAllowedTime
sellSignal = crossunder(shortMAValue, longMAValue) and isAllowedTime
// Update last buy and sell signal values
if (buySignal)
buyEntryPrice_1 := close
buyEntryPrice_2 := close
else if (sellSignal)
sellEntryPrice_1 := close
sellEntryPrice_2 := close
// Apply background color for entry candles
barcolor(buySignal or sellSignal ? color.yellow :na)
/// Creating buy and sell labels
if (buySignal)
label.new(bar_index, low, text="BUY", style=label.style_label_up, color=color.green, textcolor=color.white, yloc=yloc.belowbar)
if (sellSignal)
label.new(bar_index, high, text="SELL", style=label.style_label_down, color=color.red, textcolor=color.white, yloc=yloc.abovebar)
// Creating labels for 100-point movement
if (not na(buyEntryPrice_1) and close >= buyEntryPrice_1 + target_1)
label.new(bar_index, high, text=tostring(target_1), style=label.style_label_down, color=color.green, textcolor=color.white, yloc=yloc.abovebar)
buyEntryPrice_1 := na // Reset after label is created
if (not na(buyEntryPrice_2) and close >= buyEntryPrice_2 + target_2)
label.new(bar_index, high, text=tostring(target_2), style=label.style_label_down, color=color.green, textcolor=color.white, yloc=yloc.abovebar)
buyEntryPrice_2 := na // Reset after label is created
if (not na(sellEntryPrice_1) and close <= sellEntryPrice_1 - target_1)
label.new(bar_index, low, text=tostring(target_1), style=label.style_label_up, color=color.red, textcolor=color.white, yloc=yloc.belowbar)
sellEntryPrice_1 := na // Reset after label is created
if (not na(sellEntryPrice_2) and close <= sellEntryPrice_2 - target_2)
label.new(bar_index, low, text=tostring(target_2), style=label.style_label_up, color=color.red, textcolor=color.white, yloc=yloc.belowbar)
sellEntryPrice_2 := na // Reset after label is created