package com.jbooktrader.strategy;

import com.jbooktrader.indicator.velocity.*;
import com.jbooktrader.platform.indicator.*;
import com.jbooktrader.platform.model.*;
import com.jbooktrader.platform.optimizer.*;
import com.jbooktrader.strategy.base.*;

/**
 *
 */
public class KalmanTest extends StrategyES {

	// Technical indicators
	private Indicator tensionKalmanInd;

	// Strategy parameters names
	private static final String FAST_ERROR = "Fast Error";
	private static final String SLOW_ERROR = "Slow Error";
	private static final String ENTRY = "Entry";
    //private static final String EXIT = "Exit";

	// Strategy parameters values
    private final int entry;//, exit;

	public KalmanTest(StrategyParams optimizationParams) throws JBookTraderException {
		super(optimizationParams);
		entry = getParam(ENTRY);
        //exit = getParam(EXIT);
	}

	@Override
	public void setIndicators() {
		tensionKalmanInd = addIndicator(new TensionKalman(getParam(FAST_ERROR), getParam(SLOW_ERROR)));
	}

	/**
	 * Adds parameters to strategy. Each parameter must have 5 values: name:
	 * identifier min, max, step: range for optimizer value: used in backtesting
	 * and trading
	 */
	@Override
	public void setParams() {
		addParam(FAST_ERROR, 0, 100, 1, 0);
		addParam(SLOW_ERROR, 0, 100, 1, 5);
        addParam(ENTRY, 15, 40, 1, 22);
        //addParam(EXIT, 1, 15, 1, 9);
	}

	/**
	 * Framework invokes this method when a new snapshot of the limit order book
	 * is taken and the technical indicators are recalculated. This is where the
	 * strategy itself (i.e., its entry and exit conditions) should be defined.
	 */
	@Override
	public void onBookSnapshot() {
		
		double tension = tensionKalmanInd.getValue();
		if (tension >= entry) {
			setPosition(1);
		} else if (tension <= -entry) {
			setPosition(-1);
        } /*else if (Math.abs(tension) <= exit) {
            setPosition(0);
		}   */
		
	}
}
