Header Ads

  • Ticker News

    High success rate Ichimoku Cloud trading strategy

     

    The Ichimoku Cloud, often referred to as Ichimoku Kinko Hyo, is a comprehensive technical analysis tool and trading strategy in forex trading. Developed by Goichi Hosoda in the 1960s, it provides a holistic view of price dynamics, combining various components to help traders identify potential trends, support and resistance levels, and trade signals. 


    Here's a concise overview of the Ichimoku Cloud trading strategy:

    Components:

    • Tenkan-sen (Conversion Line): A moving average of the highest high and lowest low over a specified period. It's often used to identify short-term trends.
    • Kijun-sen (Base Line): Similar to the Tenkan-sen, but calculated over a longer period. It offers insights into medium-term trends.
    • Senkou Span A (Leading Span 1): The average of the Tenkan-sen and Kijun-sen, projected ahead by a certain number of periods.
    • Senkou Span B (Leading Span 2): The average of the highest high and lowest low over an extended period, also projected ahead.
    • Kumo (Cloud): The area between Senkou Span A and Senkou Span B. It serves as a visual representation of support and resistance zones.

    Strategy:

    • Cloud Color and Position: A bullish trend is identified when the Senkou Span A is above Senkou Span B, forming a green cloud. A bearish trend is indicated by a red cloud with Senkou Span A below Senkou Span B.
    • Crossovers: When the Tenkan-sen crosses above the Kijun-sen, it generates a bullish signal. Conversely, a bearish signal is produced when the Tenkan-sen crosses below the Kijun-sen.
    • Kumo Breakouts: A breakout occurs when the price moves above or below the cloud. These breakouts can suggest potential trend changes or continuation.
    • Chikou Span (Lagging Line): The current closing price plotted back by a certain number of periods. Its position relative to historical price action can provide confirmation for trade signals.

    Benefits:

    • Holistic Analysis: The Ichimoku Cloud provides a comprehensive overview of the market by considering multiple components simultaneously.
    • Dynamic Support and Resistance: The Kumo acts as a support or resistance area, aiding in identifying potential entry and exit points.
    • Trend Confirmation: The combination of components helps confirm trends and reduce false signals.

    Considerations:

    • Complexity: The Ichimoku Cloud involves multiple elements, which might require time and practice to fully understand and interpret.
    • Adaptation: Different timeframes and market conditions can influence the effectiveness of the strategy.

    Incorporating the Ichimoku Cloud strategy into your trading plan requires dedication and familiarity with its components. Traders should backtest the strategy, consider risk management, and adapt it to their trading style and risk tolerance. As with any strategy, practicing in a demo environment before applying it in real trading is highly recommended.

    Explaining the code

    The code is an implementation of an Ichimoku Cloud trading strategy in Pine Script, which is used for creating custom trading indicators and strategies on the TradingView platform.

    Here's a breakdown of the code:

    Strategy Setup:

    • Sets the title and initial parameters for the strategy, such as capital, order quantity, and commission.
    • Provides options to show/hide the Ichimoku Cloud, TP/SL levels, and additional indicators.

    Ichimoku Cloud Calculation:

    • Defines a function called donchian() that calculates the Donchian channel for a given length.
    • Calculates the Conversion Line, Base Line, Leading Span A, Leading Span B, and Lagging Span based on the Donchian channel.

    Plotting:

    • Plots the Conversion Line, Base Line, Lagging Span, Leading Span A/B, and the Kumo Cloud.
    • Colors and styles the plots to make them visually distinguishable.
    • Optional plot of a long-term moving average line.

    Strategy Execution:

    • Imports the TradingView/Strategy/2 module for helper functions.
    • Defines input parameters for trade direction, date range filter, TP/SL percentages, and alert messages.

    TP/SL Calculation:

    Uses the TradingView/Strategy/2 module to convert the input TP/SL percentages to tick levels.

    Position and Trade Conditions:

    • Defines boolean variables to check the current position and trade biases.
    • Sets conditions for long and short entries based on Ichimoku Cloud criteria and the date range filter.
    • Checks for exit conditions to close existing positions if necessary.

    Strategy Execution:

    • Implements the entry and exit logic based on the defined conditions.
    • Uses the TradingView/Strategy/2 module for TradePlan exits with TP/SL percentages and alert messages.

    The strategy aims to generate buy signals when the price is above the Ichimoku Cloud and sell signals when the price is below the Ichimoku Cloud. It also considers the long-term moving average for additional confirmation. TP/SL levels can be set as a percentage of the entry price.

    Please note that this is a general explanation of the code. It's important to thoroughly understand the Ichimoku Cloud and customize the strategy according to your trading preferences and risk management.

    Copypaste code to your Tradingview Strategy Tester
    
      //@version=5
    strategy(title="PionexGPT Testing Strategy", shorttitle="PionexGPT Testing Strategy", overlay=true, initial_capital = 1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_value = 0.05)
    showBB = input.bool(false, "Show Ichimoku Cloud")
    showTrade   = input.bool(false, 'Show TP/SL')
    conversionPeriods = input.int(4, minval=1, title="Conversion Line Length")
    basePeriods = input.int(4, minval=1, title="Base Line Length")
    laggingSpan2Periods = input.int(46, minval=1, title="Leading Span B Length")
    displacement = input.int(20, minval=1, title="Lagging Span")
    donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
    conversionLine = donchian(conversionPeriods)
    baseLine = donchian(basePeriods)
    leadLine1 = math.avg(conversionLine, baseLine)
    leadLine2 = donchian(laggingSpan2Periods)
    plot(showBB ? conversionLine : na, color=#2962FF, title="Conversion Line")
    plot(showBB ? baseLine : na, color=#B71C1C, title="Base Line")
    plot(showBB ? close : na, offset = -displacement + 1, color=#43A047, title="Lagging Span")
    p1 = plot(showBB ? leadLine1 : na, offset = displacement - 1, color=#A5D6A7,
       title="Leading Span A")
    p2 = plot(showBB ? leadLine2 : na, offset = displacement - 1, color=#EF9A9A,
       title="Leading Span B")
    plot(leadLine1 > leadLine2 ? leadLine1 : leadLine2, offset = displacement - 1, title = "Kumo Cloud Upper Line", display = display.none)
    plot(leadLine1 < leadLine2 ? leadLine1 : leadLine2, offset = displacement - 1, title = "Kumo Cloud Lower Line", display = display.none)
    fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))
    
    // Add this to the existing strategy
    longest = ta.ema(close, 200)
    plot(showBB ? longest : na, color = color.yellow)
    
    
    // Strategy code begins here
    import TradingView/Strategy/2 as css
    
    //DATE RANGE FILTER {
    i_tradeDirection = input.string(title='Trade Direction', defval=strategy.direction.all, options=[strategy.direction.all, strategy.direction.long, strategy.direction.short], group='Trade Filters')
    strategy.risk.allow_entry_in(i_tradeDirection)
    i_startTime = input.time(defval=timestamp('01 Jan 2012 00:00 +0000'), title='Start Time', group='Trade Filters')
    i_endTime = input.time(defval=timestamp('01 Jan 2099 00:00 +0000'), title='End Time', group='Trade Filters')
    inDateRange = time >= i_startTime and time <= i_endTime
    //}
    //SL TP PERCENT {
    string sltp= "STOP/TAKE PROFIT"
    usetpsl     = input.bool(true, 'Use TP/SL', inline=sltp, group=sltp)
    float percentStop = input.float(1.75, "Stop %",  minval = 0.0, step = 0.25, group=sltp, inline='percent')
    float percentTP   = input.float(3.25, "Limit %", minval = 0.0, step = 0.25, group=sltp, inline='percent')
    //}
    //ALERTS {
    i_alert_txt_entry_long = input.text_area(defval = "", title = "Long Entry Message", group = "Alerts")
    i_alert_txt_entry_short = input.text_area(defval = "", title = "Short Entry Message", group = "Alerts")
    i_alert_txt_exit_long = input.text_area(defval = "", title = "Long Exit Message", group = "Alerts")
    i_alert_txt_exit_short = input.text_area(defval = "", title = "Short Exit Message", group = "Alerts")
    //}
    
    // Using the input stop/ limit percent, we can convert to ticks and use the ticks to level functions.
    // This can be used to calculate the take profit and stop levels.
    float sl = css.ticksToStopLevel (css.percentToTicks (percentStop))
    float tp = css.ticksToTpLevel   (css.percentToTicks (percentTP))
    
    exitPrice = strategy.closedtrades.exit_price(strategy.closedtrades-1)
    bias      = math.sign(strategy.position_size)
    avg       = strategy.position_avg_price
    
    // Conditions used to reference position and determine trade bias
    bool long         = strategy.position_size > 0
    bool short        = strategy.position_size < 0
    bool enterLong    = long  and not long [1]
    bool enterShort   = short and not short[1]
    bool enter        = enterLong or enterShort
    bool exit         = strategy.position_size == 0 and not (strategy.position_size == 0)[1]
    bool flat         = strategy.position_size == 0
    
    //STRATEGY PLOTS {
    avgerage    = plot(showTrade  ? avg : na, "ENTRY", not enter ? color.new(color.white, 0) : na, 2, plot.style_linebr)
    slp         = plot(showTrade  ? sl  : na, "STOP LOSS", not enter ? color.new(color.red, 60) : na, 4, plot.style_linebr)
    tpp         = plot(showTrade  ? tp  : na, "TAKE PROFIT", not enter ? color.new(color.green,   60) : na, 4, plot.style_linebr)
    
    fill(tpp, avgerage, color = color.new(color.green,   80), title='TP Background')
    fill(avgerage, slp, color = color.new(color.red, 80) , title= 'SL Background')
    //}
    
    if usetpsl == true and long
        css.exitPercent("exit long", percentStop, percentTP, alertMessage=i_alert_txt_exit_long)
    
    if usetpsl == true and short
        css.exitPercent("exit short", percentStop, percentTP, alertMessage=i_alert_txt_exit_short)
    
    
    // Strategy code begins here
    long_entry = (close > longest) and (close > leadLine1) and (close > leadLine2) and (close > conversionLine) and (close > baseLine)
    short_entry = (close < longest) and (close < leadLine1) and (close < leadLine2) and (close < conversionLine) and (close < baseLine)
    
    bool longCondition  = long_entry
    bool shortCondition = short_entry
    
    // Create entries based on the cross conditions for both trades biases.
    if longCondition and inDateRange
        strategy.close("SHORT", "SX" , alert_message=i_alert_txt_exit_short)
        strategy.entry("LONG", strategy.long, alert_message=i_alert_txt_entry_long)
    
    if shortCondition and inDateRange
        strategy.close("LONG", "LX", alert_message=i_alert_txt_exit_long)
        strategy.entry("SHORT", strategy.short, alert_message=i_alert_txt_entry_short)
    
    
    if shortCondition or (strategy.position_size > 0) and (close < leadLine1)
        strategy.close("Long", "Close Long", alert_message=i_alert_txt_exit_long)
    if longCondition or (strategy.position_size < 0) and (close > leadLine1)
        strategy.close("Short", "Close Short", alert_message=i_alert_txt_exit_short)
    
    
    


    In this script, the Ichimoku Cloud indicators are calculated using the iIchimoku function. The script checks for buy signals when the Tenkan-sen crosses above the Kijun-sen and for sell signals when the Tenkan-sen crosses below the Kijun-sen. Take profit and stop loss levels are set based on the user-defined pip values. As always, remember to thoroughly test any trading strategy in a demo environment before deploying it on a live account. Additionally, consider implementing proper risk management practices to protect your capital.

    Copy this code to your MT4 Editor

    
    //+------------------------------------------------------------------+
    //|                         IchimokuCloudStrategy                    |
    //|                       Copyright 2023, YourNameHere              |
    //|                         http://www.yourwebsite.com               |
    //+------------------------------------------------------------------+
    //| This script implements an Ichimoku Cloud trading strategy with  |
    //| take profit and stop loss levels.                               |
    //+------------------------------------------------------------------+
    extern int TenkanPeriod = 9;          // Period for Tenkan-sen
    extern int KijunPeriod = 26;          // Period for Kijun-sen
    extern int SenkouPeriod = 52;         // Period for Senkou Span B (Leading Span 2)
    extern int TakeProfitPips = 50;       // Take profit in pips
    extern int StopLossPips = 30;         // Stop loss in pips
    
    //+------------------------------------------------------------------+
    void OnStart()
    {
       double TenkanLine, KijunLine;
       ArraySetAsSeries(TenkanLine, true);
       ArraySetAsSeries(KijunLine, true);
    
       // Calculate Tenkan-sen and Kijun-sen
       if (!iIchimoku(NULL, 0, TenkanPeriod, KijunPeriod, SenkouPeriod, 1, TenkanLine, KijunLine, NULL, NULL, NULL))
       {
          Print("Error calculating Tenkan-sen and Kijun-sen!");
          return;
       }
    
       double entryPrice = 0;
       double takeProfitPrice = 0;
       double stopLossPrice = 0;
    
       // Check for a buy signal (Tenkan-sen crosses above Kijun-sen)
       if (TenkanLine[1] < KijunLine[1] && TenkanLine[0] > KijunLine[0])
       {
          entryPrice = Ask;
          takeProfitPrice = entryPrice + TakeProfitPips * Point;
          stopLossPrice = entryPrice - StopLossPips * Point;
          
          int ticket = OrderSend(Symbol(), OP_BUY, 1, entryPrice, 2, stopLossPrice, takeProfitPrice, "Ichimoku Cloud Buy", 0, clrNONE);
          if (ticket > 0)
             Print("Buy order opened at price:", entryPrice);
       }
       
       // Check for a sell signal (Tenkan-sen crosses below Kijun-sen)
       if (TenkanLine[1] > KijunLine[1] && TenkanLine[0] < KijunLine[0])
       {
          entryPrice = Bid;
          takeProfitPrice = entryPrice - TakeProfitPips * Point;
          stopLossPrice = entryPrice + StopLossPips * Point;
          
          int ticket = OrderSend(Symbol(), OP_SELL, 1, entryPrice, 2, stopLossPrice, takeProfitPrice, "Ichimoku Cloud Sell", 0, clrNONE);
          if (ticket > 0)
             Print("Sell order opened at price:", entryPrice);
       }
    }
    //+------------------------------------------------------------------+
    
    

    Posts you may Like !

    No comments

    Post Bottom Ad

    Powered by Blogger.
    email-signup-form-Image