Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

one problem to fix range bar strategy tester
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=16&t=56430
Page 1 of 1

Author:  goose_ [ Wed 11 Apr, 2018, 15:20 ]
Post subject:  one problem to fix range bar strategy tester

Hi.
I have a problem with test my strategy, this is range bar strategy. In here is description of my problem https://images84.fotosik.pl/1035/e93aa69b73d4742f.png
I turn on this strategy in mode "process ticks on a defined price range change" and value 1. My PriceRange in strategy is 15. I want the strategy to work on 15 pips range bars. And I don't know what i'm doing wrong. When strategy is strarted I see different chart than the live chart EURUSD is. When strategy is stopped i switch for a while to 1 pip period, and switch again to 15 pip period and then I see right chart, correct range bar chart. But at the beginning bars are different and i don't know how to change this to correct bars like from EURUSD 15 pip bar chart we see right now in that time period. So, what is wrong? This is my strategy.
Regards.

package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IIndicators.AppliedPrice;

import com.dukascopy.api.feed.*;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;
import com.dukascopy.api.feed.util.*;

public class MyStrategy implements IStrategy, IFeedListener {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    private IChart chart;
    private IOrder order;
   
    public double amount = 0.001;
    public double slippage = 1;
   
    public IFeedDescriptor feedDescriptor = new RangeBarFeedDescriptor(Instrument.EURUSD, PriceRange.valueOf(15), OfferSide.BID);     
   
    private int counter = 0; // getLabel function global variable
   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
        this.chart = context.getChart(feedDescriptor.getInstrument());
        //chart.setDataPresentationType(DataType.DataPresentationType.RANGE_BAR.valueOf("ONE_PIP"));
     
        context.setSubscribedInstruments(java.util.Collections.singleton(feedDescriptor.getInstrument()), true);
        context.subscribeToFeed(feedDescriptor, this);
    }
   
    @Override
    public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
       
        IRangeBar rangeBar = (IRangeBar)feedData;

        try {
            createOrder(feedDescriptor, feedData, rangeBar);
        } catch (Exception e) {
            e.printStackTrace();
        }
       
    }

    public void createOrder(IFeedDescriptor feedDescriptor, ITimedData feedData, IRangeBar rangeBar) throws JFException {
       
        double stopLossPrice, takeProfitPrice;   

        if (rangeBar.getClose() > rangeBar.getOpen()) {
            // bull bar
            //print( "bull" );
            stopLossPrice = history.getLastTick(feedDescriptor.getInstrument()).getBid() + feedDescriptor.getInstrument().getPipValue() * 10;
            takeProfitPrice = history.getLastTick(feedDescriptor.getInstrument()).getBid() - feedDescriptor.getInstrument().getPipValue() * 10;
            double price = history.getLastTick(feedDescriptor.getInstrument()).getBid() + feedDescriptor.getInstrument().getPipValue() * 1;
            order = engine.submitOrder(getLabel(feedDescriptor.getInstrument()), Instrument.EURUSD, OrderCommand.SELLLIMIT, amount, price, slippage, stopLossPrice, takeProfitPrice);
            orderClose("sell");
        } else if (rangeBar.getClose() < rangeBar.getOpen()) { 
            // bear bar
            // print( "bear" );
            stopLossPrice = history.getLastTick(feedDescriptor.getInstrument()).getAsk() - feedDescriptor.getInstrument().getPipValue() * 10;
            takeProfitPrice = history.getLastTick(feedDescriptor.getInstrument()).getAsk() + feedDescriptor.getInstrument().getPipValue() * 10;
            double price = history.getLastTick(feedDescriptor.getInstrument()).getAsk() + feedDescriptor.getInstrument().getPipValue() * 1;
            order = engine.submitOrder(getLabel(feedDescriptor.getInstrument()), Instrument.EURUSD, OrderCommand.BUYLIMIT, amount, price, slippage, stopLossPrice, takeProfitPrice);   
            orderClose("buy");
        } 
 
    }

    private void orderClose(String str) throws JFException {
        for (IOrder order : engine.getOrders()) {
            if (str == "buy") {
                if (order.getState() == IOrder.State.OPENED) {
                    //print( order.getId() + " " + order.getState() );
                    order.close();
                }
            } else if (str == "sell") {
                if (order.getState() == IOrder.State.OPENED) {
                    //print( order.getId() + " " + order.getState() );
                    order.close();
                }
            }
        }
    }

    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 {}

    protected String getLabel(Instrument instrument) {
        String label = instrument.name();
        label = label + (counter ++);
        label = label.toUpperCase();
        return label;
    }
   
    public void print(Object obj) {
        console.getOut().println(obj);
    }
}



Image

Attachments:
jforex range bar tester error.png [192.02 KiB]
Downloaded 291 times

Author:  goose_ [ Thu 19 Apr, 2018, 23:26 ]
Post subject:  Re: one problem to fix range bar strategy tester

Ok, Vadim Berezhnoj helped me to solve this problem.

Hello.

1. Range bars can be calculated from ticks or from interpolated data of 1M or 1H candles:
[screenshot1.png] https://www.dukascopy.com/swiss/english/forex/jforex/forum/download/file.php?un=1&id=9658

2. Historical Tester has its own input data interpolation settings (for test speed up):
[screenshot2.png] https://www.dukascopy.com/swiss/english/forex/jforex/forum/download/file.php?un=1&id=9659

3. When interpolation method other than "Process all ticks" is selected, tested strategy and HT chart in visual mode will receive only this interpolated ticks and candles / PA bars built from them. Of course, they can differ significantly from candles / bars built from all available ticks, which are displayed on regular charts.
Compare data on HT charts before "Test start" time marker (without interpolation) and after it (only ticks with 1 pip price change were processed during test):
[screenshot4.png] https://www.dukascopy.com/swiss/english/forex/jforex/forum/download/file.php?un=1&id=9660
[screenshot3.png] https://www.dukascopy.com/swiss/english/forex/jforex/forum/download/file.php?un=1&id=9661

4. When test is finished, data on HT charts should not change after chart reload or switching to other period and back (interpolated data from local cache must be used).
This issue was fixed for PA charts - fix will be available in next platform release.

Kind regards, Support Team.

...

And here is my settings which solved my problem https://images82.fotosik.pl/1049/a970664ca0d191a8.png . I have "default" before, in frame "range bar calculation settings" but right now I switch from "deafult" to "all ticks" and in tester control panel my settings is "ticks - bid - process all ticks" and everything works fine !!!

So, this is guide how to solve this problem. Ok, thanks support, thank you again Vadim Berezhnoj.
Regards.

Attachments:
screenshot1.png [49.26 KiB]
Downloaded 248 times
screenshot2.png [21.67 KiB]
Downloaded 246 times
screenshot3.png [37.26 KiB]
Downloaded 237 times
screenshot4.png [34.39 KiB]
Downloaded 244 times

  Page 1 of 1