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.

MultiInstrument indicator
 Post subject: MultiInstrument indicator Post rating: 0   New post Posted: Tue 28 Sep, 2010, 10:20 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello I would like ask you something..
I am taking look at JForex API last few days and it seems really great done work, I like this opportunity to write custom indicators/strategies in my favourite Java...
The only thing I am confused from is how could I implement indicator which is calculating values from two different instruments...?

I am programming indicator which will calculate the correlation index between GPBUSD 1Hour and EURUSD 1Hour
I already have this indicator but I am not sure if the source code is correct.
I think the calculated values are ok, but I am worried about exceptions of this indicator in future, because the way how my indicator is accessing data is this:

I have two InputParametrInfo instances. One for GBPUSD one for EURUSD.
In "calculate" method I am accessing needed array of IBars from both of the instruments.
But my question is.. could it throw exception when one instrument will have less IBars like anotherone?

Here is the source code...
https://files.lorencsoftware.cz/20000007 ... 1Hour.java


Maybe the best way how you can teach me or explain how to write multiinstrument indicators will be
when you will post some example indicator calculating Close price of GBPUSD 1Hour minus Close price of EURUSD 1 Hour..
Thank you very much for your assistance.


 
 Post subject: Re: MultiInstrument indicator Post rating: 0   New post Posted: Tue 28 Sep, 2010, 15:45 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi, please consider this: https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=10&t=23784&view=unread


 
 Post subject: Re: MultiInstrument indicator Post rating: 0   New post Posted: Tue 28 Sep, 2010, 19:38 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Yes the previous post is also from me.
The example is good but there is still some thing which are confusing for me :( ...
Please post code example of following indicator:

Indicator is calculating GBPUSD Close price of 1Hour timefrime minus EURUSD Close price of 1Hour timefrime
You know what I mean... difference between close prices of some different instruments..
When I will see source code of this then I can understand the principals how to handle and access data from two different instruments in calculation.. Then I can apply it and create my custom indicators like Correlation etc..

Thank you


 
 Post subject: Re: MultiInstrument indicator Post rating: 0   New post Posted: Wed 29 Sep, 2010, 10:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ZOOinek wrote:
But my question is.. could it throw exception when one instrument will have less IBars like anotherone?

When indicator has one input which is the same instrument and period of chart, then the task is simple. We put data from chart in the indicator, get the output and draw it. If the indicator has two inputs then our task is more complicated. We need to maintain andother array of candles for that indicator.

When the user scrolls the chart, data from the disk or from the internet are downloaded in background. It is very likely that data for the chart will be downloaded quicker than the data for the additional input of the indicator. In this case we have two options: delay the indicator calculation untill all data for all inputs are downloaded or give the indicator the data that we already have and when the remaining part is downloaded call it again and refresh everything. We did choose second approach as we feel it will make charts more responsive. Also it allows setting different periods for inputs and providing different number of elements when we call calculate() method of the indicator. It makes indicator implimentation more complicated though.

When you implement indicator with two or more inputs you need to be aware that number of elements of different inputs can differ. For most indicators it means you should choose input type IBar and allign inputs by time. Indexes passed as the parameters of the calculate method and the indexes and number of the elements of the output are relative to the "basic" input of the indicator. It is the input as it would be without and instruments or periods set to it.

In your example you access your inputs cycling from startIndex to endIndex. If your indicator is added to the chart with period 10 seconds, then you will get ArrayIndexOutOfBoundsException because startIndex and endIndex are relative to the 10sec array of elements and your inputs are arrays with 1hour elements (mush shorter, most likely it will have 1 element only). You also assume that both your inputs are the same size and it's corresponding elements has the same time. It's not always true. Also you output your errors with JOptionPane.showMessageDialog method. It blocks the calculation thread which is bad because it holds monitor that awt thread needs. This results in complete application hang :)


 

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