strat: Create Ichimoku Strategies

View source: R/strat.R

stratR Documentation

Create Ichimoku Strategies


Create ichimoku cloud strategies using the indicator condition 'long / short while c1 > c2'. Complex strategies can be formulated as combined 'c1 > c2 & c3 > c4' (both conditions must be satisfied) or asymmetric 'c1 > c2 x c3 > c4' (where 'c1 > c2' denotes the entry and 'c3 > c4' the exit indicator).


  c1 = c("close", "chikou", "open", "high", "low", "tenkan", "kijun", "senkouA",
    "senkouB", "cloudT", "cloudB"),
  c2 = c("tenkan", "kijun", "senkouA", "senkouB", "cloudT", "cloudB", "chikou",
    "close", "open", "high", "low"),
  c3 = c("close", "chikou", "open", "high", "low", "tenkan", "kijun", "senkouA",
    "senkouB", "cloudT", "cloudB"),
  c4 = c("tenkan", "kijun", "senkouA", "senkouB", "cloudT", "cloudB", "chikou",
    "close", "open", "high", "low"),
  dir = c("long", "short"),
  type = 2



an ichimoku object.


[default 'close'] column name specified as a string.


[default 'tenkan'] column name specified as a string.


(optional) column name specified as a string.


(optional) column name specified as a string.


[default 'long'] trade direction, either 'long' or 'short'.


[default 2] if 'c3' and 'c4' are specified, type 2 will create the combined strategy 'c1 > c2 & c3 > c4' whilst type 3 will create the asymmetric strategy 'c1 > c2 x c3 > c4'.


The following assumption applies to all strategies: confirmation of whether a condition is satisfied is received at the 'close' of a particular period, and a transaction is initiated at the immediately following 'open'. All transactions occur at the 'open'.

By default, the periods in which the strategy results in a position is shaded on the ichimoku cloud chart and the strategy is printed as the chart message (if not otherwise specified). To turn off this behaviour, pass the strat = FALSE argument to plot() or iplot().


An ichimoku object augmented with the strategy.

Ichimoku Object Specification for Strategies

The ichimoku object is augmented with the following additional elements:

Columns [numeric]:

  • $cond: a boolean vector if the indicator condition is met

  • $posn: a boolean vector indicating if a position is held

  • $txn: a vector representing the transactions to implement the position (1 = enter position, -1 = exit position)

  • $logret: a vector of log returns

  • $slogret: a vector of log returns for the strategy

  • $ret: a vector of discrete returns

  • $sret: a vector of of discrete returns for the strategy


  • $strat: the strategy summary [matrix]

The strategy summary may be accessed by the summary() method for ichimoku objects or via look.

Complex Strategies

For complex strategies: 's1' denotes the strategy 'c1 > c2' and 's2' denotes the strategy 'c3 > c4'.

  • Combined strategy 's1 & s2': indicator conditions in 's1' and 's2' have to be met simulateneously for a position to be taken. The column $cond will show when both conditions are met.

  • Asymmetric strategy 's1 x s2': indicator condition in 's1' has to be met to enter a position, and indicator condition in 's2' to exit a position. These rules are applied recursively over the length of the data. The column $cond will show when the indicator condition is met in 's1'

Further Details

Please refer to the strategies vignette by calling: vignette("strategies", package = "ichimoku")


cloud <- ichimoku(sample_ohlc_data, ticker = "TKR")

strat <- strat(cloud, c1 = "tenkan", c2 = "cloudB", dir = "short")

strat2 <- strat(cloud, c1 = "cloudT", c2 = "kijun", c3 = "cloudT", c4 = "close")

ichimoku documentation built on May 23, 2022, 9:05 a.m.