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.

create a jar file
 Post subject: create a jar file Post rating: 0   New post Posted: Fri 01 Jul, 2011, 04:02 

User rating: 0
Joined: Sun 12 Jun, 2011, 04:31
Posts: 6
Location: United States,
I have a strategy that compiles and runs well on one instrument.

Based on the simple parrallel example provided, I've written a second java file which will create multiple instances of the first strategy (to run multiple strategies within one strategy).

I don't know how to make a jar file of the first strategy so it can be included (via @Library) into the second strategy. I've used eclipse to create a jar file based on the 1st strategy's source code, but I get a warning that there are compile errors. Also, if I try to pull that jar file into a compile of the 2nd strategy, I get the following error: "myFirstStrategy cannot be resolved to a type"

I have 2 QUESTIONS:

When I compile the first strategy from the jforex platform, is a jar file created somewhere that I could move, or simply reference from the @Library statement within the second strategy?

Since I have to compile on the jforex platform, how do I create a jar file that will work with the 2nd parallel-execution strategy?


 
 Post subject: Re: create a jar file Post rating: 0   New post Posted: Fri 01 Jul, 2011, 09:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
rimrock wrote:
I don't know how to make a jar file of the first strategy so it can be included (via @Library) into the second strategy. I've used eclipse to create a jar file based on the 1st strategy's source code, but I get a warning that there are compile errors. Also, if I try to pull that jar file into a compile of the 2nd strategy, I get the following error: "myFirstStrategy cannot be resolved to a type"
If you have difficulties to create a jar, maybe try creating a new java project, reference from it JForex API libraries, add a single strategy to it (the one you want to run multiple instances of), export it into a jar and see if it works out.
rimrock wrote:
When I compile the first strategy from the jforex platform, is a jar file created somewhere that I could move, or simply reference from the @Library statement within the second strategy?
No, only a jfx file gets created.
rimrock wrote:
Since I have to compile on the jforex platform, how do I create a jar file that will work with the 2nd parallel-execution strategy?
See the answer above.

For your convenience we have attached the jar file used in the wiki example. So you might at first try if the example works for you on JForex client before making jars of your own. Also note that the compile error must have been caused by the lack of package notation at the beginning of StrategySimpleParallel class in JForex wiki (this now has been updated).


Attachments:
simple-strategies.rar [1.12 MiB]
Downloaded 398 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: create a jar file Post rating: 0   New post Posted: Sat 02 Jul, 2011, 04:26 

User rating: 0
Joined: Sun 12 Jun, 2011, 04:31
Posts: 6
Location: United States,
Thank you for your answer. Since I am new to java and eclipse, there could be several small things I'm doing wrong to prevent my jar from working properly. Please endure... I've attached 4 screen shots showing you step by step my method for creating the jar file and attempting to compile the multi-strategy class which pulls in the jar.

Also, the jar file you attached has an extension of .rar -- is that correct? Am I supposed to change it to .jar?

Thank you.


Attachments:
File comment: I created a package called "strata" alongside the "singlejartest" which came with the API download. My strategy is called "flint05"
Screen 1 of 4.jpg [126.62 KiB]
Downloaded 409 times
File comment: I right clicked on the project "JForexClientLibrary" to export generated class files into a jar called strata.jar on C:\temp
Screen 2 of 4.jpg [69.98 KiB]
Downloaded 403 times
File comment: I use @Library to reference the jar file and create 2 instances of flint05 called strategy1 and strategy2
Screen 3 of 4.jpg [59.38 KiB]
Downloaded 393 times
File comment: When I compile mica (on the jforex platform) I only get one error: "flint05 cannot be resolved to a type"
Screen 4 of 4.jpg [150.25 KiB]
Downloaded 393 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: create a jar file Post rating: 0   New post Posted: Mon 04 Jul, 2011, 16:41 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
rimrock wrote:
Thank you for your answer. Since I am new to java and eclipse, there could be several small things I'm doing wrong to prevent my jar from working properly. Please endure... I've attached 4 screen shots showing you step by step my method for creating the jar file and attempting to compile the multi-strategy class which pulls in the jar.
The .jar file creation looks ok, there must be some small nuance why this does not work out.
rimrock wrote:
Also, the jar file you attached has an extension of .rar -- is that correct? Am I supposed to change it to .jar?
You have to extract the .rar file to a .jar file.

You can also consider other possibilities of running two instance of your strategy, for example:
    a) from API:
            IStrategy strategy1 = new StrategySimple();
            IStrategy strategy2 = new StrategySimple();
            ((StrategySimple)strategy1).amount = 0.01;
            ((StrategySimple)strategy1).stopLossPips = 40;
            ((StrategySimple)strategy1).takeProfitPips = 40;
            ((StrategySimple)strategy2).amount = 0.02;
            ((StrategySimple)strategy2).stopLossPips = 60;
            ((StrategySimple)strategy2).takeProfitPips = 60;
            //strategy1.
           
            LOGGER.info("Starting strategy 1");
            client.startStrategy(strategy1);
            LOGGER.info("Starting strategy 2");
            client.startStrategy(strategy2);
    b) Opening multiple instances of your strategy in JForex Client and manually pass them different parameters.


 

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