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.

Save the no. of times a market level has been breached in a variable
 Post subject: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 13:22 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
To Dukascopy Support,

Could you plz tell me how to save the no. of times a market level has been breached in a variable?

For example, if the EURUSD goes above the value of 1.3200 once and then goes below it and then again goes above it, it means it has breached it twice. So the variable should store 2.

Thanks. :)

Jimmy.


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 13:36 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider retrieving ticks by time interval and then checking their prices:
https://www.dukascopy.com/wiki/#History_ticks/Ticks_by_time_interval


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 13:49 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
I don't want to retrieve the value of ticks by time interval but since the time a particular trade was opened.
For example, if a EURUSD trade was opened at 1.3200, I want to check how many times the level of 1.3225 has been breached since then. Could you plz tell me how to do that?


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 13:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
then you need to retrieve the ticks in a way similar to this:
List<ITick> ticks = history.getTicks(Instrument.EURUSD, order.getFillTime(), lastTick.getTime());


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 15:09 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
When I try to define the value of ticks as

List<ITick> ticks = history.getTicks(Instrument.EURUSD, order.getFillTime(), lastTick.getTime());

it show the following errors :

List cannot be resolved to a type

and

lastTick cannot be resolved

Do I need to define something else before I define ticks?


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 15:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Download the strategy which is attached to the wiki article and run it to see how it works. Then adjust it to work with your selected interval.


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 15:51 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
I want to know how many times a particular level has been breached since the opening of a trade and not as per the time interval. After that I want to store that number in a variable. How should I change the following code to do that?

private void getTicksByTimeInterval() throws JFException{            
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") {{setTimeZone(TimeZone.getTimeZone("GMT"));}};
        ITick lastTick = history.getLastTick(Instrument.EURUSD);
        List<ITick> ticks = history.getTicks(Instrument.EURUSD, lastTick.getTime() - 10 * 1000, lastTick.getTime());
        int last = ticks.size() - 1;
        console.getOut().println(String.format(
            "Tick count=%s; Latest bid price=%.5f, time=%s; Oldest bid price=%.5f, time=%s",
            ticks.size(), ticks.get(last).getBid(), sdf.format(ticks.get(last).getTime()), ticks.get(0).getBid(), sdf.format(ticks.get(last).getTime())));
    }


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Tue 16 Oct, 2012, 16:40 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We added another wiki example, see:
https://www.dukascopy.com/wiki/#History_ticks/Follow_the_price_dynamic


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Thu 18 Oct, 2012, 13:42 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
An error is generated for

package jforex.data;

that it expects 'import' instead of 'package' and when I write

import jforex.data;

again an error is generated. Plz tell me what should I write instead of it?


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Thu 18 Oct, 2012, 14:07 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide full error message. Also see if this could help you with the strategy running:
https://www.dukascopy.com/wiki/#Create_a_strategy


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Thu 18 Oct, 2012, 15:02 

User rating: 0
Joined: Tue 16 Oct, 2012, 12:23
Posts: 40
In the example that you provided in your last to last reply - https://www.dukascopy.com/wiki/#History_ ... ce_dynamic,
in the code it is

package jforex.data;

But when I write that in my strategy, an error is generated. Again, when I write

import jforex.data;

another error is generated.

Here is the full error message.

2012-10-18 13:53:17 The import jforex.data cannot be resolved
2012-10-18 13:53:17 ^^^^^^^^^^^
2012-10-18 13:53:17 import jforex.data;
2012-10-18 13:53:17 1. ERROR in C:\Users\Mankind\AppData\Local\Temp\jfxide\tmp\compile\Strategy1.java (at line 2)

2012-10-18 13:52:48 Syntax error on token "package", import expected
2012-10-18 13:52:48 ^^^^^^^
2012-10-18 13:52:48 package jforex.data;
2012-10-18 13:52:48 1. ERROR in C:\Users\Mankind\AppData\Local\Temp\jfxide\tmp\compile\Strategy1.java (at line 2)

Can I substitute package jforex.data with something else?


 
 Post subject: Re: Save the no. of times a market level has been breached in a variable Post rating: 0   Post Posted: Thu 18 Oct, 2012, 15:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
you can compile the strategy also without the import, for avoiding such mistakes consider usage of some IDE like Eclipse or Netbeans which provide automatic assistance and tips for solving such issues, see:
https://www.dukascopy.com/wiki/#Use_in_Eclipse
https://www.dukascopy.com/wiki/#Use_in_NetBeans

In case you still encounter such problems please provide attach to the post your example strategy.


 

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