Area in between any two plots can be filled with a color (often semi-transparent). To use this feature there are
@fill
decorator and a Fill
class.
In the first place the @fill
decorator declares which two plots should be used for filling. Optionally
it may have a color argument, which should be used if a single-colored fill is desired.
The simplest possible usecase fills the space between two plot lines:
# indie:lang_version = 2
from indie import indicator, color, plot, fill, Fill
@indicator('Example 1', overlay_main_pane=True)
@plot('p1')
@plot('p2')
@fill('p1', 'p2', color=color.BLUE(0.2))
def main(ctx):
a = ctx.high
b = ctx.low
return a[0], b[0], Fill()
Please note, that both @fill
decorator and Fill
object always must be used together. Even in simple cases
of a single-colored fills where Fill
object is constructed with all default values (i.e. with no arguments Fill()
).
If a multicolored fill is needed, then the color value should be calculated in the main
function code and passed
as argument to a Fill
object returned by the main
function.
# indie:lang_version = 2
from indie import indicator, color, plot, fill, Fill
@indicator('Example 2', overlay_main_pane=True)
@plot('p1')
@plot('p2')
@fill('p1', 'p2')
def main(ctx):
c = color.GREEN(0.5) if ctx.close[0] > ctx.open[0] else color.RED(0.5)
return ctx.high[0], ctx.low[0], Fill(color=c) # NOTE: This color will override color in @fill decorator if any
Fill()
has an optional parameter offset: int
. It may be used to shift the coloring to the left (if offset
is
negative) or to the rigth (if offset
is positive):
# indie:lang_version = 2
from indie import indicator, color, plot, fill, Fill, param
@indicator('Example 3', overlay_main_pane=True)
@plot('p1')
@plot('p2')
@fill('p1', 'p2')
@param.int('fill_offset', default=2)
def main(ctx, fill_offset):
c = color.GREEN(0.5) if ctx.close[0] > ctx.open[0] else color.RED(0.5)
return ctx.high[0], ctx.low[0], Fill(color=c, offset=fill_offset)
Please note, that a non-zero fill offset
has effect only to multi-colored fills and has none to single-colored ones.
@level()
decorator creates a level (horizontal line).
@level(
value: float,
title: indie.Optional[str] = None,
line_color: indie.Color = indie.color.GRAY(0.5),
line_style: int = indie.line_style.DASHED,
line_width: int = 1
) -> NoneType
Parameters:
value
— Value of the level on a vertical scale of an indicator.title
— Human readable title which is visible in the indicator's Settings panel.line_color
— Color of the line.line_style
— Style of the line. It is represented as enum value of type line_style
.line_width
— Width of the line.Example:
# indie:lang_version = 2
from indie import indicator, level, color
@indicator('Level example')
@level(150, line_color=color.RED, line_width=4)
def main(ctx):
return ctx.close[0]
@band()
decorator creates a band (two horizontal lines usually with a semi-transparent fill in between them).
@band(
value1: float,
value2: float,
title: indie.Optional[str] = None,
fill_color: indie.Color = indie.color.GREEN(0.05),
line_color: indie.Color = indie.color.GRAY(0.5),
line_style: int = indie.line_style.DASHED,
line_width: int = 1
) -> NoneType
Parameters:
value1
— Value of the first horizontal line of a band on a vertical scale of an indicator.value2
— Value of the second horizontal line of a band on a vertical scale of an indicator.title
— Human readable title which is visible in the indicator's Settings panel.fill_color
— Color of the background.line_color
— Color of the line.line_style
— Style of the line. It is represented as enum value of type line_style
.line_width
— Width of the line.Example:
# indie:lang_version = 2
from indie import indicator, band, color
@indicator('Band example')
@band(145, 155, line_color=color.RED, line_width=4)
def main(ctx):
return ctx.close[0]