Chartbreaker
    Preparing search index...

    Knockout Generator

    Use a Controller object to add the generator to a chart:

    const knockoutGenerator = controller.addGenerator('KnockOuts');
    

    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
    };

    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 avavilable. 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.