Dukascopy
 
 
Wiki JStore Search Login

BARS FILTER 4 WEEKEND
 Post subject: BARS FILTER 4 WEEKEND Post rating: 0   New post Posted: Tue 16 Jul, 2013, 14:42 
User avatar

User rating: 0
Joined: Fri 24 Aug, 2012, 21:23
Posts: 4
Location: Italy, Rome
Hi guys,

i have a little problem. When I do my back-test, on ONE_HOUR time-frame, the historical tester take also the flats bars of the week-end. I know there are filters but i don't know how to use them.
Now I'm using the getBar method with shift.

This is the situation:

LONG ENTRY: if the close of the last bar is the lowest of the last 5 bars, BUY.

but when the market open (22:00 gmt:0 on sunday) sometime I have a wrong entry signal, because the platform read all the flats candle during the weekend.


Image

I hope my explanation is clear.
Thank you.

Umb.


Attachments:
File comment: THIS IS AN EXEMPLE
2013-07-16_1525.png [25.81 KiB]
Downloaded 636 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: BARS FILTER 4 WEEKEND Post rating: 0   New post Posted: Wed 17 Jul, 2013, 11:54 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
What is your method the get the last 5 bars? Could you modify that part and check if the bar was a flat one? (Like if bar.getOpen() == bar.getClose().)

Filters (as far as I know) are used for indicator calculation, or can be used for chart drawings (not to draw flat candles). If you use/calculate bar data on your own, without indicators, you have to implement your own 'flat filter', just as I mentioned above.


 
 Post subject: Re: BARS FILTER 4 WEEKEND Post rating: 0   New post Posted: Wed 17 Jul, 2013, 15:12 
User avatar

User rating: 0
Joined: Fri 24 Aug, 2012, 21:23
Posts: 4
Location: Italy, Rome
tcsabina wrote:
What is your method the get the last 5 bars? Could you modify that part and check if the bar was a flat one? (Like if bar.getOpen() == bar.getClose().)

Filters (as far as I know) are used for indicator calculation, or can be used for chart drawings (not to draw flat candles). If you use/calculate bar data on your own, without indicators, you have to implement your own 'flat filter', just as I mentioned above.



If I use your filter (bar.getOpen() == bar.getClose()) it can take something like a doji, especially in low TF.
I was using this method:

IBar PreviuosOne =  history.getBar(this.cross, this.period, OfferSide.BID, 1);
for(int i=2; i<=lastBar; i++){
            IBar checkbar = history.getBar(this.cross, this.period, OfferSide.BID, i);
            if(PreviousOne.getClose()>checkbar.getClose())
              {
              control=false;
              break;
              }
            }   
        return control;   


Now I'm watching for a solution here: https://www.dukascopy.com/wiki/#History_bars


 
 Post subject: Re: BARS FILTER 4 WEEKEND Post rating: 0   New post Posted: Wed 17 Jul, 2013, 22:27 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
I did my homework :D.
See attached strategy that returns the last 5 non-flat candle for every bar.
package jforex;

import java.util.*;

import com.dukascopy.api.*;
import java.text.SimpleDateFormat;

public class NonFlatBars implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    private SimpleDateFormat sdf;
       
    @Configurable("Instrument")
    public Instrument selectedInstrument = Instrument.EURUSD;
    @Configurable("Period")
    public Period selectedPeriod = Period.THIRTY_MINS;
   
    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();
        sdf = new SimpleDateFormat("yyyy.MM.dd_HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    }

    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 {
        IBar prevBar;
        IBar []nonFlatBars;
        int barCount = 0;
        int i = 1;
       
        nonFlatBars = new IBar[5];
        if ( (selectedPeriod == period) && (selectedInstrument == instrument) ) {
            while (barCount < 5) {
                prevBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, i++);
                if ( (prevBar.getClose() == prevBar.getOpen())
                  && (prevBar.getClose() == prevBar.getHigh())
                  && (prevBar.getClose() == prevBar.getLow())
                   )
                   continue;
                else
                    nonFlatBars[barCount++] = prevBar;
            }
           
            console.getOut().println("Current bar time: " + sdf.format(bidBar.getTime()) + ". Previous 5 non-flat bars are:");           
            for (IBar bar : nonFlatBars) {
                console.getOut().println("    Bar time: " + sdf.format(bar.getTime())
                                        + "; open=" + bar.getOpen() + "; close=" + bar.getClose()
                                        + "; high=" + bar.getHigh() + "; low=" + bar.getLow());
            }
        }
    }
}


Sample output from Historical Tester:
2011.01.07 is Friday, so flat period starts at 21:30. And ends at 2011.01.09_22:00.
21:29:22 Current bar time: 2011.01.10_01:00:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.09_22:30:00; open=1.28853; close=1.28934; high=1.2896; low=1.28853
21:29:22 Bar time: 2011.01.09_23:00:00; open=1.28934; close=1.29023; high=1.29055; low=1.28934
21:29:22 Bar time: 2011.01.09_23:30:00; open=1.29045; close=1.28948; high=1.29048; low=1.28882
21:29:22 Bar time: 2011.01.10_00:00:00; open=1.28947; close=1.28975; high=1.29006; low=1.28851
21:29:22 Bar time: 2011.01.10_00:30:00; open=1.28975; close=1.29029; high=1.29052; low=1.28935
21:29:22 Current bar time: 2011.01.10_00:30:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.09_22:00:00; open=1.28745; close=1.28853; high=1.28858; low=1.28716
21:29:22 Bar time: 2011.01.09_22:30:00; open=1.28853; close=1.28934; high=1.2896; low=1.28853
21:29:22 Bar time: 2011.01.09_23:00:00; open=1.28934; close=1.29023; high=1.29055; low=1.28934
21:29:22 Bar time: 2011.01.09_23:30:00; open=1.29045; close=1.28948; high=1.29048; low=1.28882
21:29:22 Bar time: 2011.01.10_00:00:00; open=1.28947; close=1.28975; high=1.29006; low=1.28851
21:29:22 Current bar time: 2011.01.10_00:00:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.07_21:30:00; open=1.29134; close=1.2906; high=1.29175; low=1.29045
21:29:22 Bar time: 2011.01.09_22:00:00; open=1.28745; close=1.28853; high=1.28858; low=1.28716
21:29:22 Bar time: 2011.01.09_22:30:00; open=1.28853; close=1.28934; high=1.2896; low=1.28853
21:29:22 Bar time: 2011.01.09_23:00:00; open=1.28934; close=1.29023; high=1.29055; low=1.28934
21:29:22 Bar time: 2011.01.09_23:30:00; open=1.29045; close=1.28948; high=1.29048; low=1.28882
21:29:22 Current bar time: 2011.01.09_23:30:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.07_21:00:00; open=1.29087; close=1.29134; high=1.29209; low=1.29077
21:29:22 Bar time: 2011.01.07_21:30:00; open=1.29134; close=1.2906; high=1.29175; low=1.29045
21:29:22 Bar time: 2011.01.09_22:00:00; open=1.28745; close=1.28853; high=1.28858; low=1.28716
21:29:22 Bar time: 2011.01.09_22:30:00; open=1.28853; close=1.28934; high=1.2896; low=1.28853
21:29:22 Bar time: 2011.01.09_23:00:00; open=1.28934; close=1.29023; high=1.29055; low=1.28934
21:29:22 Current bar time: 2011.01.09_23:00:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.07_20:30:00; open=1.29279; close=1.29087; high=1.29289; low=1.29054
21:29:22 Bar time: 2011.01.07_21:00:00; open=1.29087; close=1.29134; high=1.29209; low=1.29077
21:29:22 Bar time: 2011.01.07_21:30:00; open=1.29134; close=1.2906; high=1.29175; low=1.29045
21:29:22 Bar time: 2011.01.09_22:00:00; open=1.28745; close=1.28853; high=1.28858; low=1.28716
21:29:22 Bar time: 2011.01.09_22:30:00; open=1.28853; close=1.28934; high=1.2896; low=1.28853
21:29:22 Current bar time: 2011.01.09_22:30:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.07_20:00:00; open=1.29318; close=1.29284; high=1.29337; low=1.29252
21:29:22 Bar time: 2011.01.07_20:30:00; open=1.29279; close=1.29087; high=1.29289; low=1.29054
21:29:22 Bar time: 2011.01.07_21:00:00; open=1.29087; close=1.29134; high=1.29209; low=1.29077
21:29:22 Bar time: 2011.01.07_21:30:00; open=1.29134; close=1.2906; high=1.29175; low=1.29045
21:29:22 Bar time: 2011.01.09_22:00:00; open=1.28745; close=1.28853; high=1.28858; low=1.28716
21:29:22 Current bar time: 2011.01.09_22:00:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.07_19:30:00; open=1.29328; close=1.29318; high=1.29359; low=1.29289
21:29:22 Bar time: 2011.01.07_20:00:00; open=1.29318; close=1.29284; high=1.29337; low=1.29252
21:29:22 Bar time: 2011.01.07_20:30:00; open=1.29279; close=1.29087; high=1.29289; low=1.29054
21:29:22 Bar time: 2011.01.07_21:00:00; open=1.29087; close=1.29134; high=1.29209; low=1.29077
21:29:22 Bar time: 2011.01.07_21:30:00; open=1.29134; close=1.2906; high=1.29175; low=1.29045
21:29:22 Current bar time: 2011.01.09_21:30:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.07_19:30:00; open=1.29328; close=1.29318; high=1.29359; low=1.29289
21:29:22 Bar time: 2011.01.07_20:00:00; open=1.29318; close=1.29284; high=1.29337; low=1.29252
21:29:22 Bar time: 2011.01.07_20:30:00; open=1.29279; close=1.29087; high=1.29289; low=1.29054
21:29:22 Bar time: 2011.01.07_21:00:00; open=1.29087; close=1.29134; high=1.29209; low=1.29077
21:29:22 Bar time: 2011.01.07_21:30:00; open=1.29134; close=1.2906; high=1.29175; low=1.29045
21:29:22 Current bar time: 2011.01.09_21:00:00. Previous 5 non-flat bars are:
21:29:22 Bar time: 2011.01.07_19:30:00; open=1.29328; close=1.29318; high=1.29359; low=1.29289
21:29:22 Bar time: 2011.01.07_20:00:00; open=1.29318; close=1.29284; high=1.29337; low=1.29252
21:29:22 Bar time: 2011.01.07_20:30:00; open=1.29279; close=1.29087; high=1.29289; low=1.29054
21:29:22 Bar time: 2011.01.07_21:00:00; open=1.29087; close=1.29134; high=1.29209; low=1.29077
21:29:22 Bar time: 2011.01.07_21:30:00; open=1.29134; close=1.2906; high=1.29175; low=1.29045


Attachments:
NonFlatBars.java [2.54 KiB]
Downloaded 386 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: BARS FILTER 4 WEEKEND Post rating: 0   New post Posted: Fri 19 Jul, 2013, 02:04 
User avatar

User rating: 0
Joined: Fri 24 Aug, 2012, 21:23
Posts: 4
Location: Italy, Rome
I founded this way to avoid weekend bars (exemple for the last 5 bars, buy):
 long prevBarTime = history.getPreviousBarStart(period, history.getLastTick(cross).getTime());
        List<IBar> bars = history.getBars(cross, period, OfferSide.BID, Filter.WEEKENDS, numbOFbars-1, prevBarTime, 0 );
        int last = bars.size()-1;         

        for(int i=0; i<last; i++){                             
            double checkclose = bars.get(last-i).getClose();
            if(LastOne.getClose()>checkclose)
              {
              control=false;
              break;
              }
            }           

I think it is more simple and fast :-)
Image
I dont't know why, but "getPreviousBarStart" give the start of the 0 bar. So I modified the code in my own way.


Attachments:
2013-07-19_0252.png [11.98 KiB]
Downloaded 607 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com