Please help with this code, I don't know coding, so copy and past from different indicators of our forum members.
I want 5 min first bar's position compared to ema 21, and study should stop after closing of first bar.
Here is the code I compiled,
input agg = AggregationPeriod.DAY;
input StartTime = 0930;
input EndTime = 0935;
def c = close;
def o = open;
def ORActive = if SecondsFromTime(StartTime) > 0 and
SecondsTillTime(EndTime) >= 0
then 1
else 0;
def BC = if ORActive and !ORActive[1]
then c
else Double.NaN;
def BO = if ORActive and !ORActive[1]
then o
else Double.NaN;
input length = 21;
def AvgExp = ExpAverage(close, length);
plot trend = if o > avgexp and c > avgexp and c > o then 111 else if o > avgexp and c > avgexp and c < o then 11 else if o < avgexp and c > avgexp and c > o then 1 else if o < avgexp and c < avgexp and c < o then -111 else if o < avgexp and c < avgexp and c > o then -11 else if o > avgexp and c < avgexp and c < o then -1 else 0;
assignBackgroundColor(if trend > 0 then color.dark_green else if trend < 0 then color.Dark_red else color.Gray);
After first bar is over, it changes for second bar.
Please help....
Thanks
I want 5 min first bar's position compared to ema 21, and study should stop after closing of first bar.
Here is the code I compiled,
input agg = AggregationPeriod.DAY;
input StartTime = 0930;
input EndTime = 0935;
def c = close;
def o = open;
def ORActive = if SecondsFromTime(StartTime) > 0 and
SecondsTillTime(EndTime) >= 0
then 1
else 0;
def BC = if ORActive and !ORActive[1]
then c
else Double.NaN;
def BO = if ORActive and !ORActive[1]
then o
else Double.NaN;
input length = 21;
def AvgExp = ExpAverage(close, length);
plot trend = if o > avgexp and c > avgexp and c > o then 111 else if o > avgexp and c > avgexp and c < o then 11 else if o < avgexp and c > avgexp and c > o then 1 else if o < avgexp and c < avgexp and c < o then -111 else if o < avgexp and c < avgexp and c > o then -11 else if o > avgexp and c < avgexp and c < o then -1 else 0;
assignBackgroundColor(if trend > 0 then color.dark_green else if trend < 0 then color.Dark_red else color.Gray);
After first bar is over, it changes for second bar.
Please help....
Thanks