Ho Ho Ho- 8 months after the release of the last version I hereby proudly present

ichinscratchy v0.3.0

It is an Ichimoku-based trading system originally developed in libreoffice/ openoffice basic macro language and rewritten in C from scratch. To immediately jump to the shiny new page, use: The Ichinscratchy trading system (or continue reading to find out about the new features).

This release contains many brand new features and might be followed by some maintenance releases that do some polish and/or fix bugs. Most prominent new features include a complete money management system that is aware of an account currency, can handle markets in different currencies and does the per-position risk-management in the account currency. Besides that the new version introduces two different market regime filters that are targeted towards filtering out sideways markets, more verbose outputs, a new way to access the database using a wrapper script that will execute pre-canned sql scripts and a lot more. See the complete changelog at the end of this article.

Actually most of the code was stable (stable in a sense of "does the job for me as I roughly intended") since October. Ever since then I wanted to do some documentation cleanup, write a LOT more documentation (especially the "first steps" part needs extensive care, as I am aware of the fact that the software is not an easy "click and forget" one- in short: make it more accessible and user friendly. But as time went by, I found myself busy with my work, my family and other commitments while above actions somewhat stalled. Now I decided to release at is, because I think it is still far better than nothing. Maybe I will add the missing information piece-by-piece, maybe not (in this case I will continue working on the software). 

The part of that release that I am most proud of is the introduction of the "money"-concept to the system. Before that, the software had no clue of underlying market currencies, account currencies, wins/losses in terms of money etc. All changes were in % for each market separate. To change that I had to dig deep within the entrails of the code, parts that I did not touch since writing them in early 2016- which again showed me how far I have come in terms of programming (translation: I used to be no programmer, now I became a lousy one).

 auto execution

The screenshot above shows the new money management in action. In this special case, the account currency is in €.  The signals are generated in the market currency (in the screenshots you can see SPX and DJI in $, DAX and Eurostoxx50 in € and EUR/JPY in...well..EUR/JPY :) ). The SL in the example above is also determined by the market (which can be points, pips, a currency or whatever) and calculated by using the "SL_[...]" options within the config file. The term "risk" in the screenshot quantifies exactly the difference between entry and exit by the calculated SL. The next term "max risk" is in account currency. Roughly speaking, it is your bet size. It is the equivalent of the "RISK_PER_POSITION" (in terms of %) setting within the limits of the account (current "balance" plus "risk free equity"- the latter being the active positions in the portfolio if sold for the current stop losses). While RISK_PER_POSITION quantifies for each individual position the % of your money that should be risked MAXIMUM, "max risk" translates that into account currencies` money.
By translating "risk" into account currency and dividing "max_risk" by "risk" you get the recommended quantity: the number of units of this market (where you got an entry signal) you should buy, based on the risk settings (to be more precise, this is only true for "PORTFOLIO_ALLOCATION=equal", if using the correlation-based allocation the position size might get even smaller as the overall portfolio risk (and the contribution of the current market) is also considered).
Sounds complicated? Yes, I am even worse in explaining than in coding...
Next big advantage is the possibility to quantify each trade (profit/loss) in terms of account currency. Until now the backtest results could show you a tendency, but tell nothing how much money you would actually would have won or lost. The same is true for the orderbook when doing live trading. To achive all this, I had to change the format of the config files that define the markets. Keep in mind that for translating one currency into another, you need quotes. Quotes of the actual pair: in above example you would need EUR/USD for SPX and DJI. USD/EUR would also suffice, the code checks if a suitable pair is available and terminate if not. On the other hand you can "switch off" some markets in the config file. For those markets neither signals nor trades will be generated. This is usefull if you don't want to trade specific FOREX pairs, but need their quotes for above currency conversions.
For the other shiny features, changes and bugfixes: the complete changelog is attached below:

changes in 0.3.0 from v0.2.1

New features:

  • changed symbol file contents and layout, new symbol file includes information that is needed for money management:
    # Indices =========================================================================================
    #symbol     filename        tradeable?      ticks/pips     contract size    cur     type        # comment
    DAX         DAX.csv             1           0.01              1             EUR     CFDFUT      # DAX30
    DJI         DOW.csv             1           0.01              1             USD     CFDFUT      # Dow Jones
    # Futures =========================================================================================
    #symbol     filename        tradeable?      ticks/pips     contract size    cur     type        # comment
    #BuFu        BuFu.csv           1           0.01              1             EUR     CFDFUT      # Euro Bund Future
    # Forex ===========================================================================================
    #symbol     filename        tradeable?      ticks/pips     contract size    cur     type        # comment
    EURJPY      EURJPY.csv          1           0.001           100000          EUR     CFDCUR      # Euro/ Japanese Yen
    EURUSD      EURUSD.csv          0           0.00001         100000          EUR     CFDCUR      # Euro/US Dollar
    comments still start with a '#', can be as a separate comment line or at the end of a line.
    Basic parsing and sanity checks are implemented, still user has to put some thought into the config. This change breaks compatibility of the symbol file with former releases.
  • changed/ new program start parameters:
    • added command line option -c/--configfile which specifies the name of the configuration under /config. This allows to run several systems/configurations from within one main folder (adjust database name accordingly)
    • when using verbose option -v/--verbose the program now spits out the account info (balance, equity and risk- free equity) each day, together with the already known buy-/sell signals.
    • when using the portfolio option -p/--portfolio the program shows the current account info (balance, equity and risk- free equity) in account currency, for each position current value (and risk free value) is shown
    • when using the report option -r/--report all wins/losses are now calculated in account currency
  • database changes: Please note that the changes mentioned below break compatibility with prior program versions!
    • changed all float fields to decimal(x,y). With float under certain circumstances strange behaviour occured, as floats are not represented/stored exactly. Fixed decimals are exact representations instead.
    • added new table account that stores some values which are needed to calculate profit/losses, your current cash, equity and such. The table hosts variables with their corresponding values. As in theory this table can store arbitrary variables and values, the following variables are currently needed by the program (and expected in the table):
      • balance (current free cash in account)
      • equity (free cash plus current value of positions- if sold right NOW)
      • risk_free_equity (free cash plus current value of positions if all their stop losses were hit NOW)
      • virgin_flag (initialized with 1 when creating db, valid until first position is bought- after that 0)
    • added new table currency_translation that holds all information for translations from/to account currency
    • added new fields to indicators_daily: ADXregime_filter
    • the tables quotes_dailyindicators_dailyichimoku_daily and ichimoku_daily_signals now have an additional column: daynr, which holds the date as "days since 1900-01-01"
    • the table orderbook_daily now has 2 price fields: price which holds the price in the symbol´s currency and cost_per_item which holds the buying price in account´s currency
    • the table portfolio now has 3 price fields: price_buy and price_last which hold the buying and the latest price in market´s currency and cost_per_item which holds the buying costs in accounts currency
  • changed/new config file options:
    • new: ACCOUNT_CURRENCY. This parameter sets the currency of your account. Currently implemented and valid values are:
      • EUR (Euro)
      • USD (US Dollar)
      • JPY (Japanese Yen)
    • new: INDI_ADX_PERIOD. This option specifies the period, over which the ADX shall be smoothed. Basically, the ADX is an exponential average of the DMI, which in turn contains the ATR, an exponential average of the True Range. INDI_ADX_PERIOD specifies the number of periods in those exponential moving averages. Default 14
    • new: SIGNAL_REGIME_FILTER. This option switches the market regime filter on (and choses which one to use). In sideways/non- trending markets signals will not be executed, resulting in lower trading frequency but higher quality signals. Following options are valid:
      • none (Turn market regime filter off)
      • ADX (Use Average Directional Index)
      • TNI (Trend Normality Indicator by @tasciccac)
    • new: SIGNAL_REGIME_ADX_THRESH. When SIGNAL_REGIME_FILTER is set to ADX, this option specifies the threshhold under which a market will be considered as sideways (=trendless). In this case signals in this specific market won't be executed. Default is 30.
    • new: STARTING_BALANCE, which sets starting account balance at begin of backtest/live trading
    • new: RISK_PER_POSITION which sets risk of a new position in % of current equity. In conjunction with the calculated initial stop loss this determines the size of the new position (in terms of how many units will be bought).
  • under /tools a new script sql2csv was created. This little helper reads in the config, executes a sql script within the same directory and gives the results in a .csv file. Two example files get_adx.sql (which gets date, close and ADX for a specific symbol) and export_orderbook.sql (which replaces the former export_trades.sh script) are already included (and likely to get more in the future)
  • startmysql.sh now expects a command line option -c followed by config file name (located under ../config)
  • small update to statistics report: now also display overall win/loss


  • fixed a (longtime) bug that caused execution to exclude the last day of available data

ichinscratchy v0.2.1, released on April, 9th 2017

changes from v0.2.0

New features:

  • database changes: added new fields to indicators_daily: HH_atr_periodLL_atr_period
  • added config file option SIGNAL_EXECUTION_SUNDAYS. If set to false, signals that occur on sundays are not executed. This can easily happen depending on users local time/date: When some markets open on monday morning, in other regions of the world it is still sunday evening
  • colored terminal output: errors -> red, warnings -> yellow, cyan -> SL, green -> signals
  • streamlined/shortened terminal output for signal/SL execution
  • colored html output: green -> uptrend/long, red -> downtrend/short, blue -> not trending
  • integrated persistence1D library to find local minima and maxima in price data (see https://people.mpi-inf.mpg.de/~weinkauf/notes/persistence1d.html)
  • added config file option ICHI_KUMO_CONFIRM. If set to true for a Kumo breakout to be valid the price has to make a higher high/lower low on close above/below previous (horizontal) reaction high/ reaction low. This drastically improves signal quality of Kumo breakouts at the cost of making a Kumo breakout a pretty rare event. This filter is the first benefit of integrating the persistence1d library into ichinscratchy codebase (more to come :))


  • Chandelier Stop now correctly use the SL_CHANDELIER_ATR_PERIOD nr. of days to determine highest highs/lowest lows (see database change). Prior to this fix the hh26/ll26 was used.
  • fixed situation when initial SL (Chandelier) is above price for long or below price for short position. This can happen in situation when there were sharp volatility changes in past. Fallback is to use the percentage stop for those situations

ichinscratchy v0.2.0, released on March, 5th 2017

changes from v0.1.0

New features:

  • implemented portfolio management using spearman correlation
  • new config option PORTFOLIO_ALLOCATION which selects the portfolio allocation model, currently equal (all position sizes are equal) and spearman (position size of new trade is determined by spearman correlation with existing portfolio entries)
  • added config option PORTFOLIO_SPEARMAN_PERIOD which determines the period used for calculating Spearmans Rho
  • added a bunch of config options PORTFOLIO_CORR_... and PORTFOLIO_PN_... to tailor position sizing based on correlation
  • database changes: portfolio now has the column pos_size; orderbook_daily column size was renamed to quantityand additional column pos_size was added ==> THIS BREAKS DATABASE COMPATIBILTY WITH versions < v0.2.0!!
  • added command line option -p/--portfolio to skip signal evaluation/execution and print out current portfolio to database
  • added average (mean) and median holding days to orderbook analysis/ reporting function (use --report or -rcommand line option)
  • export_trades.sh and startmysql.sh in /tools now parse the config file under /config, no more hardcoded db credentials in scripts
  • release version now comes with example DAX30 data file for users to start experimenting with
  • migrated source code documentation to doxygen-compatible style --> full reference in html/pdf now available under /docs


  • if run twice without updating the quotes (with a couple of days to execute), the program would sell positions based on the last SL in database. If days to execute date back long enough, it selled even positions which were bought later
  • when running backwards, the trend filter ICHI_CHIKOU_CONFIRM did not work properly
  • if portfolio contained more than 1 position with same SL, for each day the SL was hit only 1 SL was executed
  • when reporting statistics (-r/--report or config option) and there is no trade in db --> print message instead of crashing :)

ichinscratchy v0.1.0, released on December, 12 2016

initial release

(Mostly useless) statistics about the code:

  • ~ 8 months development
  • ~8400 lines of code (compared to 7000 in v0.2.1)
  • ~5200 lines comments (compared to 4300 in v0.2.1)
  • an unknown number of beers were harmed during this work

If you are interested, I visit the trading system category for it on my blog (see top menu), or follow this link: The Ichinscratchy trading system

Development is hosted over there at gitlab:


Feel free to join and contribute to this project!


{jd_file file==11}

Comments powered by CComment