package com.jbooktrader.strategy;

import com.jbooktrader.indicator.balance.*;
import com.jbooktrader.indicator.price.*;
import com.jbooktrader.platform.indicator.*;
import com.jbooktrader.platform.model.*;
import com.jbooktrader.platform.optimizer.*;
import com.jbooktrader.strategy.base.*;

public class Sample extends StrategyES {

    // Technical indicators
    private Indicator balanceVelocityInd, priceVelocityInd;

    // Strategy parameters names
    private static final String PERIOD = "Period";
    private static final String SCALE = "Scale";
    private static final String ENTRY = "Entry";
    private static final String EXIT = "Exit";

    // Strategy parameters values
    private final int entry, exit, scale;


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

        entry = getParam(ENTRY);
        exit = getParam(EXIT);
        scale = getParam(SCALE);
    }

    @Override
    public void setParams() {
        addParam(PERIOD, 1800, 3600, 5, 3400);
        addParam(SCALE,6 , 30, 1, 12);
        addParam(ENTRY, -45, -105, 1, -60);
        addParam(EXIT, 60, 0, 1, 34);
    }

    @Override
    public void setIndicators() {
        balanceVelocityInd = addIndicator(new BalanceVelocity(1, 
getParam(PERIOD)));
        priceVelocityInd = addIndicator(new PriceVelocity(1, 
getParam(PERIOD)));

    }

    @Override
    public void onBookSnapshot() {
        double balanceVelocity = balanceVelocityInd.getValue();
        double priceVelocity = priceVelocityInd.getValue();

        double force = balanceVelocity - scale * priceVelocity;
        if (force >= entry && balanceVelocity > 0 && priceVelocity < 0) {
            goLong();
        } else if (force <= -exit) {
            goFlat();
        }
    }
}

On Tuesday, May 13, 2014 3:23:34 PM UTC-4, Eugene Kononov wrote:
>
>
>> I got PI 2.79 , net profit 6140 and total 245 trades, bias still at +100; 
>> but when I looking at chart, there is no short trades, all longs. and of 
>> course in a up trends, it made money.
>>
>>
>>
>
> Please post your version of Sample.java. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"JBookTrader" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/jbooktrader.
For more options, visit https://groups.google.com/d/optout.

Reply via email to