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:
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.
Check out this related content for more information:
https://www.prorealcode.com/topic/support-et-resistance-avec-ichimoku/#post-148628
Visit Link