PriceLevels

View as Markdown

Definition

A collection of PriceLevel objects defining lines for multi-price-level Drawing Tools (Fibonacci tools, etc.). Each PriceLevel within the collection can be configured programmatically or analyzed to obtain the parameters of user-drawn objects.

PriceLevels is only used with the following pre-built Drawing Tools, but it can be used with custom Drawing Tools, as well:

Syntax

PriceLevels[int idx]

PriceLevels[int idx].GetPrice(double startPrice, double totalPriceRange, bool isInverted)

PriceLevels[int idx].GetY(ChartScale chartScale, double startPrice, double totalPriceRange, bool isInverted)

Methods and Properties

Method/PropertyDescription
GetPrice()Returns a double which represents the price value at the specified price level
GetY()Returns a float representing the y-pixel coordinate at the specified price level
NameThe Name property of the specified PriceLevel. Set to a formatted version of Value by default.
StrokeThe Stroke used to draw the line associated with the specified PriceLevel
TagA tag used to identify the specified PriceLevel. Null by default.
ValueThe value of the PriceLevel in percentage terms

Examples

1// Define a FibonacciRetracements object outside of OnBarUpdate(), so the same object can be re-used**
2FibonacciRetracements myRetracements;
3
4protected override void OnBarUpdate()
5{
6 if (CurrentBar < 20)
7 return;
8
9 // Instantiate myRetracements
10 myRetracements = Draw.FibonacciRetracements(this, "fib", true, 20, High[20], 2, Low[2]);
11
12 // Print each price level and the corresponding value in the PriceLevels collection contain in myRetracements
13 // setting isInverted correctly is important for the Fibonacci Retracements since it will define which starting point is used, as it changes based
14 // on the anchors, i.e. if the Fibonacci is drawn from 100% to 0% (default) or the other inverted way (0% to 100%).
15 foreach (PriceLevel p in myRetracements.PriceLevels)
16 {
17 Print(p.Value);
18 Print(p.GetPrice(myRetracements.StartAnchor.Price, myRetracements.EndAnchor.Price - myRetracements.StartAnchor.Price, false));
19 }
20}
1// Define a TrendChannel object outside of OnBarUpdate(), so the same object can be re-used
2TrendChannel myTCh;
3
4protected override void OnBarUpdate()
5{
6 if (CurrentBar < 20)
7 return;
8
9 // Instantiate myTrendChannel
10 myTCh = Draw.TrendChannel(this, "tc", true, 10, Low[10], 0, High[0], 10, High[10] + 5 * TickSize);
11
12 // Print each price level and the corresponding value in the PriceLevels collection contain in myTrendChannel
13 // For the TrendChannel the 0% is the Trend anchor, the 100% the Parallel anchor
14 foreach (PriceLevel p in myTCh.PriceLevels)
15 {
16 Print(p.Value);
17 Print(p.GetPrice(myTCh.TrendStartAnchor.Price, myTCh.ParallelStartAnchor.Price - myTCh.TrendStartAnchor.Price, false));
18 }
19}