private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
    """
	Runs a strategy over a time series and adds the value markers
	corresponding to buy/sell signals to the plot.
	@param series a time series
	@param strategy a trading strategy
	@param plot the plot
    """
        // Running the strategy
        TimeSeriesManager seriesManager = new TimeSeriesManager(series);
        List<Trade> trades = seriesManager.run(strategy).getTrades();
        // Adding markers to plot
        for (Trade trade : trades) {
            // Buy signal
            double buySignalTickTime = new Minute(Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
            Marker buyMarker = new ValueMarker(buySignalTickTime);
            buyMarker.setPaint(Color.GREEN);
            buyMarker.setLabel("B");
            plot.addDomainMarker(buyMarker);
            // Sell signal
            double sellSignalTickTime = new Minute(Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
            Marker sellMarker = new ValueMarker(sellSignalTickTime);
            sellMarker.setPaint(Color.RED);
            sellMarker.setLabel("S");
            plot.addDomainMarker(sellMarker);
        }
    }
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
        // Running the strategy
        TimeSeriesManager seriesManager = new TimeSeriesManager(series);
        List<Trade> trades = seriesManager.run(strategy).getTrades();
        // Adding markers to plot
        for (Trade trade : trades) {
            // Buy signal
            double buySignalTickTime = new Minute(Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
            Marker buyMarker = new ValueMarker(buySignalTickTime);
            buyMarker.setPaint(Color.GREEN);
            buyMarker.setLabel("B");
            plot.addDomainMarker(buyMarker);
            // Sell signal
            double sellSignalTickTime = new Minute(Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
            Marker sellMarker = new ValueMarker(sellSignalTickTime);
            sellMarker.setPaint(Color.RED);
            sellMarker.setLabel("S");
            plot.addDomainMarker(sellMarker);
        }
    }
private static void addBuySellSignals ( TimeSeries series , Strategy strategy , XYPlot plot ) { // Running the strategy TimeSeriesManager seriesManager = new TimeSeriesManager ( series ) ; List < Trade > trades = seriesManager . run ( strategy ) . getTrades ( ) ; // Adding markers to plot for ( Trade trade : trades ) { // Buy signal double buySignalTickTime = new Minute ( Date . from ( series . getTick ( trade . getEntry ( ) . getIndex ( ) ) . getEndTime ( ) . toInstant ( ) ) ) . getFirstMillisecond ( ) ; Marker buyMarker = new ValueMarker ( buySignalTickTime ) ; buyMarker . setPaint ( Color . GREEN ) ; buyMarker . setLabel ( "B" ) ; plot . addDomainMarker ( buyMarker ) ; // Sell signal double sellSignalTickTime = new Minute ( Date . from ( series . getTick ( trade . getExit ( ) . getIndex ( ) ) . getEndTime ( ) . toInstant ( ) ) ) . getFirstMillisecond ( ) ; Marker sellMarker = new ValueMarker ( sellSignalTickTime ) ; sellMarker . setPaint ( Color . RED ) ; sellMarker . setLabel ( "S" ) ; plot . addDomainMarker ( sellMarker ) ; } }
Runs a strategy over a time series and adds the value markers
corresponding to buy/sell signals to the plot.
@param series a time series
@param strategy a trading strategy
@param plot the plot
Runs a strategy over a time series and adds the value markers corresponding to buy / sell signals to the plot .