Command-line Backtester for LUA Strategies

FXCM’s native Trading Station platform offers a visual backtester for those looking to test performance of a strategy and quickly and easily. However, the maximum backtesting period for this application is 48 months (fewer if conversion calculations are required). Therefore, an alternative is the command line version of the marketscope backtester, available here: http://fxcodebase.com/wiki/index.php/Indicore_Backtest_Utils

Using this version, you can backtest for much longer periods, and the output is also faster. The only drawback is that you don’t get the visual representation of the equity curve, but the statistics information is produced in the same way and it’s possible to output a full list of closed trades that could then be graphed, as well.

3 Likes

Dear @QN_Liza
I am trying to do back test using LUA.

The strategy is below:
condition 1: If EMA 100 periods of ATR 20 periods > EMA 499 periods of ATR 20 periods
Buy if:
next condition 2: SMA 10 periods > SMA 500 periods
next condition 3 : EMA 50 periods > EMA 500 periods
next condition (ichimoku) 4:
tenkansen>kijunsen & kijunsen > senkou_a & kijunsen > senkou_b

For EMA (EMA) and SMA (MVA) the streaming data is clear from Tutorial in YouTube:
gSource = ExtSubscribe(1, nil, instance.parameters.TF, instance.parameters.Type == “Bid”, “bar”);
iSMA500 = core.indicators:create(“MVA”, gSource.close, SMA500period)
iEMA50 = core.indicators:create(“EMA”, gSource.close, EMA50period)

First Question: How to get streaming data from secondary streaming (in my case iATR)? Have tried below with no success:
iATR = core.indicators:create(“ATR”, gSource.close, ATR20period)
iatr20ema100 = core.indicators:create(“EMA”, iATR, atr20ema100period)
iatr20ema950 = core.indicators:create(“EMA”, iATR, atr20ema950period)

Second question: How to get tenkansen, kijunsen, chiku_span, senkou_a and senkou_b in LUA?

Only very minor changes needed:

iATR = core.indicators:create("ATR", gSource, ATR20period)
iatr20ema100 = core.indicators:create("EMA", iATR.DATA, atr20ema100period)
iatr20ema950 = core.indicators:create("EMA", iATR.DATA, atr20ema950period)

Here are some snippets for creating an Ichimoku indicator in FXCM Trading Station:

Inside Prepare() function you need to create the indicator:
iICH = core.indicators:create("ICH", gSource, TenkanPeriods, KijunPeriods, SenkouSpanBPeriods)

Inside ExtUpdate() function there are the following 4 tables for Ichimoku data that can be called. This will print those values inside the Trading Station Events log so you can make sure they are the correct values:

core.host:trace("iICH.SL: " .. tostring(iICH.SL[period]))
core.host:trace("iICH.TL: " .. tostring(iICH.TL[period]))
core.host:trace("iICH.SA: " .. tostring(iICH.SA[period]))
core.host:trace("iICH.SB: " .. tostring(iICH.SB[period]))

Let me know if you have any further questions,

Rob

2 Likes

HI @QN_Rob,
Thank you for your prompt answer. For question number 2 actually I am looking for something like below (written in Python using pyti module https://github.com/kylejusticemagnuson/pyti/blob/master/pyti/ichimoku_cloud.py )

ts = tenkansen(pricedata[‘bidclose’], period=9)
ks = kijunsen(pricedata[‘bidclose’], period=26)
ck = chiku_span(pricedata[‘bidclose’])
sa = senkou_a(pricedata[‘bidclose’])
sb = senkou_b(pricedata[‘bidclose’], period=52)

when i put your answer in above format:
ks=core.host:trace("iICH.SL: " … tostring(iICH.SL[period]))
ts=core.host:trace("iICH.TL: " … tostring(iICH.TL[period]))
sa=core.host:trace("iICH.SA: " … tostring(iICH.SA[period]))
sb= core.host:trace("iICH.SB: " … tostring(iICH.SB[period]))

it says ERROR: ‘)’ expected near ‘…’

Please advice how to put above format in the ExtUpdate so i can get all 5 values to be compared each other and also with gSource.close.

Sorry for not making my self clear from beginning. And also I don’t understand how to print value inside the Trading Station Events log. As the YouTube tutorial only showing the trade was performed in the chart.

What you are looking for then is this:

ks=iICH.SL[period]
ts=iICH.TL[period]
sa=iICH.SA[period]
sb= iICH.SB[period]
ck = nil
if iICH.CS[period] ~= nil then
   ck = iICH.CS[period]
end

You can then use ks, ts, sa, sb, and ck to compare to whatever you need, including gSource.close. Feel free to email me your source code if you remain stuck after the above changes.

Rob
rob@fxcm.com