package jforex;
import java.util.*;
import com.dukascopy.api.*;

public class WmaTest implements IStrategy {
    private IContext context;    
    private IIndicators indicators;
    private IHistory history;
    private IConsole console;
    
    public void onStart(IContext context) throws JFException {
        this.context = context;        
        this.indicators = context.getIndicators();
        this.history = context.getHistory();    
        this.console = context.getConsole();
    }

    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 {
        if (instrument == Instrument.GBPUSD){
            long time = history.getPreviousBarStart(Period.FOUR_HOURS ,history.getLastTick(Instrument.GBPUSD).getTime());
            int i = 1;
            do {
                double[] a = indicators.wma(Instrument.GBPUSD, Period.FOUR_HOURS, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 27, Filter.NO_FILTER, 1, time, 0);
            
                double b = indicators.wma(Instrument.GBPUSD, Period.FOUR_HOURS, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 27, i);
            
                double[] c = indicators.wma(Instrument.GBPUSD, Period.FOUR_HOURS, OfferSide.BID, IIndicators.AppliedPrice.MEDIAN_PRICE, 27, time, time);
                    
                if (a.length > 0 && c.length > 0 && !Double.valueOf(b).isNaN()){            
                    console.getOut().print("A: "+a[0]);
                    console.getOut().print(", B: "+b);
                    console.getOut().println(", C: "+c[0]);
                }
                time = history.getTimeForNBarsBack(Period.FOUR_HOURS, time, 2);
                ++i;
            } while (i < 10);
            context.stop();
        }
    }
    
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}