I'm trying to code an indicator that prints the slope of three oscillators and colors the chart background if the total is greater than a certain number.
For example, lets say the indicator has three CCIs with periods 10, 20 and 40 in one panel.
How can I code this indicator to display the total slope for all three lines on the chart or in the panel? In other words, I want the indicator to add the slope of all three lines and print that total somewhere on the chart.
If that total is greater than a given number X (let's say 10, for example), I want it to draw background: {BackBrush = Brushes.CornflowerBlue;}. The draw object isn't important. I'm trying to learn how to program functions using that slope total. (I've been asking the AIs and getting nowhere!)
I understand that the slope needs to be measured over a given distance. Let's specify slope length of 3 bars, the present bar and two bars in the past.
Thank you for your help!
Matt
Below is what I believe to be the relevant/useful CCI code for your reference.
The Set 1 Function colored red is nonsense - I'm not sure how to help more:
else if (State == State.DataLoaded)
{
CCI1 = CCI(Close, 10);
CCI2 = CCI(Close, 20);
CCI3 = CCI(Close, 40);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 3)
return;
// Set 1
if (
(Slope(CCI1, 10, 3) > 0)
&& (Slope(CCI2, 20, 3) > 0)
&& (Slope(CCI3, 40, 3) > 0)
)
{
BackBrush = Brushes.CornflowerBlue;
}

Comment