package jforex.strategies.indicators;

import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;

@RequiresFullAccess
public class RSITest implements IStrategy {
	
	@Configurable("")
	public Period period = Period.FOUR_HOURS;
	@Configurable("")
	public Instrument instrument = Instrument.EURAUD;
	@Configurable("")
	public OfferSide side = OfferSide.BID;
	@Configurable("")
	public AppliedPrice appliedPrice = AppliedPrice.CLOSE;
	@Configurable("")
	public int timePeriod = 14;
	
	private IIndicators indicators;
	private IConsole console;
	private IHistory history;
	

	@Override
	public void onStart(IContext context) throws JFException {
		indicators = context.getIndicators();
		console = context.getConsole();
		history = context.getHistory();
		long time = history.getBarStart(period, history.getLastTick(instrument).getTime());
		
		double RSI=indicators.rsi(instrument, period, side, appliedPrice, 14, 0);
		double[] RSIArray =indicators.rsi(instrument, period, side, appliedPrice, 14, 
				Filter.WEEKENDS, 1, time, 0);
		//in this case RSIArray[RSIArray.length - 1] = RSIArray[0] since the array length is 1, 
		//we use here RSIArray.length - 1 in order to stress that the last element is the latest one
	    console.getOut().println(String.format("rsi no filter: %.5f, weekend filter: %.5f", RSI, RSIArray[RSIArray.length - 1]));

	    context.stop();
	}

	@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 {}

}
