Strategy · Pine Script v5 · On the chart

Ichimoku Kinko Hyo TK Cross Strategy

by SynergOps· code credited to Salih Emin (cerebrux)

This long-only strategy executes trades based on Ichimoku Kinko Hyo Tenkan-Sen and Kijun-Sen crossovers.

View on GitHub

GitHub stars7on the repository
Pine versionv5runs as is
Lines of code393
Settings18inputs
LicenceMPL-2.0
Last update1 year ago4 Aug 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

393 lines of Pine Script v5 from Ichimoku Kink Hyo - Strategy/4 - Ichimoku TK Cross Long only Strategy/ichimoku TK Cross.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

ichimoku TK Cross.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Salih Emin (cerebrux)

//@version=5
strategy('Ichimoku Kinko Hyo: TK Cross Strategy', overlay=true, default_qty_value = 100, default_qty_type = strategy.percent_of_equity, initial_capital = 100)

//Inputs
Tenkan_sen = input.int(9, minval=1, title='Tenkan-Sen')
Kijun_sen = input.int(26, minval=1, title='Kijun-Sen')
Senku_spanB = input.int(52, minval=1, title='Senkou-Span B')
Chiku_span_offset = input.int(26, minval=1, title='Chikou-Span Offset')
Kumo_offset = input.int(26, minval=1, title='Kumo Offset')

middle(len) => math.avg(ta.lowest(len), ta.highest(len))

// Ichimoku Components
tenkan = middle(Tenkan_sen)
kijun = middle(Kijun_sen)
senkouA = math.avg(tenkan, kijun)
senkouB = middle(Senku_spanB)

// Plot Ichimoku Kinko Hyo
plot(tenkan, color=color.new(#04ff19, 0), title='Tenkan-Sen')
plot(kijun, color=color.new(#991515, 0), title='Kijun-Sen')
plot(close, offset=-Chiku_span_offset + 1, color=color.new(#459915, 0), title='Chikou-Span')
senkouAplot = plot(senkouA, offset=Kumo_offset - 1, color=color.new(color.green, 0), title='Senkou-Span A')
senkouBplot = plot(senkouB, offset=Kumo_offset - 1, color=color.new(color.red, 0), title='Senkou-Span B')
fill(senkouAplot, senkouBplot, color = senkouA > senkouB ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90), title='Cloud color')

ss_high = math.max(senkouA[Kumo_offset - 1], senkouB[Kumo_offset - 1])
ss_low = math.min(senkouA[Kumo_offset - 1], senkouB[Kumo_offset - 1])

// Entry Signals

// Conditions for Long
long_entry = input(true, title='Long Entry')
tk_cross_bull = tenkan > kijun

// Conditions for exit
tk_cross_bear = tenkan < kijun

// Create Signal condition for buy
if tk_cross_bull and long_entry
    strategy.entry(id = 'Buy', direction = strategy.long, alert_message = 'Open Long Position')
    alert('Long entry signal', alert.freq_once_per_bar)

// Create Signal condition for closing buy
if tk_cross_bear and long_entry
    strategy.close(id = 'Buy', alert_message = 'Close Long Position')
    alert('Exit your position', alert.freq_once_per_bar)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MONTHLY TABLE based on the script written by QuantNomad - Copy & Paste code from here down into your strategy script /{
// Original Script: https://tradingview.com/script/kzp8e4X3-Monthly-Returns-in-PineScript-Strategies/                   //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var string GROUP_PERFORMANCE_TABLE = "Monthly Performance Table"
mptable_on = input.bool(title="Turn On |", defval=true, display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Toggles")
mptable_debug = input.bool(title="Debug Mode |", defval=false, display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Toggles")
mptable_precision = input.int(title="Decimal Precision", defval=2, minval=1, display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Toggles", tooltip="Decimal precision of each cell")
mptable_titleColor = input.color(title="Title Cell Color", defval=#cccccc, display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Colors")
mptable_titleTextColor = input.color(title="Title Text Color", defval=#363a45, display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Colors")
mptable_textColor = input.color(title="Cell Text Color", defval=color.white, display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Colors")
mptable_ProfitColor = input.color(title="Year Profit Color", defval=color.new(color.green, 50), display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Colors")
mptable_LossColor = input.color(title="Year Loss Color", defval=color.new(color.red, 50), display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Colors")
mptable_BreakEvenColor = input.color(title="Year B/E Color", defval=color.new(color.white, 50), display=display.none, group=GROUP_PERFORMANCE_TABLE, inline="MPT_Colors")
mptable_pageNumber = input.int(title="Page Number", defval=1, minval=1, step=1, maxval=10, display=display.none, group=GROUP_PERFORMANCE_TABLE, tooltip="Which page of results to display") - 1 // -1 is for corection for arrays. Aaray index start with 0 
mptable_pageSize = input.int(title="Page Size (Rows)", defval=20, minval=1, display=display.none, group=GROUP_PERFORMANCE_TABLE, tooltip="How many rows to display") - 1  // 9 is used to show 10 rows of data due to array start from 0
mptable_tableTextSize = input.string(title="Text Size", defval="Small", options=["Auto",  "Huge",  "Large", "Normal", "Small", "Tiny"], display=display.none, group=GROUP_PERFORMANCE_TABLE)

// Custom function for getting table text sized based on user input
table_text_size(_size) =>
    switch _size
        "Auto"   => size.auto   
        "Huge"   => size.huge   
        "Large"  => size.large  
        "Normal" => size.normal 
        "Small"  => size.small
        => size.tiny
tableTextSize = table_text_size(mptable_tableTextSize)

// Custom function for getting decimal precision based on given number 
// (eg. if number is > 0 but < 0.05 or < 0 and > -0.05, set precision to 3 to avoid rounding to 0 which is misleading)
GetRoundingPrecision(float num) =>
    if (num > 0 and num < 0.05) or (num < 0 and num > -0.05)
        3
    else
        mptable_precision

// Define an open trade's cost (used to calculate commission cost)
type TradeCost
    int entryTime
    float entryPrice
    float cost

// Define a monthly/yearly return type
type StrategyReturn
    float profit
    float drawdown
    float peak
    int timestamp

// Store accumulated P&L values
var float accumulatedMonthlyPL = 0
var float accumulatedYearlyPL = 0
var float bestAccumulatedMonthlyPL = 0
var float bestAccumulatedYearlyPL = 0

// Store drawdown values
var float equityPeak = strategy.initial_capital
var float yearlyEquityHigh = 0
var float currentYearlyDrawdown = 0
var float yearlyMaxDrawdown = 0
var float worstDrawdown = 0
var float monthlyEquityHigh = 0
var float currentMonthlyDrawdown = 0
var float monthlyMaxDrawdown = 0
var int currentDrawdownBars = 0
var int maxDrawdownBars = 0

// Store stat arrays
var totalDrawdownBars = array.new<int>(0)
var totalDrawdowns = array.new<float>(0)

// Store long & short trade count
var int totalBreakEvenTrades = 0
var int totalLongTrades = 0
var int totalLongTradeWins = 0
var int totalShortTrades = 0
var int totalShortTradeWins = 0

// Store open trade commission costs in array
var costOfOpenTrades = array.new<TradeCost>(0)

// Detect opened trade and save cost of trade (I tried many methods to get my numbers to match the Cumulative Profit list in the Strategy Tester, no idea why, but none of them worked without doing this)
if strategy.opentrades != strategy.opentrades[1] and strategy.closedtrades == strategy.closedtrades[1]
    costOfTrade = strategy.grossloss - strategy.grossloss[1]
    costOfOpenTrades.push(TradeCost.new(strategy.opentrades.entry_time(strategy.opentrades - 1), strategy.opentrades.entry_price(strategy.opentrades - 1), costOfTrade))

// Detect a closed trade
// TV Documentation: Trade List's Cumulative Profit % Formula = TradeProfit / (InitialCapital + Cumulative Profit of the previous trades) * 100%
if strategy.closedtrades != strategy.closedtrades[1]
    
    // Retrieve trade cost for the closed trade
    float tradeCost = 0
    int removeIdx = -1
    if costOfOpenTrades.size() > 0
        for i = 0 to costOfOpenTrades.size() - 1
            TradeCost tc = costOfOpenTrades.get(i)
            if tc.entryTime == strategy.closedtrades.entry_time(strategy.closedtrades - 1) and tc.entryPrice == strategy.closedtrades.entry_price(strategy.closedtrades - 1)
                tradeCost := tc.cost
                removeIdx := i 
                break
    
    // Remove cost
    if removeIdx != -1
        costOfOpenTrades.remove(removeIdx)

    // Calculate equity before trade closed (strategy.equity will not do, because it changes bar-by-bar based on open P&L not realized P&L)
    float preEquity = strategy.initial_capital + strategy.netprofit[1]

    // Calculate P&L + cost of this trade
    float profitLoss = 0 
    if strategy.losstrades > strategy.losstrades[1]
        profitLoss := (strategy.grossloss - (strategy.grossloss[1] - tradeCost)) * -1
    else
        profitLoss := strategy.grossprofit - strategy.grossprofit[1]
    
    // Check if this was a long or short trade and if it won or lost
    if strategy.position_size[1] > 0
        totalLongTrades := totalLongTrades + 1
        if profitLoss > 0
            totalLongTradeWins := totalLongTradeWins + 1
    else if strategy.position_size[1] < 0
        totalShortTrades := totalShortTrades + 1
        if profitLoss > 0
            totalShortTradeWins := totalShortTradeWins + 1
        
    // Check if the trade broke even
    if profitLoss == 0
        totalBreakEvenTrades := totalBreakEvenTrades + 1

    // Calculate cumulative profit % for this trade 
    float cumulativeProfitPercent = (profitLoss / preEquity) * 100

    // Store highest peak value of equity (we can now use strategy.equity since equity has updated to realized P&L on this bar)
    if strategy.equity > equityPeak
        equityPeak := strategy.equity

    // Calculate total system drawdown %
    float equityDD = ((strategy.equity - equityPeak) / equityPeak) * 100
    if equityDD < worstDrawdown
        worstDrawdown := equityDD

    // Store accumulated monthly + yearly P&L
    accumulatedMonthlyPL := cumulativeProfitPercent + accumulatedMonthlyPL[1]
    accumulatedYearlyPL := accumulatedYearlyPL + cumulativeProfitPercent

    // Save max favourable excursion for this month (ie. peak return as %)
    if accumulatedMonthlyPL > bestAccumulatedMonthlyPL
        bestAccumulatedMonthlyPL := accumulatedMonthlyPL

    // Save max favourable excursion for this year (ie. peak return as %)
    if accumulatedYearlyPL > bestAccumulatedYearlyPL
        bestAccumulatedYearlyPL := accumulatedYearlyPL

    // Track max equity high over current year for max yearly drawdown calculation
    if accumulatedYearlyPL > yearlyEquityHigh
        yearlyEquityHigh := accumulatedYearlyPL
    
    // Check if our yearly realized equity high minus current realized equity exceeds our stored max drawdown for the year, update if necessary, and save worst drawdown
    if accumulatedYearlyPL - yearlyEquityHigh < 0
        currentYearlyDrawdown := accumulatedYearlyPL - yearlyEquityHigh
        if currentYearlyDrawdown < yearlyMaxDrawdown
            yearlyMaxDrawdown := currentYearlyDrawdown
        currentDrawdownBars := currentDrawdownBars + 1
    
    // Track max equity high over current month for max monthly drawdown calculation
    if accumulatedMonthlyPL > monthlyEquityHigh
        monthlyEquityHigh := accumulatedMonthlyPL
    
    // Check if our monthly realized equity high minus current realized equity exceeds our stored max drawdown for the month, update if necessary, and save worst drawdown
    if accumulatedMonthlyPL - monthlyEquityHigh < 0
        currentMonthlyDrawdown := accumulatedMonthlyPL - monthlyEquityHigh
        if currentMonthlyDrawdown < monthlyMaxDrawdown
            monthlyMaxDrawdown := currentMonthlyDrawdown
    
    // Debug label
    if mptable_debug
        string debugTip = "Equity = $" + str.tostring(strategy.equity, "#.##") + 
         "\nP&L=" + str.tostring(cumulativeProfitPercent) + "%" +
         "\nAccumMonthlyP&L=" + str.tostring(math.round(accumulatedMonthlyPL, GetRoundingPrecision(accumulatedMonthlyPL))) + "%" +
         "\nAccumYearlyP&L=" + str.tostring(math.round(accumulatedYearlyPL, GetRoundingPrecision(accumulatedYearlyPL))) + "%" +
         "\nMonthlyMaxDD=" + str.tostring(math.round(monthlyMaxDrawdown, GetRoundingPrecision(monthlyMaxDrawdown))) + "%" +
         "\nYearlyMaxDD=" + str.tostring(math.round(yearlyMaxDrawdown, GetRoundingPrecision(yearlyMaxDrawdown))) + "%" +
         "\nTotalMaxDD=" + str.tostring(math.round(worstDrawdown, GetRoundingPrecision(worstDrawdown))) + "%" +
         "\nCurrentDDBars=" + str.tostring(currentDrawdownBars) +
         "\nMaxDDBars=" + str.tostring(maxDrawdownBars) +
         "\nTotalBreakEven=" + str.tostring(totalBreakEvenTrades) +
         "\nTotalLongs=" + str.tostring(totalLongTrades) +
         "\nTotalLongWins=" + str.tostring(totalLongTradeWins) +
         "\nTotalShorts=" + str.tostring(totalShortTrades) +
         "\nTotalShortWins=" + str.tostring(totalShortTradeWins)
        label.new(bar_index, high + (high * 0.01), "P&L " + str.tostring(math.round(cumulativeProfitPercent, GetRoundingPrecision(cumulativeProfitPercent))) + "%", tooltip=debugTip, textcolor=color.white)

// Calculate drawdown since last equity high (NOT max drawdown, just the current max DD since we were out of DD)
float t_equityDD = ((strategy.equity - equityPeak) / equityPeak) * 100
var float currentMaxDrawdownSinceLast = 0

// Update Max Drawdown bar count and current DD if equity is under water, check isconfirmed to prevent double-counting bars with recalc_on_order_fills on
if strategy.equity < equityPeak and barstate.isconfirmed
    currentDrawdownBars := currentDrawdownBars + 1
    if currentDrawdownBars > maxDrawdownBars
        maxDrawdownBars := currentDrawdownBars
    if t_equityDD < currentMaxDrawdownSinceLast
        currentMaxDrawdownSinceLast := t_equityDD
else
    if currentDrawdownBars > 0
        totalDrawdownBars.push(currentDrawdownBars)
        totalDrawdowns.push(currentMaxDrawdownSinceLast)
    currentDrawdownBars := 0
    currentMaxDrawdownSinceLast := 0

// Prepare arrays to store Yearly and Monthly P&Ls
var monthlyReturns = array.new<StrategyReturn>(0)
var yearlyReturns = array.new<StrategyReturn>(0)

var bool firstEntryTime = false
// Retrieve entry time of initial entry in open position
if not firstEntryTime and strategy.opentrades.entry_time(0)
    firstEntryTime := true

// Detect new month and year
new_month = month(time) != month(time[1])
new_year = year(time) != year(time[1])

// Detect a new month and store its return profile
if not barstate.isfirst and new_month and firstEntryTime or barstate.islastconfirmedhistory
    StrategyReturn mr = StrategyReturn.new(accumulatedMonthlyPL, monthlyMaxDrawdown, bestAccumulatedMonthlyPL, time[1]) // time)
    monthlyReturns.push(mr)
    accumulatedMonthlyPL := 0
    monthlyMaxDrawdown := 0
    monthlyEquityHigh := 0
    currentMonthlyDrawdown := 0
    bestAccumulatedMonthlyPL := 0

    // Detect a new year and reset tracking variables
if not barstate.isfirst and new_year and firstEntryTime or barstate.islastconfirmedhistory
    StrategyReturn yr = StrategyReturn.new(accumulatedYearlyPL, yearlyMaxDrawdown, bestAccumulatedYearlyPL, time[1])
    yearlyReturns.push(yr)
    accumulatedYearlyPL := 0
    yearlyMaxDrawdown := 0
    yearlyEquityHigh := 0
    currentYearlyDrawdown := 0
    bestAccumulatedYearlyPL := 0

// DEBUG code
bgcolor(mptable_debug and new_month ? color.lime : na, title="New Month", display=display.none)
bgcolor(mptable_debug and new_year ? color.red : na, title="New Year", display=display.none)
// END DEBUG CODE

// Define Monthly P&L Table    
var table performance_table = table(na)

//Adjust mptable_pageSize if the years are less than the mptable_pageSize
if yearlyReturns.size() < mptable_pageSize
    mptable_pageSize := yearlyReturns.size()

// Caluclate the start and end of page to display
startIndex = math.max(math.min(yearlyReturns.size() - 1, yearlyReturns.size() - 1 - (mptable_pageSize + 1) * mptable_pageNumber), mptable_pageSize - 1)
endIndex = math.max(startIndex - mptable_pageSize, 0)
mptable_pageSize := endIndex <= mptable_pageSize ? endIndex : mptable_pageSize

// If this is the last bar on our chart, display the performance table
var int EXTRA_STAT_ROWS = 5 // This ensures table includes enough rows for CAGR etc
if mptable_on and monthlyReturns.size() > 0 and barstate.islastconfirmedhistory

    // Create table (100 rows = 100 years of data, should be plenty for all markets!)
    performance_table := table.new(position.bottom_right, columns=17, rows=yearlyReturns.size() + EXTRA_STAT_ROWS, border_width=1)

    // Set column headers
    performance_table.cell(0, 0, "Year", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(1, 0, "Jan", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(2, 0, "Feb", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(3, 0, "Mar", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(4, 0, "Apr", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(5, 0, "May", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(6, 0, "Jun", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(7, 0, "Jul", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(8, 0, "Aug", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(9, 0, "Sep", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(10, 0, "Oct", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(11, 0, "Nov", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(12, 0, "Dec", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(13, 0, "TOTAL", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
    performance_table.cell(14, 0, "MaxDD", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)

    // Set yearly values
    for year_index = startIndex to yearlyReturns.size() == 0 ? na : endIndex
        
        // Get yearly return for this loop, set year number in first column, determine color of cell
        StrategyReturn yearlyReturn = yearlyReturns.get(year_index)

        // Set year title and determine color
        performance_table.cell(0, year_index + 1, str.tostring(year(yearlyReturn.timestamp)), bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_size=tableTextSize)
        color y_color = yearlyReturn.profit > 0 ? mptable_ProfitColor : yearlyReturn.profit == 0 ? mptable_BreakEvenColor : mptable_LossColor

        // Populate yearly cell values
        string yearlyTip = "MaxDD: " + str.tostring(math.round(yearlyReturn.drawdown, GetRoundingPrecision(yearlyReturn.drawdown))) + "%" +
             "\nMFE: " + str.tostring(math.round(yearlyReturn.peak, GetRoundingPrecision(yearlyReturn.peak))) + "%"
        performance_table.cell(13, year_index + 1, (yearlyReturn.profit > 0 ? "+" : "") + str.tostring(math.round(yearlyReturn.profit, GetRoundingPrecision(yearlyReturn.profit))) + "%", bgcolor=y_color, text_color=color.white, text_size=tableTextSize, tooltip=yearlyTip)
        performance_table.cell(14, year_index + 1, str.tostring(math.round(yearlyReturn.drawdown, GetRoundingPrecision(yearlyReturn.drawdown))) + "%", bgcolor=mptable_BreakEvenColor, text_color=color.white, text_size=tableTextSize)

        // Set monthly values
        for month_index = 0 to monthlyReturns.size() - 1

            // Get monthly return for this loop, get current year for this loop, then calculate the corresponding table column and row
            StrategyReturn monthlyReturn = monthlyReturns.get(month_index)
            int yearOfMonth = year(monthlyReturn.timestamp)
            int monthCol = month(monthlyReturn.timestamp)
            
            // populate monthly profit only if the years of the yearly return match with the monthly return. 
            if yearOfMonth == year(yearlyReturn.timestamp)
                 // Determine color for monthly P&L
                color m_color = monthlyReturn.profit > 0 ? color.new(mptable_ProfitColor, color.t(mptable_ProfitColor) + 20) : monthlyReturn.profit == 0 ? color.new(mptable_BreakEvenColor, color.t(mptable_BreakEvenColor) + 20) : color.new(mptable_LossColor, color.t(mptable_LossColor) + 20)
                
                // Set monthly P&L cell
                string monthlyTip = "MaxDD: " + str.tostring(math.round(monthlyReturn.drawdown, GetRoundingPrecision(monthlyReturn.drawdown))) + "%" +
                     "\nMFE: " + str.tostring(math.round(monthlyReturn.peak, GetRoundingPrecision(monthlyReturn.peak))) + "%"
                performance_table.cell(monthCol, year_index + 1, str.tostring(math.round(monthlyReturn.profit, GetRoundingPrecision(monthlyReturn.profit))), bgcolor=m_color, text_color=color.white, text_size=tableTextSize, tooltip=monthlyTip)

    float percentReturn = (strategy.netprofit / strategy.initial_capital) * 100
    float cagr = (math.pow((strategy.netprofit + strategy.initial_capital) / strategy.initial_capital, 1 / yearlyReturns.size()) - 1) * 100
    float mar = cagr / math.abs(worstDrawdown)
    lastMonthRowIndex = startIndex < 5 ? 5 : startIndex

    // Populate table data
    float totalWinRate = (strategy.wintrades / strategy.closedtrades) * 100
    float longWinRate = nz((totalLongTradeWins / totalLongTrades) * 100)
    float shortWinRate = nz((totalShortTradeWins / totalShortTrades) * 100)
    string returnTip = "Based on a total of " + str.tostring(strategy.closedtrades) + " trades" +
         "\nWin Rate = " + str.tostring(math.round(totalWinRate, GetRoundingPrecision(totalWinRate))) + "%" +
         "\nLong Trades = " + str.tostring(totalLongTrades) + " (Win " + str.tostring(math.round(longWinRate, GetRoundingPrecision(longWinRate))) + "%)" +
         "\nShort Trades = " + str.tostring(totalShortTrades) + " (Win " + str.tostring(math.round(shortWinRate, GetRoundingPrecision(shortWinRate))) + "%)"
    performance_table.cell(15, lastMonthRowIndex, "Return: " + (percentReturn > 0 ? "+" : "") + str.tostring(math.round(percentReturn, GetRoundingPrecision(percentReturn))) + "%", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_font_family=font.family_monospace, text_size=tableTextSize, tooltip=returnTip)
    performance_table.cell(15, lastMonthRowIndex - 1, "MAR: " + str.tostring(mar, "#.##"), bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_font_family=font.family_monospace, text_size=tableTextSize, tooltip="Measure of return adjusted for risk: CAGR divided by Max Drawdown. Indicates how comfortable the system might be to trade. Higher than 0.5 is ideal, 1.0 and above is very good, and anything 3.0 or above should be considered suspicious.")
    performance_table.cell(15, lastMonthRowIndex - 2, "DD Bars: " + str.tostring(maxDrawdownBars), bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_font_family=font.family_monospace, text_size=tableTextSize, tooltip="Average Drawdown Bars: " + str.tostring(totalDrawdownBars.avg(), "#.#") + "\n\nThis is how many bars it took to recover the longest drawdown (note: this is different to the MAX drawdown, and represents time drawdown)")
    performance_table.cell(15, lastMonthRowIndex - 3, "MaxDD: " + str.tostring(math.round(worstDrawdown, GetRoundingPrecision(worstDrawdown))) + "%", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_font_family=font.family_monospace, text_size=tableTextSize, tooltip="Average Drawdown: " + str.tostring(totalDrawdowns.avg(), "#.##") + "%\n\nThis number is different to the Strategy Tester because this number is based on closed trade equity while the Tester's MaxDD is based on open equity.")
    performance_table.cell(15, lastMonthRowIndex - 4, "CAGR: " + (cagr > 0 ? "+" : "") + str.tostring(math.round(cagr, GetRoundingPrecision(cagr))) + "%", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_font_family=font.family_monospace, text_size=tableTextSize, tooltip="Compounded annual growth rate")
    performance_table.cell(15, lastMonthRowIndex - 5, "REALIZED P&L", bgcolor=mptable_titleColor, text_color=mptable_titleTextColor, text_font_family=font.family_monospace, text_size=tableTextSize, tooltip="These numbers are based on Realized equity (closed trades)")
// } END MONTHLY TABLE

/////////// END OF PERFORMANCE TABLE CODE. ///////////

Overview

Ichimoku Kinko Hyo TK Cross Strategy opens a long position when the Tenkan-Sen moves above the Kijun-Sen and closes the position when the Tenkan-Sen falls below the Kijun-Sen. Main settings allow customization of Ichimoku periods (Tenkan, Kijun, Senkou Span B) and offset parameters. The script plots the full Ichimoku indicator overlay on the price chart and renders an embedded monthly performance table. Note that the strategy relies purely on crossover signals for exits without dedicated stop-loss or take-profit rules.

Details

Published by

SynergOps on GitHub

Code credit

Salih Emin (cerebrux), as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Screeners & dashboards

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Tenkan-Senint9Tenkan_sen
Kijun-Senint26Kijun_sen
Senkou-Span Bint52Senku_spanB
Chikou-Span Offsetint26Chiku_span_offset
Kumo Offsetint26Kumo_offset
Long Entrybooltruelong_entry
Turn On |booltruemptable_on
Debug Mode |boolfalsemptable_debug
Decimal Precisionint2mptable_precision
Title Cell Colorcolor#ccccccmptable_titleColor
Title Text Colorcolor#363a45mptable_titleTextColor
Cell Text Colorcolorcolor.whitemptable_textColor
Show all 18 settings
SettingTypeDefaultVariable
Year Profit Colorcolorcolor.new(color.green, 50)mptable_ProfitColor
Year Loss Colorcolorcolor.new(color.red, 50)mptable_LossColor
Year B/E Colorcolorcolor.new(color.white, 50)mptable_BreakEvenColor
Page Numberint1mptable_pageNumber
Page Size (Rows)int20mptable_pageSize
Text SizestringSmallmptable_tableTextSize
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

AC- MY SCRIPT1

by hasnocool
106 stars

This strategy plots an Optimized Trend Tracker and a selectable moving-average support line on the price chart. It builds the average as SMA, EMA, WMA, TMA, VAR, WWMA, ZLEMA, or TSF, then offsets long and short stops by a percent of that average. Optional mark

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of AC- MY SCRIPT1

Calculates a custom moving average (MaMA) by modifying the source price with price momentum, acceleration, and psychological win-rate probability before applying an EMA or SMA. Plots the adjusted moving average directly on the price chart alongside optional re

Strategy v5 Moving averagesTrend
Updated 4 years ago · None stated GitHub repository of Momentum Adjusted Moving Average by DGT

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers