Simple MT4 - Java bridge - page 2

 

Thanks cyberflohr for your reply. I have another question.

There are predefined methods defined in SampleEA, which come with your sample. These methods linked to MT4 through mt4j.dll. if I want to add my own method to SampleEA.java and want it to be called in MT4, what should I do? modify the mt4j.dll?

cyberflohr:
unfortunately writing to System.out / System.err will not show up messages in your MT terminal. you must write your messages to a file (using java.io) or use a java logging framework like log4j or slf4j.

I'll prepare a more complex sample which do some trades in the next few days.

regards,
cyberflohr
 

You can add your own set/get Methods to your class i.e. void setBuyPrice(double price), double getPrice(), but adding methods with a variable parameter list is not possible.

PS: I could add support for noargs methods if you want, that mean you call first your setter methods to prepare your instance object with data and then call the noargs method to start processing - what ever you want.

 

Support for noargs methods (void someMethod()) would be very handy. As this would improve the separation of transferring the data and the control of operations to run on it.


Regards,

 

Hi cyberflohr,

Excellent tool. I have one question:

How can I re generate mt4j.dll if I would like to expose my own public java api to call from MT4?

Thanks,

Alot!

Regards,

Tamas

 

Hi CyberFlohr, thanks a lot for this MT4 Java Bridge. I am interested on having some traits of the content of the MT4J.dll implementation, i'd like having a start point for me to develop my own DLL, because I'd like to add some technical functions availability within the API.


Thanks,

Jesus

 

Hi Cyberflohr,

I followed you r instruction to install the mt4jv0.2 and got no any error reported in MT4 platform. However from the SampleEA.java I find that there is a method which seems to be run when the EA initialization according to the description in MT4BasicClient.java

code in SampleEA.java:

@Override

public void init() {

System.out.println("init()");

}

description in MT4BasicClient.java:Beats by Dr. Dre Solo

/**

* Called by the MT4 client during init phase.

*/

From these code I think there shall be something to be printed out while initialization. but U didn't see the "init()" message get printed in MT4 platform. Do I understand the code correctly?

Besides, can you give another demo to place an order?

thank you very much, I really appreciate your code. :D

 

Has anyone done some rigid testing on sending over double values?


I have tried several options to send over a double value and then receive the same back, but without any succes. The sending into the Java enviroment succeeds (as I have debugged the received value at the java side) but receiving the same value back into the MT environment fails.


On printing the received value it shows output like below :


2012.05.03 22:57:32 ATT - Java EURUSD,M5: Double rec : -1.#IND


Has anyone encountered the same? It seems like the dll which is doing the actual transfer is not correctly handling the transfer back of double types.



Thanks in advance.

 
pivotpoint:

Has anyone done some rigid testing on sending over double values?


I have tried several options to send over a double value and then receive the same back, but without any succes. The sending into the Java enviroment succeeds (as I have debugged the received value at the java side) but receiving the same value back into the MT environment fails.


On printing the received value it shows output like below :


2012.05.03 22:57:32 ATT - Java EURUSD,M5: Double rec : -1.#IND


Has anyone encountered the same? It seems like the dll which is doing the actual transfer is not correctly handling the transfer back of double types.



Thanks in advance.

Are you using the right getter method - getDoubleProperty(jCtx, "DoublePropertyName") ?

I've verified the sample mt4jSAmple.mq4 with double values and it works.

setDoubleProperty(jCtx, "DoublePropertySample", DoubleProperty);
if (DoubleProperty != getDoubleProperty(jCtx, "DoublePropertySample")) {
Alert("Double wasn't set correct: " + getDoubleProperty(jCtx, "DoublePropertySample"));

}


Maybe it's the float value itself, what is the float value?

 
fasdfwesdgwe:

Hi Cyberflohr,

I followed you r instruction to install the mt4jv0.2 and got no any error reported in MT4 platform. However from the SampleEA.java I find that there is a method which seems to be run when the EA initialization according to the description in MT4BasicClient.java

code in SampleEA.java:

@Override

public void init() {

System.out.println("init()");

}

description in MT4BasicClient.java:Beats by Dr. Dre Solo

/**

* Called by the MT4 client during init phase.

*/

From these code I think there shall be something to be printed out while initialization. but U didn't see the "init()" message get printed in MT4 platform. Do I understand the code correctly?

Besides, can you give another demo to place an order?

thank you very much, I really appreciate your code. :D

As I already wrote in a previous posting, there is no way to redirect the messages wrote to System.out/err back to the MT4 platform. Please use a logging framework (log4j,slfj) to write your messages to a file.
To redirect messages written to System.out to a file, just add the following static initializer code to the MT4BasicClient.java class:

static {
try {
System.setOut(new PrintStream(new FileOutputStream("c:\\temp\\mt4j.log",true)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
 
cyberflohr:
As I already wrote in a previous posting, there is no way to redirect the messages wrote to System.out/err back to the MT4 platform. Please use a logging framework (log4j,slfj) to write your messages to a file.
To redirect messages written to System.out to a file, just add the following static initializer code to the MT4BasicClient.java class:

static {
try {
System.setOut(new PrintStream(new FileOutputStream("c:\\temp\\mt4j.log",true)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}


Another sample for redirection below :


String out_filename = String.format("%s%s.log","experts/logs/",this.getClass().getSimpleName());
String err_filename = String.format("%s%s_error.log","experts/logs/",this.getClass().getSimpleName());

System.setOut(new PrintStream(out_filename));
System.setErr(new PrintStream(err_filename));


Which will nicely log all your console and error logging.

Reason: