-- 
-- Ted

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"JBookTrader" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jbooktrader?hl=en
-~----------~----~----~----~------~----~------~--~---

package com.jbooktrader.strategy;

import com.jbooktrader.indicator.depth.*;
import com.jbooktrader.indicator.price.*;
import com.jbooktrader.platform.indicator.*;
import com.jbooktrader.platform.model.*;
import com.jbooktrader.platform.optimizer.*;

/**
 *
 */
public class HanSolo extends StrategyES {

    // Technical indicators
    private final Indicator balanceRsiInd, rsiInd;

    // Strategy parameters names
    private static final String DEPTH_RSI_PERIOD = "EmaPeriod";
    private static final String RSI_PERIOD = "RsiPeriod";
    private static final String BALANCE_ENTRY = "BalanceEntry";
    private static final String RSI_ENTRY = "RsiEntry";

    // Strategy parameters values
    private final int balanceEntry, rsiEntry;


    public HanSolo(StrategyParams optimizationParams) throws 
JBookTraderException {
        super(optimizationParams);

        balanceEntry = getParam(BALANCE_ENTRY);
        rsiEntry = getParam(RSI_ENTRY);

        // Create technical indicators
        rsiInd = new PriceRSI(getParam(RSI_PERIOD));
        balanceRsiInd = new DepthBalanceRSI(getParam(DEPTH_RSI_PERIOD));
        addIndicator(rsiInd);
        addIndicator(balanceRsiInd);
    }

    /**
     * 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(DEPTH_RSI_PERIOD, 1, 126, 2, 21);
        addParam(RSI_PERIOD, 1, 201, 2, 35);
        addParam(BALANCE_ENTRY, 1, 51, 2, 43);
        addParam(RSI_ENTRY, 1, 51, 2, 47);
    }

    /**
     * This method is invoked by the framework when an order book changes and 
the technical
     * indicators are recalculated. This is where the strategy itself should be 
defined.
     */
    @Override
    public void onBookChange() {
        double rsi = rsiInd.getValue() - 50;
        double balanceRsi = balanceRsiInd.getValue();
        if (balanceRsi >= balanceEntry && rsi <= -rsiEntry) {
            setPosition(1);
        } else if (balanceRsi <= -balanceEntry && rsi >= rsiEntry) {
            setPosition(-1);
        }
    }
}

Reply via email to