How to check if price is inbetween the range

I am playing with the Ichumoku cloud and want to check if my price is inbetween the cloud.
for eg. in the code segment below, i want to check if the price bar is between cloudHigh and cloudLow.
cloudHigh = Max( SenkouA_values, SenkouB_values );
cloudLow = Min( SenkouA_values, SenkouB_values );

Appreciate any help.

SetOption( "MaxOpenPositions", 5 ); // This sets maximum number of open positions to 5


SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
//https://www.raoufx.com/trading%20with%20ichimoku%20clouds%20the%20essential%20guide%20to%20ichimoku%20kinko%20hyo%20technical%20analysis.pdf
Plot( C, "Close", colorDefault, styleNoTitle | GetPriceStyle() );
_SECTION_BEGIN( "Tenkan-Sen" );
TenkanPer = Param( "Tenkan-Sen Period", 9, 1, 100, 1 );
TenkanCol = ParamColor( "Tenkan-Sen Color", colorRed );
TenkanSty = ParamStyle( "Tenkan-Sen Style", styleLine | styleThick );
Tenkan = ( HHV( H, TenkanPer ) + LLV( L, TenkanPer ) ) / 2;
Plot( Tenkan, "Tenkan", TenkanCol, TenkanSty );
_SECTION_END();

_SECTION_BEGIN( "Kijun-Sen" );
KijunPer = Param( "Kijun-Sen Period", 22, 1, 100, 1 ); // using 22 instead of 26 as there are only 22 trading days in a month.
KijunCol = ParamColor( "Kijun-Sen Color", colorBlue );
KijunSty = ParamStyle( "Kijun-Sen Style", styleLine | styleThick );
Kijun = ( HHV( H, KijunPer ) + LLV( L, KijunPer ) ) / 2;
Plot( Kijun, "Kijun", KijunCol, KijunSty );
_SECTION_END();

_SECTION_BEGIN( "Chikou Span" );
ChikouShft = Param( "Chikou Span Shift", 22, 1, 100, 1 ); // using 22 instead of 26 as there are only 22 trading days in a month.
ChikouCol = ParamColor( "Chikou Span Color", colorViolet );
ChikouSty = ParamStyle( "Chikou Span Style", styleLine | styleNoLabel );
Chikou = C;
Plot( Chikou, "", ChikouCol, ChikouSty, Null, Null, -ChikouShft );
_SECTION_END();

_SECTION_BEGIN( "Senkou-Kumo" );
SenkouKumoShft = Param( "Senkou-Kumo Shift", 21, 0, 100, 1 );
_SECTION_END();

_SECTION_BEGIN( "Senkou Span A" );
SenkouACol = ParamColor( "Senkou Span A Color", colorSeaGreen );
SenkouASty = ParamStyle( "Senkou Span A Style", styleLine );
SenkouA = ( Tenkan + Kijun ) / 2;
Plot( SenkouA, "Senkou A", SenkouACol, SenkouASty, Null, Null, SenkouKumoShft ) ;
_SECTION_END();

_SECTION_BEGIN( "Senkou Span B" );
SenkouBPer = Param( "Senkou Span B Period", 42, 1, 200, 1 );
SenkouBCol = ParamColor( "Senkou Span B Color", colorPink );
SenkouBSty = ParamStyle( "Senkou Span B Style", styleLine );
SenkouB = ( HHV( H, SenkouBPer ) + LLV( L, SenkouBPer ) ) / 2;
Plot( SenkouB, "Senkou B", SenkouBCol, SenkouBSty, Null, Null, SenkouKumoShft ) ;
_SECTION_END();

_SECTION_BEGIN( "Kumo" );
KumoUpCol = ParamColor( "Kumo UP Color", colorSeaGreen );
KumoDnCol = ParamColor( "Kumo DN Color", colorPink );
PlotOHLC( SenkouA, SenkouA, SenkouB, SenkouB, "", IIf( SenkouA > SenkouB, KumoUpCol, KumoDnCol ), styleCloud | styleNoLabel, Null, Null, SenkouKumoShft );
_SECTION_END();
cloudHigh = Max( SenkouA_values, SenkouB_values );
cloudLow = Min( SenkouA_values, SenkouB_values );

if you have reached till here, why cant you just compare the H and L of the bar:

TopIn = IIf( cloudHigh > H, 1, 0);
BotIn = IIf( L > cloudLow , 1, 0);

You can even Reference older bars and check the condition as you like.

1 Like

i had a brain freeze. thank you for your help

For what it's worth, you can simplify the code a bit, like this:

TopIn = H < cloudHigh;
BotIn = L > cloudLow;
2 Likes

If it was my code it would be the same way :smile: or even skipped the two variables and used directly.
I nest multiple statements in one liners but sometimes code readability is hampered.

For explanation purpose and the thread starters "ah ha" moment, it help in readability and understand the other many possibilities.
He can return other states instead of 1 and 0 as well.

Anyway, shorter format accepted.