KnockOut Generator
Add to Chart:
Use a BG.charts.Controller object to add the generator to a chart:
const knockoutGenerator = controller.addGenerator('KnockOutGenerator');
The generator initializes three lines with the following values:
entry
: current close
value of the latest candle.
stoploss
: 15% of the chart height below the entry
line.
target
: 15% of the chart height above the entry
line.
Types
type LineType = 'entry' | 'stoploss' | 'target';
type LineChangeData = {
line: LineType,
value: number
};
type ValueChangeData = {
maxloss: number,
invested: number
};
Events:
The generator emits a lineChange
event when the user changes the values of the horizontal lines.
#lineChange
-
Type
interface KnockoutGeneratorGenerator {
emit(type: 'lineChange', data: LineChangeData): void;
} -
Details
When drag and drop is used, the event is fired 300ms after the last movement, to avoid emitting too many events.
-
Example
// example usage
knockoutGenerator.on('lineChange', (data) => {
console.log(data);
});
#valueChange
-
Type*
interface KnockoutGeneratorGenerator {
emit(type: 'valueChange', data: ValueChangeData): void;
} -
Details
The generator also emits a
valueChange
event when themaxloss
orinvested
field is edited. As only one of the two number fields can be used at a time, the second one will be reset to zero. -
Example
// example usage
knockoutGenerator.on('valueChange', (data) => {
console.log(data);
});
#openKOWidget
-
Type
interface KnockoutGeneratorGenerator {
emit(type: 'openKOWidget'): void
} -
Details
When the
Open search
button is pressed, the generator emits aopenKOWidget
event. This event does not contain any additional data. -
Example
knockoutGenerator.on('openKOWidget', () => {
//openKOSearch();
});
Public methods:
#setLineValue
-
Type
interface KnockoutGeneratorGenerator {
setLineValue(lineName: LineType, value: number): void;
} -
Details
The generator has two public methods avavilable. The first one,
setLineValue
, can be used to set the line values.
#getValues
-
Type
interface KnockoutGeneratorGenerator {
getValues(): {
entry: number,
stoploss: number,
target: number,
maxloss: number,
invested: number
}
} -
Details
The second one,
getValues
, returns all values that can be set by the user.