|
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.
Saving a varibale to my PC? |
[inkexit]
|
Post subject: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Thu 12 Aug, 2010, 15:00
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
I'd like to track my drawdown in terms of USD. Could someone explain or give an example of how I would create a variable that could be saved to my PC and how I make some code that would check it and update if the current drawdown > myVariable? The idea is to track my drawdown forever, not just the biggest drawdown of each time i log in. To do this I imagine I would have to save the data to my hardrive somehow?
|
|
|
|
 |
API Support
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 12:59
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Hi, Please consider the following code. Path to log file is displayed at the start of the strategy. package jforex;
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.TimeZone;
import com.dukascopy.api.Configurable; import com.dukascopy.api.IAccount; import com.dukascopy.api.IBar; import com.dukascopy.api.IConsole; import com.dukascopy.api.IContext; import com.dukascopy.api.IEngine; import com.dukascopy.api.IHistory; import com.dukascopy.api.IMessage; import com.dukascopy.api.IOrder; import com.dukascopy.api.IStrategy; import com.dukascopy.api.ITick; import com.dukascopy.api.Instrument; import com.dukascopy.api.JFException; import com.dukascopy.api.Period;
public class Logger implements IStrategy { @Configurable("Instrument") public Instrument instrument = Instrument.EURUSD; @Configurable("Drawdown") public double drawDown = 1000; @Configurable("Update log every") public Period updatePeriod = Period.FIFTEEN_MINS; private IEngine engine; private IConsole console; private IHistory history; private IContext context; public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.history = context.getHistory(); this.context = context; console.getOut().println("Path to log file: " + this.context.getFilesDir() + "\\log.txt"); }
public void onAccount(IAccount account) throws JFException { }
public void onMessage(IMessage message) throws JFException { }
public void onStop() throws JFException { }
public void onTick(Instrument instrument, ITick tick) throws JFException { } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (period != this.updatePeriod || instrument != this.instrument) return; double totalDrawdown = 0; for (IOrder order : engine.getOrders()){ if (order.getProfitLossInUSD() >= 0) continue; totalDrawdown -= order.getProfitLossInUSD(); } if (totalDrawdown >= this.drawDown) { logDrawdown(totalDrawdown); } } private void logDrawdown(double currentDrawdown)throws JFException{ SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); try { File file = new File(this.context.getFilesDir() + "\\log.txt"); FileWriter fw = new FileWriter(file, true); fw.write(fmt.format(history.getLastTick(this.instrument).getTime()) + " Current drawdown: " + currentDrawdown + System.getProperty("line.separator")); fw.close(); } catch (IOException e) { console.getOut().println(e.getMessage()); } } }
|
|
|
|
 |
[inkexit]
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 16:16
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
Thank you for the reply!
As I see a number a Java "libararys?" have been imported for this code, this brings up a question I have been thinkning about for a while.
Is there a list available of all the Java classes that can be imported? And where do they come from? I am used to coding in c++ and anything that gets imported into the code needs to be in the same folder as the source code, or at leat somewhere on my PC. I see none of these java libraries are on my pc however? Seems like I am working a bit in the dark here. Do all those libraries come with Java by default, and were they installed to my pc when I installed your demo, or downloaded the latest java download from Sun?
What if I wanted to add more librarys? For example, the JMatLib library, which has all the functionality of the MathLab program, but is written for Java? Would I simply have to put the library in the Strategies folder?
I am new to Java and still trying to figure out these basics. Thank you.
|
|
|
|
 |
[inkexit]
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 16:19
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
Oh, BTW, I believe this line: totalDrawdown -= order.getProfitLossInUSD(); should be this: totalDrawdown += order.getProfitLossInUSD(); as drawdowns are already negative, and a negative plus a negative is a positive.
|
|
|
|
 |
[inkexit]
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 17:12
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
For example, I will need to use the java function Math.max in my code.
How can I know if I can just write "import java.math.*" or If I actually have to go find the library online, download it, and place it in the strategues folder before it will work?
|
|
|
|
 |
tspeicher
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 17:21
|
|
User rating: 0
Joined: Wed 18 May, 2011, 11:25 Posts: 60 Location: DE
|
use an IDE like eclipse or netbeans, imports can be done automatically there. so you can see, if you are using a standard java library or external libraries. but java.math.* is standard 
|
|
|
|
 |
[inkexit]
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 17:41
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
Thanks Tom,
On the reccomendations of the Java forum at Dream In Code, I started using notepad++. Can I create and compile classes and do imports with Notepad++? Again, the Java world is brand new to me, OOP, for that matter..
|
|
|
|
 |
[inkexit]
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 17:43
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
So I'm guessing a number of Java classes are standard when you download Java? This is different for me. In the C++ world nothing comes standard, unless you use a C++ IDE, in which case most of them come with libraries built in.
|
|
|
|
 |
[inkexit]
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 17:57
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
Well I'm currently downloading Netbeans....
Can I compile a JFroex program with it? Seems like I couldn't as the JForex package won't be included with netbeans... I would imagine I would get an error like "can't locate jForex package" or something like that? I gotta say all these hidden semi-unaccesible libraries in Java make it kind of hard to actually know what's going on with your code. I like to be able to see everything, and see the source code for everything.
|
|
|
|
 |
tspeicher
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 18:40
|
|
User rating: 0
Joined: Wed 18 May, 2011, 11:25 Posts: 60 Location: DE
|
you need do download the JForexClientLibrary from Dukascopy and extract it. then locate the libs folder and add all the jars to your project in netbeans.
i always create a lib-folder in my project and copy the jar-files to this folder before including them into my application.
|
|
|
|
 |
[inkexit]
|
Post subject: Re: Saving a varibale to my PC? |
Post rating: 0
|
Posted: Fri 13 Aug, 2010, 19:45
|
|
User rating: 0
Joined: Mon 09 Aug, 2010, 21:49 Posts: 30
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|