package jforex.strategies.indicators;

import java.text.DecimalFormat;

import com.dukascopy.api.*;

/**
 * The startegy prints out daily, weekly and monthly pivot levels
 *
 */
public class Pivot2 implements IStrategy {
	private IConsole console;
	private IIndicators indicators;

	private Instrument instrument = Instrument.EURUSD;
	
	private static String[] pivotLevelNames = { "P", "R1", "S1", "R2", "S2", "R3", "S3" };

	public void onStart(IContext context) throws JFException {
		this.console = context.getConsole();
		this.indicators = context.getIndicators();
		
		boolean showHistoricalLevels = true;
		double [] pivotDaily = indicators.pivot(instrument, Period.DAILY, OfferSide.BID, 7, showHistoricalLevels, 0);
		double [] pivotWeekly = indicators.pivot(instrument, Period.WEEKLY, OfferSide.BID, 8, showHistoricalLevels, 0);
		double [] pivotMonthly = indicators.pivot(instrument, Period.MONTHLY, OfferSide.BID, 9, showHistoricalLevels, 0);

		print("pivotMonthly " +arrayToString(pivotMonthly));
		print("pivotWeekly " +arrayToString(pivotWeekly));
		print("pivotDaily " +arrayToString(pivotDaily));		
		
	}

	private void print(Object message) {
		console.getOut().println(message);
	}
	
	public static String arrayToString(double [] arr){
		String str = "";
		for (int r=0; r<arr.length; r++) {
		    str += " " + pivotLevelNames[r] + ": "+ (new DecimalFormat("0.000000")).format(arr[r]) + "; ";
		}
		return str;
	}
	
	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 {}
	


}
