Usage of Strategy in MT4 Terminal using In Process 32-bit Oracle 7/8 JVM

166 views
Skip to first unread message

hyperscalper

unread,
Jan 22, 2016, 4:15:25 PM1/22/16
to NJ4X Forum

My problem is that:
   1) coordinate() is not called, although init is called.
   2) on removal of jfx, MT4 platform hangs

As a newbie to NJ4X I thought I'd post my simple code, and
ask whether I'm on the right track:

Here's the Strategy code:
package com.fs.nj4x.strategy;

import java.io.IOException;

import com.fs.StrategyRunnerExample;
import com.jfx.ErrUnknownSymbol;
import com.jfx.strategy.Strategy;
import com.jfx.strategy.StrategyRunner;

public class NullNj4xStrategy extends Strategy {
   
    public NullNj4xStrategy() {
        System.out.println("NullNj4xStrategy constructor.");
    }
   
    @Override
    public synchronized void init(String symbol, int period, StrategyRunner strategyRunner)
            throws ErrUnknownSymbol, IOException {
        super.init(symbol, period, strategyRunner); // MUST DO
        System.out.println("NullNj4xStrategy Connected, " + getVersion());
        setAutoRefreshRates(false);
    }
   
    @Override
    public void coordinate() {
        //super.coordinate(); // DO NOT CALL THIS
        System.out.println("NullNj4xStrategy ...in coordinate()");
    }
   
    @Override
    public long coordinationIntervalMillis() {
        return 3000;
    }
   
    @Override
    public void deinit() {
        System.out.println("...in deinit()");
        super.deinit();
    }


}

java.out shows:
Connecting [EURUSDus.1.508645(ATC Brokers)/14 MQLv...@com.fs.nj4x.strategy.NullNj4xStrategy:1,0,0,0,0,0,0,0,0,0]
NullNj4xStrategy constructor.
NullNj4xStrategy Connected, NJ4X API v.2.4.9, DLL v.2.4.9, MQL v.2.4.9
(...which verifies that constructor and init are being called, no further output)


I'm trying to let MT4 "do the driving" as my first NJ4X project.
Using NJ4X v2.4.9 with Java.  Windows 7 64-bit OS i3 processor.
I tried this with Generic MT4 build 910 and build 950 and also used Oracle
JRE 1.7.0_71 and JRE 1.8.0_71 as 32-bit Java VM's (to match MT4 32-bit).

By defining JFX_JRE_HOME I was able successfully to get the
jfx EA to activate the JVM in process and find my Strategy, which was placed
in the MT4 libraries directory, which contains my
jar and the nj4x plus log4j jars.  I activated jfx.ex4 on a EUR/USD chart,
with no other charts running.

I did notice by tracing classloading that all Java system classes are
definitely being loaded from the CORRECT VM from jfx-jre-home .  However, I
did see ONE ANOMALY.  The CLASSPATH reported by NJ4X
included the wrong VM path below:

*** Using Generic MetaTrader on ATC Brokers Demo account ****

005764 04244 | Fri Jan 22 15:42:44 2016> JFX: 9bb79463-3013-470b-adf6-28980a85c2a3 130968330465615145 EURUSDus init=com.fs.nj4x.strategy.NullNj4xStrategy, acc=508645(ATC Brokers), timeCurr=2016.01.22 22:42:43, timeLocal=2016.01.22 15:42:44, w=14
005764 04244 | 22 15:42:44.195> com.fs.nj4x.strategy.NullNj4xStrategy> init(): EURUSDus, isTradeAllowed=1
005764 04244 | 22 15:42:44.195> Terminal idle timeout set to 21600 sec (default, change by JFX_TERM_IDLE_TMOUT_SECONDS env. variable)
************** NOTE the CLASSPATH does point to the wrong VM here ************
************ BUT initial class loading trace verifies Java classes being loaded from
************ jfx_jre_home, as expected  CLASSPATH may be a problem, not sure here ???
*** the jre1.8.0_71 is NOT the VM I am currently using
*** MAYBE CLASSES GET LOADED from the jre1.8.0_71 since it is at the front of CLASSPATH ?
*** CLASSLOADER TRACE shows classes being loaded from the correct VM, however ...
*** NJ4X runtime appends the other jar files correctly here:
005764 04244 | 22 15:42:44.195> create_vm: CLASSPATH=[-Djava.class.path=.;C:\Program Files (x86)\Java\jre1.8.0_71\lib;MQL4\Libraries\HSNJ4XStrategies.jar;MQL4\Libraries\jfx-2.4.9.jar;MQL4\Libraries\log4j-1.2.17.jar]
005764 04244 | 22 15:42:44.196> create_vm: JFX_JVM_OPTIONS=[-Djfx.no_log4j=false -Dnj4x_activation_key=1937116145 -XX:+TraceClassLoading]
005764 04244 | 22 15:42:44.196> JFX_JVM_OPTION [-Djfx.no_log4j=false]
005764 04244 | 22 15:42:44.197> JFX_JVM_OPTION [-Dnj4x_activation_key=1937116145]
005764 04244 | 22 15:42:44.198> JFX_JVM_OPTION [-XX:+TraceClassLoading]
*********** This is the VM I want to use inside the MT4 process, and classes do load from here
005764 04244 | 22 15:42:44.199> create_vm: JFX_JRE_HOME=[c:\Program Files (x86)\Java\jre7]
005764 04244 | 22 15:42:44.199> create_vm: DLL=[c:\Program Files (x86)\Java\jre7\bin\client\jvm.dll]
005764 04244 | 22 15:42:44.202> jvm.dll loaded
005764 04244 | 22 15:42:44.203> Creating JVM
...subsequent lines show normal class loading


So, since this is my first time, I thought I'd ask whether to go down this route
with MT4 "doing the driving".  I intend to create a Swing user interface but,
as of this time, the coordinate() callback isn't called, and there is definitely a problem
with shutdown, which HANGs MT4.

Everything looks good, init is called, no classloading errors, startup
looks good  (Note I am using Java 7 32-bit JVM but I have also tried
on Java 8 32-bit)  (Also, I've tried Generic MetaTrader build 950 as well
as build 910 terminal in NJ4x distribution, same results.)

JFX EA parameter values:
Expert jfx uses jfxPort = 0 and specifies strategy as com.fs.nj4x.strategy.NullNj4xStrategy
with default jfxHost set to 127.0.0.1 .  MT4 is "doing the driving" here so unclear
about jfxHost, etc... so I left them as defaulted.

Is there something more I need to do, or to check ?

hyperscalper

hyperscalper

unread,
Jan 23, 2016, 11:00:45 AM1/23/16
to NJ4X Forum

I would like to be very clear what I'm trying to do.

I just want to write an EA (Strategy) in Java which runs in the MT4 terminal process
using an IN-PROCESS 32-bit Java VM.  So it's just writing an EA "the NJ4X way"
within the MT4 terminal.exe process itself.  No additional processes are involved.

So, IS THIS POSSIBLE?  By using jfxPort=0 I believe this is supposed to
be possible.

No external processes are involved.  Once I get coordinate() working, then I'll
develop a Java Swing User Interface and simple manual trading functions.

Hope that's clear !!
hyperscalper

hyperscalper

unread,
Jan 23, 2016, 11:15:03 AM1/23/16
to NJ4X Forum

NJ4X

unread,
Jan 23, 2016, 3:31:40 PM1/23/16
to NJ4X Forum
About CLASSPATH pointing to the wrong VM - pls check CLASSPATH environment variable

FutureScalper

unread,
Jan 23, 2016, 4:41:45 PM1/23/16
to nj...@googlegroups.com
OK, I will do that.  I did verify that initial class loading was
all from the CORRECT VM corresponding to the jfx_jre_home
variable, but I will correct so that CLASSPATH is correct and
report progress Monday.

So I should expect coordinate() to be called, once the
init(...) is completed?  Nothing else should be necessary?
I will assume this for now...

hyperscalper


--
You received this message because you are subscribed to a topic in the Google Groups "NJ4X Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nj4x/Wdo7B0W20NY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nj4x+uns...@googlegroups.com.
To post to this group, send email to nj...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages