package charts.test;

import java.awt.Color;
import java.util.UUID;

import com.dukascopy.api.*;
import com.dukascopy.api.drawings.IRayLineChartObject;

public class RayLine implements IStrategy {

    private IChart chart;
    private IHistory history;
    
    @Override
    public void onStart(IContext context) throws JFException {
        this.chart = context.getChart(Instrument.EURUSD);
        this.history = context.getHistory();
        ITick tick = history.getLastTick(Instrument.EURUSD);    

        double price1 = (tick.getAsk() + tick.getBid()) / 2;
        IRayLineChartObject line1 = chart.getChartObjectFactory().createRayLine();
        line1.setPrice(0, price1);
        line1.setTime(0, tick.getTime());
        line1.setPrice(1, price1 - 0.0010);
        //5 bars ahead
        line1.setTime(1, tick.getTime() - chart.getSelectedPeriod().getInterval() * 5);
        line1.setColor(Color.BLUE);
        chart.addToMainChart(line1);
        
        //use the same coordinates, but change the style
        IRayLineChartObject line2 = chart.getChartObjectFactory().createRayLine(UUID.randomUUID().toString(),
                line1.getTime(0), line1.getPrice(0),
                line1.getTime(1), line1.getPrice(1));
        line2.setOpacity(0.2f);
        line2.setColor(Color.RED);
        line2.setLineWidth(10);
        chart.addToMainChart(line2);
        
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {}

}
