PDA

View Full Version : Hiding a plotted DataSeries in an indicator


tquinn
01-12-2007, 11:10 AM
I have an indicator which calculates support/resistance levels and displays them with DrawHorizontalLine. These "levels" are not "Plotted", therefore they are not used in AutoScale.

However, as prices approach one of these levels I would like the S/R line to come on screen prior to the currentbar actually reaching that line, so I can observe price behaviour as it approaches S/R.

I can do this by adding a plot, and letting AutoScale=true make the S/R line visible. This would then make public those plotted values, and there is no reason, since they are used only for controlling "white space" on the chart.

Ideas?

Raditz
01-12-2007, 05:17 PM
You can control the chart white space by override the GetMinMaxValues() function,
let me know if you need help.

Muly
Final
http://fin-alg.com/

tquinn
01-13-2007, 02:12 AM
Thanks for the reply. I'm not a good enough programmer to take this nugget of wisdom and run.

If the market is at 801.1 and I have a Resistance at 802.5 (15 ticks away), I want to make the Resistance Line appear on screen (if it is not already visible).

More help please.

NinjaTrader_Ray
01-13-2007, 02:32 AM
Why not go with your second approach, and try something like:

AutoScale = Math.Abs(Close[0] - supportLineValue)/ TickSize> 14 ? true: false;



I have never tried this but I believe that AutoScale property can be set dynamically.

Ray

tquinn
01-13-2007, 03:38 AM
Thanks Ray,

I was trying to make the S/R lines visible without making public useless data.

If I understand your code sample, it will only work if there is a plotted element that AutoScale can process. If I do that, those values are made public, but they have no value to the public.

Is there a way to Plot without making the plotted values public, and still have those values considered by AutoScale?

I get the idea that AutoScale evaluates all plots (Where AutoScale is true) and produces the values held by GetMinMaxValues(), Raditz was proposing to Directly set GetMinMaxValues(), effectively bypassing AutoScale. This approach (if I understand it right) will do what I want. However I still can't figure out the Syntax.

NinjaTrader_Ray
01-13-2007, 06:19 AM
Adding a plot always increments the Values[] array by adding an object. The Values array is always public.

GetMinMaxValues() will work as Muly suggested but this is outside of what NinjaTrader will support at this time. Muly might be able to provide you with a sample that will point you in the right direction.

Ray

Raditz
01-13-2007, 09:01 AM
Use this as a psedo code, it is not complete nor tested code

public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
{
//Go over all the visible bars in the chart
for (int i = 0; i < ChartControl.BarsPainted; i++)
{
int barNo = ((chartControl.LastBarPainted - chartControl.BarsPainted) + 1) + i;
if (barNo>= 0) && (barNo< Bars.Count)
{
if (R2.Get(num3) - max < 5 * TickSize)
{
//R2 is within 5 ticks from the visible area of the chart, make it visible
max = Math.Max(max, R2.Get(num3)+2*TickSize);
}

if (min - R2.Get(num3) < 5 * TickSize)
{
//R2 is within 5 ticks from the visible area of the chart, make it visible
min = Math.Min(min, R2.Get(num3)-2*TickSize);
}

}
}
}
Muly
Final
http://fin-alg.com/

tquinn
01-13-2007, 11:42 AM
Muly Thanks,

This is the code I ended up with. I removed your loops checking all bars on the chart, evidently AutoScale does this. Working well so far.
[line] OnBarUpdate()
{
(FoundValue)= Next Resistance above Close[0]
(FoundIncr)=Distance from FoundValue to Support below Close[0]
}

public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
{
// define variables using values from OnBarUpdate()
if (Math.Abs(ChartControl.LastBarPainted-Bars.Count)<10)
{
double above=FoundValue;
double below=FoundValue-FoundIncr;
if (above - High[0] < FoundIncr/ 2 )
max = Math.Max(max, above + 2*TickSize);
if (Low[0] - below < FoundIncr/ 2 )
min = Math.Min(min, below - 2*TickSize);
}
}

[line]