package jforex;

import java.util.*;

import com.dukascopy.api.*;

public class ErrorDemo implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    
    // Declaring Configurable Variables
    @Configurable("Trading Instrument")
    public Instrument tInstrument = Instrument.EURUSD;
    @Configurable("Bars On Sides")
    public int barsOnSides = 3;
    @Configurable("Sample Size")
    public int sampleSize = 1000;
    
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
        
        List<IBar> barList;
        double[][] fractal;
        long from;
        long lastTickTime;
        long to;
        
        Period tPeriod = Period.WEEKLY;
        lastTickTime = history.getTimeOfLastTick(tInstrument);
        from = history.getTimeForNBarsBack(tPeriod, lastTickTime, sampleSize + barsOnSides);
        to = history.getTimeForNBarsBack(tPeriod, lastTickTime, barsOnSides);
        barList = history.getBars(tInstrument, tPeriod, OfferSide.ASK, Filter.ALL_FLATS, from, to);
        fractal = indicators.fractal(tInstrument, tPeriod, OfferSide.ASK, barsOnSides, Filter.ALL_FLATS, from, to);
        console.getOut().println("Length Data for Period: " + tPeriod.toString());
        console.getOut().println("Bars List Length: " + barList.size());
        console.getOut().println("Fractal Indicator Length: " + fractal[0].length);
        
        tPeriod = Period.DAILY;
        lastTickTime = history.getTimeOfLastTick(tInstrument);
        from = history.getTimeForNBarsBack(tPeriod, lastTickTime, sampleSize + barsOnSides);
        to = history.getTimeForNBarsBack(tPeriod, lastTickTime, barsOnSides);
        barList = history.getBars(tInstrument, tPeriod, OfferSide.ASK, Filter.ALL_FLATS, from, to);
        fractal = indicators.fractal(tInstrument, tPeriod, OfferSide.ASK, barsOnSides, Filter.ALL_FLATS, from, to);
        console.getOut().println("Length Data for Period: " + tPeriod.toString());
        console.getOut().println("Bars List Length: " + barList.size());
        console.getOut().println("Fractal Indicator Length: " + fractal[0].length);
        
        tPeriod = Period.DAILY_SKIP_SUNDAY;
        lastTickTime = history.getTimeOfLastTick(tInstrument);
        from = history.getTimeForNBarsBack(tPeriod, lastTickTime, sampleSize + barsOnSides);
        to = history.getTimeForNBarsBack(tPeriod, lastTickTime, barsOnSides);
        barList = history.getBars(tInstrument, tPeriod, OfferSide.ASK, Filter.ALL_FLATS, from, to);
        fractal = indicators.fractal(tInstrument, tPeriod, OfferSide.ASK, barsOnSides, Filter.ALL_FLATS, from, to);
        console.getOut().println("Length Data for Period: " + tPeriod.toString());
        console.getOut().println("Bars List Length: " + barList.size());
        console.getOut().println("Fractal Indicator Length: " + fractal[0].length);
        
        tPeriod = Period.DAILY_SUNDAY_IN_MONDAY;
        lastTickTime = history.getTimeOfLastTick(tInstrument);
        from = history.getTimeForNBarsBack(tPeriod, lastTickTime, sampleSize + barsOnSides);
        to = history.getTimeForNBarsBack(tPeriod, lastTickTime, barsOnSides);
        barList = history.getBars(tInstrument, tPeriod, OfferSide.ASK, Filter.ALL_FLATS, from, to);
        fractal = indicators.fractal(tInstrument, tPeriod, OfferSide.ASK, barsOnSides, Filter.ALL_FLATS, from, to);
        console.getOut().println("Length Data for Period: " + tPeriod.toString());
        console.getOut().println("Bars List Length: " + barList.size());
        console.getOut().println("Fractal Indicator Length: " + fractal[0].length);
        
        tPeriod = Period.ONE_HOUR;
        lastTickTime = history.getTimeOfLastTick(tInstrument);
        from = history.getTimeForNBarsBack(tPeriod, lastTickTime, sampleSize + barsOnSides);
        to = history.getTimeForNBarsBack(tPeriod, lastTickTime, barsOnSides);
        barList = history.getBars(tInstrument, tPeriod, OfferSide.ASK, Filter.ALL_FLATS, from, to);
        fractal = indicators.fractal(tInstrument, tPeriod, OfferSide.ASK, barsOnSides, Filter.ALL_FLATS, from, to);
        console.getOut().println("Length Data for Period: " + tPeriod.toString());
        console.getOut().println("Bars List Length: " + barList.size());
        console.getOut().println("Fractal Indicator Length: " + fractal[0].length);
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
    
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}