Implementing Ichimoku-Based Support and Resistance Checks in Trading Strategy

30 Jun 2020
0 comment
0 attachment

This code snippet demonstrates how to integrate Ichimoku Cloud indicators as support and resistance levels in a trading strategy to control order execution based on proximity to these levels. The strategy allows trading only if the price is sufficiently distant from the nearest support or resistance level, defined by the Ichimoku Cloud.

defparam cumulateorders=false
// — settings
distance = 15 //no orders if there is a SR within X points
lookback = 1000 //lookback in bars to check recent SR
tp = 30 //takeprofit in points
sl = 10 //stoploss in points
// ———————————-
// — ichimoku support and resistance
kijun = (highest[26](high)+lowest[26](low))/2
SSB = (highest[52](high[26])+lowest[52](low[26]))/2
kijunp = summation[9](Kijun=Kijun[1])=9
ssbp = summation[9](SSB=SSB[1])=9
if kijunp then kijunPrice = kijun
if ssbp then ssbPrice = SSB
if kijunprice=ssbprice then SRlevel = kijunprice
// ———————————-
// — dummy strategy
buycondition = rsi[14] crosses over 50
sellcondition = rsi[14] crosses under 50
if buycondition or sellcondition then
//check if the current price is distant from at least “distance” from recent support or resistance
allowtrading=1
for i = 0 to lookback-1 do
dist = abs(close-srlevel[i])<distance*pointsize
if dist then
allowtrading=0 //no trading is allowed we are near a SR!
break //break the loop, no need to continue, trading is not allowed anymore!
endif
next
//trigger orders or not
if allowtrading then
if buycondition then buy 1 contract at market
if sellcondition then sellshort 1 contract at market
endif
endif
set target pprofit tp
set stop ploss sl
endif
// ———————————-
graph allowtrading as “0=near a SR , don’t trade!”

The code is structured as follows:

  • Settings: Defines the parameters like distance from support/resistance, lookback period, take profit, and stop loss.
  • Ichimoku Calculation: Calculates the Kijun and Senkou Span B (SSB) lines of the Ichimoku Cloud, which are used to determine support and resistance levels.
  • Trading Conditions: Uses the RSI indicator to define buy and sell conditions.
  • Proximity Check: Before executing any trade, the script checks if the current price is at least the specified ‘distance’ away from the nearest support or resistance level. If it is too close, trading is not allowed.
  • Order Execution: If the conditions are met and the price is sufficiently distant from support/resistance levels, the script executes the trade.
  • Graph Output: Displays a graph indicating whether trading is allowed or not based on the proximity to support/resistance.

This example provides a practical application of Ichimoku Cloud indicators in automated trading strategies, focusing on risk management by avoiding trades near key technical levels.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/support-et-resistance-avec-ichimoku/#post-148628

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...