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.

ShortLine
 Post subject: ShortLine Post rating: 0   New post Posted: Fri 29 Jun, 2012, 13:04 

User rating: 0
Joined: Fri 29 Jun, 2012, 12:45
Posts: 10
Hello,

Can you tell me, how can I get the current price of a ShortLine f.e. in the onTick function?
I catched the ShortLine (IChartObject), but I don't find any function about the price (just start and end price)

Thank your for your answer


 
 Post subject: Re: ShortLine Post rating: 0   New post Posted: Mon 02 Jul, 2012, 08:09 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Could you please provide your example strategy?


 
 Post subject: Re: ShortLine Post rating: 0   New post Posted: Mon 02 Jul, 2012, 08:58 

User rating: 0
Joined: Fri 29 Jun, 2012, 12:45
Posts: 10
Here is an example:

java.util.List<IChartObject> objects = chart.getAll();
Iterator it = objects.iterator();
while (it.hasNext()) {
IChartObject obj = (IChartObject) it.next();
if (obj.getType().equals(IChart.Type.SHORT_LINE)) {
...
}
}

It works and finds the shortline objects.


 
 Post subject: Re: ShortLine Post rating: 0   New post Posted: Mon 02 Jul, 2012, 09:05 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
To get the price property, you need to cast the object to the corresponding interface:
((IShortLineChartObject)obj).getPrice(0);
Another option is just to call the toString method, which will print both coordinates, i.e.:
console.getOut().println(obj.toString());
or simply:
console.getOut().println(obj);


 
 Post subject: Re: ShortLine Post rating: 0   New post Posted: Mon 02 Jul, 2012, 10:43 

User rating: 0
Joined: Fri 29 Jun, 2012, 12:45
Posts: 10
The getPrice(0) gives the price at the start of the short_line, the getPrice(1) gives the price at the end of the short_line.
I would like to get the price between. (Calculating the ascend/descend ratio of the line doesn't work, because on backtest, the BT draw sometimes flat bars during the weekend). Is there any function to get the price properly? Or how I could get the bars drawn into the chart to decide if there's any flat bar in it?

The main problem is when the BT get to the weekend, the end of the line's time is a weekend time, but as the first tick comes sunday night, the end of the line's time changes.

What I exactly want to do is to check whether the current price crosses the short_line.


 
 Post subject: Re: ShortLine Post rating: 0   New post Posted: Mon 02 Jul, 2012, 12:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider modifying the following example such that instead of passing the shift, you pass the price and find the shift instead of the price:
https://www.dukascopy.com/wiki/#Ray_line_prices_by_shift


 
 Post subject: Re: ShortLine Post rating: 0   New post Posted: Mon 02 Jul, 2012, 13:14 

User rating: 0
Joined: Fri 29 Jun, 2012, 12:45
Posts: 10
Thank you, but this is not that, what I asked.

In the chart I can't see the weekends in the past, but I can see those intervals in the future.

The getBar() returns with the weekend's flat bars too so your barInterval result is bad.

Finally as I wrote "Calculating the ascend/descend ratio of the line doesn't work, because on backtest, the BT draw sometimes flat bars during the weekend".
Please tell me a more precise method, to calculate the shortline's price.

Thank you


 
 Post subject: Re: ShortLine Post rating: 0   New post Posted: Mon 02 Jul, 2012, 13:39 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
  1. mrmiyagi wrote:
    In the chart I can't see the weekends in the past, but I can see those intervals in the future.
    This depends on platform settings. The filters on chart can be changed in JForex client settings: Tools > Preferences > Chart > Flats Filtration.
  2. mrmiyagi wrote:
    The getBar() returns with the weekend's flat bars too so your barInterval result is bad.
    That is why there is follow-up example which shows how to deal with filters.
  3. mrmiyagi wrote:
    Finally as I wrote "Calculating the ascend/descend ratio of the line doesn't work, because on backtest, the BT draw sometimes flat bars during the weekend".
    See 1.
  4. mrmiyagi wrote:
    Please tell me a more precise method, to calculate the shortline's price.
    See 2.


 

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