Unable to Find Issue with ValueWhen

Hi,

I am just trying to find the value of Low when BarIndex is say some value.

In the below code, am not getting any value for ValueWhen(bo1probable == BarIndex(),L)

Thought will seek some help from the forum. Plz suggest. Thannks

_SECTION_BEGIN("PATTERNS");


dn = Day();
BI = BarIndex();
tn = TimeNum();
StartTime = 091500; 
EndTime   = 092500; 
StartBar = tn == StartTime; 
EndBar = tn == Endtime; 
newDay = dn != Ref( dn, -1 ); 

strength = abs((Open-Close)/(High-Low));
strengthCandle = IIf(strength>0.5,True,False);

bo1probable = ValueWhen(strengthCandle AND (C > O), BarIndex(),2);
bo2probable = ValueWhen(strengthCandle AND (C > O), BarIndex(),1);
bo12 = IIf(ValueWhen(BI == bo1probable,L) <= LowestSince(BI == bo1probable,L),True, false);

PlotShapes(IIf(bo12, shapeUpTriangle, shapeNone), colorViolet); 

Filter = 1;

AddColumn(BI, "BI");
AddColumn(strengthCandle, "strengthCandle");
AddColumn(bo1probable, "bo1probableVal");
AddColumn(ValueWhen(bo1probable == BarIndex(),L), "BO1", 1.2);
AddColumn(bo2probable, "bo2probableVal");
AddColumn(ValueWhen(BarIndex() == bo2probable,L), "BO2", 1.2);
AddColumn(bo12, "bo12");


_SECTION_END();

Change to:

ValueWhen(bo1probable, L)

HI, This didnt help. Adding more info with a picture.

DoubtABForum

There is no issue with ValueWhen(). You're not getting any value because the condition does not comply with your expectation.

You might want to refer to ValueWhen - how to use.

Could you please state your intention clearly in words to what exactly you mean by this (especially assignment of bo12 in the last line):

1 Like

In addition to what @Cougar said, if you are trying to get the Low price of a particular condition (which looks like you are trying to get the Low price from 'bo2probable' ??? then use 'ValueWhen' to return the Low price rather than the BarIndex().

1 Like

Hi, Thx

What I am trying to achieve is this.

First. I am finding the recent candle which satisfy the condition abs((Open-Close)/(High-Low)) > 0.5. I get the BarIndex meeting the criteria. ( That is bo1probable)

Secondly, I am trying to find the candle prior to the first identified candle meeting the above condition. (2nd recent) . I get the BarIndex meeting the criteria. ( That is bo2probable)

Third, I want to get the Low Values from either candles and check if the low of the candle identified first is not breached by any candles between first and the second on the lower side. I use the Valuewhen to find the low of the candles identified in Step 1 and 2.

Hope I understood your logic correctly:

BI = BarIndex();

// First. I am finding the recent candle which satisfy the condition abs((Open-Close)/(High-Low)) > 0.5
Cond = abs( ( O - C ) / ( H - L ) ) > 0.5;

// I get the BarIndex meeting the criteria
CondThisBI = ValueWhen( Cond, BI );
// Secondly, I am trying to find the candle prior to the first identified candle meeting the above condition. (2nd recent) . I get the BarIndex meeting the criteria
CondPrevBI = ValueWhen( Cond, BI, 2 );

// Third, I want to get the Low Values from either candles
CondThisBiLow = ValueWhen( Cond, L );					CondPrevBiLow = ValueWhen( Cond, L, 2 );

// and check if the low of the candle identified first is not breached by any candles between first and the second on the lower side
LwstLowSncePrevCond = LowestSince( Cond, L, 2 );		CondThisBiLowChkr = CondThisBiLow <= LwstLowSncePrevCond;

Filter = 1;
AddColumn( BI, "BI", 1.0 );
AddColumn( L, "Low", 1.2 );

AddColumn( Cond, "Cond", 1.0 );

AddColumn( CondThisBI, "Cond ThisBI", 1.0 );								AddColumn( CondPrevBI, "Cond PreviousBI", 1.0 );
AddColumn( CondThisBiLow, "Cond ThisBi Low", 1.2 );							AddColumn( CondPrevBiLow, "Cond PrevBi Low", 1.2 );
AddColumn( LwstLowSncePrevCond, "Lowest Low since prev Cond", 1.2 );		AddColumn( CondThisBiLowChkr, "Cond ThisBi LowChkr", 1.0 );
5 Likes