1 (edited by ab 2013-02-09 05:24:27)

Topic: Diagnostic Monitoring of FST

In order to ensure that my automated MT4 instance is online, I use a monitoring platform that polls my systems regularly and alerts me (via email and SMS) if there are problems, so I can take action to correct the issue as soon as possible.

I use a number of FST instances on the same machine, all connected to multiple charts on a single MT4 instance.  Monitoring MT4 is easy as I can just verify that there is an active process named 'terminal.exe', but monitoring FST is not so simple.  The issue is that I can't simply monitor for a running copy of 'Forex Strategy Trader.exe' as I have a number of them running, and unless they all fail, I will never see an error from my monitoring system.

In order to be able to monitor a specific instance of FST, I have added some code into my FST fork (available at https://github.com/QANTau/Forex-Strategy-Trader) to include a means to remotely monitor a specific FST instance remotely, and have submitted a pull request for this work.

The added code includes a basic TCP server into the application that can be started from the command line, allowing for each running copy of FST to be monitored individually.

The TCP server needs a port to be set at the command line and works as follows:

  • If FST is started from anything other than the command line, the TCP Server is NOT started.

  • If FST is started using existing command line settings that specify the Connection ID, Strategy, and AutoStart value only (3 parameters provided), the TCP Server is NOT started.

  • If FST is started from the command line with 4 parameters listed, the fourth parameter is the TCP port and the TCP Server WILL start.

Existing documentation for the autostart process is available at http://forexsb.com/wiki/fst/manual/autostart, which will be updated with the necessary instructions if this change is accepted.

Where the existing command line would appear as something like:

start "" "Forex Strategy Trader.exe"   100   "yes"   "Test Trade"

the TCP Server can be started from the command line by entering a 4th parameter, such as:

start "" "Forex Strategy Trader.exe"   100   "yes"   "Test Trade"  1234

In the above example, this command line will autostart the TCP Server after FST is loaded, using port 1234 for incoming connections.

If the TCP Port must be less than 65536 and cannot be 0 (a value of 0 will work, but the TCP Server will not start).

If the TCP Server starts correctly, the journal will have a message listed such as "TCP Server Started on Port 1234".

The most common problem with the TCP Server will be trying to use a port that is already in use.  As an example, attempting to use Port 3389 would result in an error being displayed in the journal "TCP Server Error (...) using Port 3389".  Any errors will be displayed in the journal.

The service will only work from a remote system if the chosen port has been permitted through the firewall on the machine running FST.

A connection from a remote system on the chosen port will currently just display a message as follows:

<fst>OK</fst>

After this response if provided, the incoming connection is disconnected immediately.

The message can be modified internally by adding code as needed such as:

if (_tcpServer != null)
    _tcpServer.Message = customMessageString

I am only just polling for the availability of the port (which I take to mean that FST is running) and then set an alarm if the port doesn't respond when polled, although it would be fairly simple to sent diagnostic data from FST back to the calling application if that we necessary.

Comments and feedback would be appreciated.

2 (edited by ab 2013-02-15 06:51:05)

Re: Diagnostic Monitoring of FST

After some testing, a number of changes have been made to the proposed changes to FST.

Initially the TCP server was just responding with a generic message verify that the application was running, where now there are a number of different messages depending on the state of the connection between FST and MT4.

When FST is first launched, the response is:

<fst>
  <message>Unknown</message>
</fst>

When FST has a connection to MT4, the response is:

<fst>
  <message>OK</message>
</fst>

If FST loses the connection to MT4, the response is:

<fst>
  <message>Error</message>
</fst>

In certain cases (likely when the connection between FST and MT4 up, but the internal FST-to-MT4 'ping' process is not receiving a response to every request), the response is:

<fst>
  <message>Warning</message>
</fst>

Another minor change to the code from the earlier post is that is will no longer be possible to change the message by directly setting the 'Message' property, although a custom message can be set by as per the following example:

if (_tcpServer != null)
    _tcpServer.SetMessage("Error");

This will allow users to not only monitor FST availability from a monitoring tool, but also the actual state of the FST instance being monitored.

Re: Diagnostic Monitoring of FST

Is it means that we can easily make FST responding with some activity data as: IsConnected, IsTrading, Symbol, Period, Balance, Equity, OpenLots, PositionDirection, FloatingProfitLoss...

Can we command FST through this server: StartTrading, StopTrading, ClosePosition...
If so, can we make some web interface, android app or Ipad app for that

I suppose that all of this is possible, but probably we can specify some communication interface  to allow user customization an expansion.

4

Re: Diagnostic Monitoring of FST

Yes, although I have not attempted to pass any messages back that are beyond the basic 4 status messages.  We can probably develop a simple schema for this to send it back in a structured format.

<fst>
  <status>IsConnected</status>
  <autotrading>True</autotrading>
  <broker>MyBroker</broker>
  <symbol>AUDUSD</symbol>
  <etc></etc>
</fst>

I don't think we need to do a advanced two-way communications at this stage, just responding with all the necessary data would probably work.

5

Re: Diagnostic Monitoring of FST

On second thoughts, rather than just a simple TCP Server, I may be better off doing this as a very basic HTTP server (with a configurable port) to allow for monitoring through an external application, but also directly from a browser.

6 (edited by ab 2013-02-17 03:16:01)

Re: Diagnostic Monitoring of FST

Did a little more work on this idea and have changed the diagnostic service to act as a HTTP server to allow for a direct browser connection.  The output is the majority of the Data object, so connectivity status, versions, and basic market information are all available via the diagnostic interface.

The command line syntax to use this feature remains unchanged, eg to open FST as Connection ID 100, Automatically Start Trading with the Strategy 'Test Trade.xml', and start the Diagnostic Web Server on port 1234, the syntax would be:

start "" "Forex Strategy Trader.exe" 100 yes "Test Trade" 1234

The web server is available by connecting to the FST client (by IP or hostname), along with the port and the /status path, eg: http://myfstsystem:1234/status

Example output at this stage is:

<fst>
  <IsConnected>True</IsConnected>
  <ConnectionID>1200</ConnectionID>
  <TerminalName>MetaTrader- AxiTrader</TerminalName>
  <ExpertVersion>1.17</ExpertVersion>
  <LibraryVersion>1.5</LibraryVersion>
  <Symbol>AUDUSD</Symbol>
  <Period>min30</Period>
  <Bars>400</Bars>
  <Bid>1.03024</Bid>
  <OldBid>1.03024</OldBid>
  <Ask>1.03069</Ask>
  <OldAsk>1.03069</OldAsk>
  <LastClose>1.03024</LastClose>
  <OldClose>0</OldClose>
  <ServerTime>15/02/2013 11:59:57 PM</ServerTime>
  <AccountName>Adam Burgess</AccountName>
  <AccountNumber>0</AccountNumber>
  <IsDemoAccount>True</IsDemoAccount>
  <AccountCurrency>AUD</AccountCurrency>
  <AccountBalance>9655.31</AccountBalance>
  <AccountEquity>9764.5</AccountEquity>
  <AccountProfit>109.19</AccountProfit>
  <AccountFreeMargin>9331.5</AccountFreeMargin>
  <BalanceDataPoints>2</BalanceDataPoints>
  <IsBalanceDataChganged>False</IsBalanceDataChganged>
  <PositionTicket>19415619</PositionTicket>
  <PositionType>1</PositionType>
  <PositionLots>0.1</PositionLots>
  <PositionOpenPrice>1.0325</PositionOpenPrice>
  <PositionOpenTime>15/02/2013 5:00:25 PM</PositionOpenTime>
  <PositionStopLoss>1.04262</PositionStopLoss>
  <PositionTakeProfit>0.98912</PositionTakeProfit>
  <PositionProfit>17.56</PositionProfit>
  <PositionComment>ID=1200,_Magic=90000002</PositionComment>
  <PositionDirection>Short</PositionDirection>
  <ConsecutiveLosses>0</ConsecutiveLosses>
  <ActivatedStopLoss>0</ActivatedStopLoss>
  <ActivatedTakeProfit>0</ActivatedTakeProfit>
  <ClosedSLTPLots>0</ClosedSLTPLots>
  <SavedStrategies>0</SavedStrategies>
  <WrongStopLoss>0</WrongStopLoss>
  <WrongTakeProf>0</WrongTakeProf>
  <WrongStopsRetry>0</WrongStopsRetry>
  <IsFailedCloseOrder>True</IsFailedCloseOrder>
  <CloseOrderTickCounter>0</CloseOrderTickCounter>
  <IsSentCloseOrder>False</IsSentCloseOrder>
  <ProgramName>Forex Strategy Trader</ProgramName>
  <ProgramVersion>1.6.0.1</ProgramVersion>
  <IsProgramBeta>False</IsProgramBeta>
  <ProgramID>1060001</ProgramID>
  <ProgramDir>C:\Forex Strategy Trader</ProgramDir>
  <SystemDir>C:\Forex Strategy Trader\System\</SystemDir>
  <LanguageDir>C:\Forex Strategy Trader\System\Languages\</LanguageDir>
  <ColorDir>C:\Forex Strategy Trader\System\Colors\</ColorDir>
  <DefaultStrategyDir>Strategies\</DefaultStrategyDir>
  <StrategyDir>C:\Users\adam.QANT\Desktop\Strategies</StrategyDir>
  <StrategyName>axitrader-AUDUSD-min30-1000 (0-988-227-3087-90000002).xml</StrategyName>
  <StrategyPath>C:\Users\adam.QANT\Desktop\Strategies\axitrader-AUDUSD-min30-1000 (0-988-227-3087-90000002).xml</StrategyPath>
  <IsStrategyChanged>False</IsStrategyChanged>
  <FirstBar>299</FirstBar>
  <SourceFolder>C:\Forex Strategy Trader\Custom Indicators\</SourceFolder>
  <LoadedSavedStrategy>C:\Users\adam.QANT\Desktop\Strategies\axitrader-AUDUSD-min30-1000 (0-988-227-3087-90000002).xml</LoadedSavedStrategy>
  <Icon>(Icon)</Icon>
  <Debug>False</Debug>
  <AutoUsePrvBarValue>True</AutoUsePrvBarValue>
  <FF>F5</FF>
  <DF>dd/MM/yy</DF>
  <DFS>dd/MM</DFS>
  <PointChar>.</PointChar>
  <VerticalDLU>1.728149</VerticalDLU>
  <HorizontalDLU>1.65574</HorizontalDLU>
  <IsData>True</IsData>
  <PeriodStr>30 Minutes</PeriodStr>
  <PeriodMTStr>M30</PeriodMTStr>
  <IsAutoStart>True</IsAutoStart>
  <StartAutotradeWhenConnected>False</StartAutotradeWhenConnected>
</fst>

This provides for a very wide range of parameters to be extracted via the diagnostic web interface.  For my purposes I need to extract only the values for IsConnected and IsFailedCloseOrder, and can display the status of each FST instance individually via this interface.
http://s3.postimage.org/60i9900v3/sample_prtg.jpg

The above image (which is taken from my monitoring system and not from FST) shows me (among other things) that I have 2 instances of FST available on the same market but different timeframes, they are both connected to MT4, although one of them has not been able to close out of a position, as indicated by the IsFailedCloseOrder flag.