nj4x 2.9.0

.NET 6.0 .NET Framework 4.6.2
dotnet add package nj4x --version 2.9.0
NuGet\Install-Package nj4x -Version 2.9.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nj4x" Version="2.9.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nj4x --version 2.9.0
#r "nuget: nj4x, 2.9.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install nj4x as a Cake Addin
#addin nuget:?package=nj4x&version=2.9.0

// Install nj4x as a Cake Tool
#tool nuget:?package=nj4x&version=2.9.0

NJ4X API – library of access to MetaTrader server for Java and .Net

Terminology

Term Description
Advisor (EA) Advisor (Expert Advisor) is mechanical trading system (МТS)
NJ4X Java and .Net interface for access to MT4/5 terminal, previous name – JFX API
NJ4X Server Socket server (part of Java and .Net interface for access to MT4/5 terminal), which receives connections from MT4/5 terminal and initializes NJ4X strategies
NJ4X Strategy Trading strategy, realized via NJ4X API library. Usually it is presented by java-class, inherited from com.jfx.strategy.Strategy or .Net object, inherited from nj4x.Strategy.
MT4/5 Server MetaQuotes Software Corp. trading server. MT4/5 server receives trading orders and other requests from trading terminals for further execution
MT4/5 Terminal <p>Client MetaTrader 4 terminal is a trader workplace, which allows to work on Forex, CFD and Futures financial markets. </p><p>Java and .Net access interface (NJ4X) launches MT4/5 terminal in background mode and uses it for access to MT4/5 Servers </p>
MQL4/5 Programming language by MetaQuotes Software Corp for development of advisors, which interact with MT4/5 trading servers.
NJ4X Terminal Server Utility that launches MT4/5 terminals in background mode on request from mechanical trading system, which uses the NJ4X library.

Overview

NJ4X API is a Java and .Net library for accessing MetaTrader servers using standard MT4/5 terminal. It helps mechanical trading system developers to avoid using MQL4/5 language and to code in their preferred environments. MT4/5 terminal acts as a mediator between MT4/5 Server and the NJ4X program.

NJ4X library allows Java or .Net programs to interact with multiple MT4/5 servers at once. Some benefits are:

  • Java/.Net advisors can be developed with any IDE
  • Multiple trading accounts can be automated and managed simultaneously.
  • Complex trading systems can be well organized. MQL is not suitable for that.

NJ4X API step by step usage guide

  1. Create Visual Studio project
  2. Add NJ4X and NLog nuget packages
  3. Add reference to System.Configuration package:
  4. Edit App.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
  </configSections>
  <appSettings>
    
    <add key="nj4x_activation_key" value="209084108"/>
    <add key="nj4x_mt5_activation_key" value="3546292279"/>
    <add key="terminal_host" value="127.0.0.1"/>
    <add key="terminal_port" value="7788"/>
    
    <add key="broker" value="MetaQuotes-Demo"/>
    <add key="account" value="130240008"/>
    <add key="password" value="4ieubwl"/>
    
    <add key="nj4x_server_host" value="127.0.0.1"/>
    <add key="nj4x_server_port" value="7778"/>
  </appSettings>
</configuration>
  1. Program.cs
using System;
using System.Configuration;
using nj4x;
using nj4x.Metatrader;

namespace nj4x_p1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create strategy
            var mt4 = newStrategy();
            // Connect to the Terminal Server
            mt4.Connect(
                ConfigurationManager.AppSettings["terminal_host"],
                int.Parse(ConfigurationManager.AppSettings["terminal_port"]),
                newBroker(ConfigurationManager.AppSettings["broker"]),
                ConfigurationManager.AppSettings["account"],
                ConfigurationManager.AppSettings["password"]
            );
            // Use API methods ...
            Console.WriteLine($"Account {mt4.AccountNumber()}");
            Console.WriteLine($"Equity {mt4.AccountEquity()}");
            //
            Console.ReadLine();
        }
    }
}
  1. Install nj4x-v.n.m.msi (v.n.m -- version number, e. g. nj4x-2.8.7.msi) and run Terminal Server

  2. Getting ticks

for (int i = 0; i < 10; i++)
{
    double bid = mt4.Marketinfo( symbol: "EURUSD", type: MarketInfo.MODE_BID); 
    double ask = mt4.Marketinfo("GBPUSD", MarketInfo.MODE_ASK);
    Console.WriteLine($"EURUSD bid={bid}");
    Console.WriteLine($"GBPUSD ask={ask}");
    Task.Delay(100).Wait();
}
  1. Placing orders (http://docs.mql4.com/trading/OrderSend)
try
{
    var ticket = mt4.OrderSend(
        symbol: "EURUSD",
        cmd: TradeOperation.OP_SELL,
        volume: 0.1, price: bid,
        slippage: 2,
        stoploss: 0, takeprofit: 0,
        comment: "my order",
        magic: 0, expiration: MT4.NoExpiration
    );
    Console.WriteLine($"New order: {ticket}");
}
catch (MT4Exception e)
{
    Console.WriteLine($"Order placing error #{e.ErrorCode}: {e.Message}"); 
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.9.0 171 5/29/2023
2.8.9 107 5/20/2023
2.8.8 108 5/20/2023
2.8.7 104 5/19/2023
2.8.6 1,472 5/13/2019
2.8.5 856 2/4/2019
2.8.4 7,805 12/21/2018
2.8.2 1,985 8/26/2018
2.8.1 1,359 7/18/2018
2.8.0 957 7/4/2018
2.7.9 2,967 4/24/2018
2.7.8 1,219 4/16/2018
2.7.5 1,306 12/23/2017
2.7.3-beta2 749 11/9/2017
2.7.3-beta1 734 10/30/2017
2.7.2-beta 755 10/30/2017
2.7.1 971 10/26/2017
2.7.0 1,154 8/8/2017
2.6.8 1,071 5/4/2017
2.6.7 988 4/18/2017
2.6.6 998 4/6/2017
2.6.4-rc1 933 11/17/2016
2.5.9-rc1 810 10/23/2016
2.5.6 1,414 8/15/2016
2.5.4 1,105 5/17/2016
2.5.0.32 1,073 2/2/2016
2.5.0.31 1,225 2/2/2016
2.4.9.6 1,148 9/10/2015
2.4.9.5 1,094 9/10/2015
2.4.9.4 1,072 9/10/2015
2.4.9.3 1,073 9/10/2015
2.4.9.2 1,070 9/10/2015
2.4.9.1 1,093 9/10/2015
2.4.9 1,050 8/31/2015
2.4.8.2 1,032 8/20/2015
2.4.8.1 1,020 8/20/2015
2.4.7 1,038 8/14/2015
2.4.3 1,131 7/24/2015
2.4.2.2 1,064 6/26/2015
2.4.2.1 1,014 6/26/2015
2.4.2 1,069 6/18/2015
2.3.9 1,018 6/8/2015
2.3.6 1,092 5/27/2015
2.3.5 1,044 5/15/2015
2.3.4.12 1,061 5/13/2015
2.3.4.11 1,039 5/13/2015
2.3.4.10 1,019 5/12/2015
2.3.4.9 1,033 5/12/2015
2.3.4.8 1,047 5/9/2015
2.3.4.7 1,189 4/20/2015
2.3.4.6 1,139 4/19/2015
2.3.4.5 1,095 4/18/2015
2.3.4.4 1,083 4/18/2015
2.3.4.3 1,160 4/17/2015
2.3.4.2 1,167 4/17/2015
2.3.4.1 1,095 4/17/2015
2.3.4 1,110 4/17/2015
2.3.3 1,293 4/9/2015

Changes log (**=item modified, ++=item added, --=item removed)

28 May 2023 (2.9.0)
   **TS: upgrade launch4j: lookup JRE in %JAVA_HOME%;%PATH%
18 May 2023 (2.8.7)
   **NJ4X: upgrade of dependencies; test with latest mt4/5 builds; set jdk11 as a minimum supported java version
05 May 2019 (2.8.6)
   **NJ4X-5: ++ fix of Position Listener initialization error at Win Server 2008 platforms.
04 Feb 2019 (2.8.5)
   **TS: ++ 'no_gdrive' parameter: if true - no google drive functionality will be used.
   **TS: ++ 'terminal.exe' parameter: defines name for the mt4/5 terminal executable (nj4x_term.exe by default)
   **NJ4X: -- no more jdk 1.7 support; ++ projects moved to Apache Maven 3.6.0 & JDK 11
   **NJ4X-5: Warning! - Balance & Credit orders ticket numbers have been increased by 0x4000000000000000L
19 Dec 2018 (2.8.4)
   **TS: ++ workaround presence of Tick Data Suite (https://eareview.net/tick-data-suite) service causing MaxNumberOfTerminalsReached error: terminal.exe process has been renamed.
   **EA: ++ use of new MQL4 OnTick method.
02 Oct 2018 (2.8.3)
   **NJ4X-5: ++ fix of historical orders selection in SELECT_BY_POS mode; fixed issue with missed orders in PositionListener/MT5.
   **NJ4X-5: ++ Strategy.WithMaxBars(<int>) method to keep MT5 terminal memory consumption under control.
26 Aug 2018 (2.8.2)
   **NJ4X: ++ fix of automatic trial period false breaking.
   **NJ4X: !Interface change WARNING! order magic number: ulong -> long (C#)
   **NJ4X-5: ++ fix of hangs in OrdersHistoryTotal() (some scenarios).
   **NJ4X-5: ++ fix of OrderGetAll method filtering function.
17 July 2018 (2.8.1)
   **NJ4X: -- excessive debug info during terminal connection/disconnection
   **NJ4X-5: ++ compression of history folders; ++ ability to download full history
   **TS: ++ automatic add-modules=java.xml.ws,java.xml.bind for Java>=9
   **TS: ++ spontaneous terminal startup hanging error fix
   **TS: ++ GDrive NullPointer error fix
   **EA: ++ ability to remove jfx EA chart (and lose terminal connection)
   **src project: ++ fix jdk9/10 compilation and javadoc
09 June 2018 (2.8.0)
   **NJ4X-5: ++ fix of ordersHistoryTotal()'s "Array out of range" error.
   **TS: ++ default cloud storage configuration; ++ cpu usage logging.
24 April 2018 (2.7.9)
   **NJ4X: ++ ChartsList method.
24 March 2018 (2.7.8)
   **TS: downgrading org.apache.cxf to 3.1.9 (to support java 1.7)
15 March 2018 (2.7.7)
   **NJ4X/PL PositionInfo,PositionChangeInfo: live/historical maps, new/closed/deleted/modified order lists made read-only.
   **NJ4X: added dummy constructors to Rate, Bar, Tick, TickInfo classes to support serialization.
09 Feb 2018 (2.7.6)
   **NJ4X: ++ SeriesInfo method mapping (https://www.mql5.com/en/docs/series/seriesinfointeger)