Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Volume problem
 Post subject: Volume problem Post rating: 0   New post Posted: Sat 15 Jan, 2011, 10:22 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
I use the below my/indicator. Playing a bit with it I get the errors like this:

09:07:02 Error in indicator: java.lang.ArrayIndexOutOfBoundsException: 40 @ jforex.VolumeForce.calculate(VolumeForce.java:61)
09:07:02 Bar times do not match.
09:07:02 Bar times do not match.
etc

It appears I either do something wrong or there is a major flaw in the bars loading on the internal JForex engine.
Theoretically, I should obtain the bars synchronized on both sides Bid and Ask.
Please have a look and let me know. The indicator sometimes do not show that error. Sometime does not draw at all if I change in the chart between Bid/Ask top box. If I scroll the chart the errors appear again.
Can you help. Thank you.

package jforex;

import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.JFException;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.indicators.*;

public class VolumeForce implements IIndicator
{
   // indicator name & title
   protected static final String iIndName  = "VOL_FORCE";
   protected static final String iIndTitle = "Volume Force";
   
    private IndicatorInfo indicatorInfo;
    private InputParameterInfo[] inputParameterInfos;
    private OptInputParameterInfo[] optInputParameterInfos;
    private OutputParameterInfo[] outputParameterInfos; 
    private IBar[] iBidBars, iAskBars;   
    private double[][] outputs = new double[1][]; // 2 for full volumes
    IConsole iConsole;
           
    public void onStart(IIndicatorContext context)
    {
       IIndicatorsProvider indicatorsProvider = context.getIndicatorsProvider();
        iConsole = context.getConsole();
       
        indicatorInfo = new IndicatorInfo(iIndName,iIndTitle,"Custom",false,false,true,2,0,1);
        inputParameterInfos = new InputParameterInfo[]
                             {
                                     new InputParameterInfo("Bid bars",InputParameterInfo.Type.BAR),
                                     new InputParameterInfo("Ask bars",InputParameterInfo.Type.BAR)
                             };
       
       inputParameterInfos[0].setOfferSide(OfferSide.BID);
       inputParameterInfos[1].setOfferSide(OfferSide.ASK);
       
        outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("Volume Force", OutputParameterInfo.Type.DOUBLE,OutputParameterInfo.DrawingStyle.LINE)};
        //outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("Bid Volume", OutputParameterInfo.Type.DOUBLE,OutputParameterInfo.DrawingStyle.LINE),
        //                                      new OutputParameterInfo("Ask Volume", OutputParameterInfo.Type.DOUBLE,OutputParameterInfo.DrawingStyle.LINE)};
    }

    public IndicatorResult calculate(int startIndex, int endIndex)
    {
        //calculating startIndex taking into account lookback value
        if(startIndex - getLookback() < 0)
        {
            startIndex -= startIndex - getLookback();
        }
       
        if(startIndex > endIndex)
        {
            return new IndicatorResult(0,0);
        }
                 
        int aOutLen = endIndex - startIndex + 1;
       
        double aVolBid, aVolAsk;
        for(int i=0;i<aOutLen;i++)
        {           
           boolean aWrongBTime = (iBidBars[startIndex+i].getTime() != iAskBars[startIndex+i].getTime());
              //throw new ArrayStoreException("Bar times do not match.");
              //iConsole.getOut().println("Bar times do not match.");
           
           aVolBid = iBidBars[startIndex+i].getVolume();
           aVolAsk = iAskBars[startIndex+i].getVolume();
           
           if(aVolBid == 0 || aVolAsk == 0 || aWrongBTime)
           {
              if(aWrongBTime)
                 iConsole.getOut().println("Bar times do not match.");
              outputs[0][i] = -1;
           }
           else
              outputs[0][i] = aVolBid/aVolAsk;           
        }
       
        return new IndicatorResult(startIndex,aOutLen);
    }

    public IndicatorInfo getIndicatorInfo()
    {
        return indicatorInfo;
    }

    public InputParameterInfo getInputParameterInfo(int index)
    {
        if(index <= inputParameterInfos.length)
        {
            return inputParameterInfos[index];
        }
        return null;
    }

    public int getLookback()
    {       
       return 5;
    }

    public int getLookforward()
    {
        return 0;
    }

    public OptInputParameterInfo getOptInputParameterInfo(int index)
    {
        if(index <= optInputParameterInfos.length)
        {
            return optInputParameterInfos[index];
        }
       
        return null;
    }

    public OutputParameterInfo getOutputParameterInfo(int index)
    {
        if(index <= outputParameterInfos.length)
        {
            return outputParameterInfos[index];
        }
       
        return null;
    }

    public void setInputParameter(int index, Object array)
    {
        switch (index)
        {
        case 0:
            iBidBars = (IBar[]) array;
            break;
         
        case 1:
            iAskBars = (IBar[]) array;
            break;
           
        default:
            throw new ArrayIndexOutOfBoundsException(iIndName+":setInputParameter(). Invalid index: "+index);
        }
    }

    public void setOptInputParameter(int index, Object value)
    {
    }

    public void setOutputParameter(int index, Object array)
    {
        outputs[index] = (double[]) array;
    }
}



 
 Post subject: Re: JFOREX-2637 Volume problem Post rating: 0   New post Posted: Mon 17 Jan, 2011, 21:48 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
I add the following supplementar notes:
- the indicator simply calculates volume bid/ask ratio at the bar
- I use JForex with settings: Filter Flats All, Merge Sunday candles into Monday Candles

It is a must we can use filtering. The above artifacts appears generally in lower timeframes eg. at M5,M15,H1.
It appears into higher tf also, but not always. It almost does not appear if I disable filtering.

I think the problem resides in the fact there are many candles which have bid ticks but not ask ticks; so that a bid candle at time T exists but not an ask candle at same time. This is especially case for lower tf like M5, M1 even M30, H1.
So, that, it appears JForex loads the bid/ask candles serially as they are in the history without to synchronize them.
An work arround for this would be for example, if a bid candle exist but not an ask one, automatically insert one with H=L=O=C and volume zero at the same time as the bid candle.

I am not sure if this is the cause but I still keep getting the above problems.

Regards,


 
 Post subject: Re: JFOREX-2637 Volume problem Post rating: 0   New post Posted: Tue 25 Jan, 2011, 16:03 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Quote:
Theoretically, I should obtain the bars synchronized on both sides Bid and Ask.

It is incorrect.

All indicators have the main input with no instrument, period or offer side set. If you don't have such input, it still exists hidden. This main input has the data from the chart where indicator is added and all indexes of calculate method are the indexes of the array of this input.
If you add additional indicators with specific instrument, period and/or offer side then this is what's happening:
1. Data of the chart is loaded from the disc or from the internet and are ready to be shown on the chart. But data for the specific input of the indicator is not loaded yet.
2. We pass the data that we already have to the indicator hoping it will return some values that we can show on the chart right now. There could be another approach to hold the indicator calculation untill data for all inputs are loaded, but that would make some indicators less responsive. We decided to give indicators more possibilities for the cost of implementation simplicity.
3. After the data for the other inputs are loaded we recalculate indicator with the same interval giving all full data for all inputs


 
 Post subject: Re: JFOREX-2637 Volume problem Post rating: 0   New post Posted: Tue 25 Jan, 2011, 20:51 

User rating: 0
Joined: Thu 19 Aug, 2010, 13:53
Posts: 62
You see, the indicator is pretty simple.
It tries to uses the bid/ask bars set for inputs as in onStart.

The exception appears at this code:

if(iBidBars[startIndex+i].getTime() != iAskBars[startIndex+i].getTime());



which says the input arrays do not have the same length.

I am also sure you understood what I mean and maybe you find a better solution.

Thank you


 
 Post subject: Re: JFOREX-2637 Volume problem Post rating: 0   New post Posted: Thu 10 Mar, 2011, 17:04 
User avatar

User rating: 2
Joined: Tue 17 May, 2011, 16:35
Posts: 10
Location: ItalyItaly
Dear support,
any news about it? Are you working on it ?

As many of us are coding indicators which access ask and bid volume at the same time,
I'd appreciate at least a work-around.

thanks in advance,

regards
chriz


 
 Post subject: Re: JFOREX-2637 Volume problem Post rating: 0   New post Posted: Thu 10 Mar, 2011, 17:31 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Please have a look at the following example: https://www.dukascopy.com/wiki/index.php ... ple_inputs


 

Jump to:  

  © 1998-2025 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