The Knockout generator displays three interactive horizontal lines - entry, stop-loss, and target - for configuring knock-out certificate parameters. Users can drag the lines or enter values directly, and the generator calculates the derived field CRV.
Use a Controller object to add the generator to a chart:
const knockoutGenerator = controller.addGenerator('KnockOutSearch');
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.
type LineType = 'entry' | 'stoploss' | 'target';
type LineChangeData = {
line: LineType,
value: number
};
type ValueChangeData = {
maxloss: number,
invested: number
};
Type: float
Details
The entry line value. Changing this recalculates the CRV and emits a lineChange event.
Type: float
Details
The stop-loss line value. Changing this recalculates the CRV and emits a lineChange event.
Type: float
Details
The target line value. Changing this recalculates the CRV and emits a lineChange event.
Type: float
Default: 0
Details
The maximum loss amount. Has no effect on chart, but can be used by the external application when searching. Only one of maxloss or invested can be non-zero at a time - setting maxloss resets invested to 0.
Type: float
Default: 0
Details
The invested amount. Has no effect on chart, but can be used by the external application when searching. Only one of maxloss or invested can be non-zero at a time - setting invested resets maxloss to 0.
Type: float (read-only)
Details
The calculated chance-risk ratio (CRV) based on the current entry, stop-loss, and target values. This option is read-only.
The generator emits a lineChange event when the user changes the values of the horizontal lines.
Type
interface Knockout {
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);
});
Type*
interface Knockout {
emit(type: 'valueChange', data: ValueChangeData): void;
}
Details
The generator also emits a valueChange event when the maxloss or invested 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);
});
Type
interface Knockout {
emit(type: 'openKOWidget'): void
}
Details
When the Open search button is pressed, the generator emits a openKOWidget event. This event does not contain any additional data.
Example
knockoutGenerator.on('openKOWidget', () => {
//openKOSearch();
});
Type
interface Knockout {
setLineValue(lineName: LineType, value: number): void;
}
Details
The generator has two public methods available. The first one, setLineValue, can be used to set the line values.
Type
interface Knockout {
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.