i want to draw divergence lines on a momentum indicator.
if price makes a new high in a certain amount of bars, and momentum does not make a new high:
i want to have a line drawn from the peak of the momentum at the same bar that price made its last high within the period to i suppose would be momentum[0] technically where the new high has been identified.
that being said, i have tried to start at the easiest point i could and get the higher high of price and whenever price makes a new high within my 2 hour timeframe i want an arrow to plot above the high of that bar where the latest high was reached.
this is kicking my butt. i really need help. perhaps something is off in my code? its a 21 period momentum im going to use. 1 or 3 minute chart.
protected override void OnBarUpdate()
{
if (CurrentBar < 1);
return;
Value[0] = CurrentBar == 0 ? 0 : Input[0] - Input[Math.Min(CurrentBar, Period)];
Momentum Mom = Momentum(Period);
double PreviousPriceHigh = double.MinValue;
int PreviousHighBar= -1;
int LookBackPeriod = 120;
for (int i = 1; i < LookBackPeriod; i++)
if (High[0]> PreviousPriceHigh)
{
PreviousPriceHigh = High[i];
PreviousHighBar = i;
Print("Bar " + i + " Price: " + High[i] + " Time: " + Time[0]);
Draw.ArrowUp(this, "HigherHigh",true,PreviousHighBar,High[0],Brushes.White);
}
}
any help at all would be so greatly appreciated.

Comment