Value not going lower

I'm trying to plot a line, based initially of the lowest low
however, i dont want the low to get lower, i only want it going higher, until the close closes below this value
I've tried an IIF..

Mylow = LLV(Low,10);
newlow = iIf(mylow<Ref(mylow,-1),Ref(mylow,-1),mylow);

however that still lets the low get lower

I've tried looking at while statements (close>mylow) and inserting this if..however i get a message saying it needs to be boolean. in fairness i just cannot get my head around while statements

could somebody help
am i barking up the wrong tree with iif and could somebody help writing this as a while statement?

very much appreciated for any pointers

ll1 = LLV(Low,10);
hll = Highest(ll1);
ll2 = IIf(C > hll, hll, Null);
// or alternative to keep break value:
//ll2 = ValueWhen(C > hll, hll);
Plot( C, "Price", colorDefault, styleBar );
//Plot( ll1, "ll", colorRed );
Plot( ll2, "hll", colorOrange );

10

2 Likes

Perfect, thank you fxshrat
the answer always appears so obvious when its there in front of you

Here is a 2nd version, being a bit different.

function HighestLLV(LLV_array, Cross_array, period) {
	/// highest LLV (stopping if crossed)
	/// @link https://forum.amibroker.com/t/value-not-going-lower/17927/4
	ll1 = LLV(LLV_array,period);
	cond1 = ll1 > Ref(ll1,-1);
	ll2 = HighestSince(cond1, ll1);
	prev_ll2 = Ref(ll2,-1);
	cond2 = ll2 != ValueWhen(Cross(prev_ll2,Cross_array), prev_ll2);
	result = IIf(cond2, ll2, Null);
	return result;
}

period = 10;
hllv = HighestLLV(L, C, period);

Plot( C, "Price", colorDefault, styleBar );
Plot(hllv, "hllv", colorOrange, styleStaircase );
//Plot(LLV(L,period), "llv", colorRed, styleStaircase );

12

for some reason it doesn't like that function at the beginning
unexpected synatax it says..is there a line missing?

No, it works just fine (please see picture). I never post code with syntax error.

If you get error in first line then you might have a DLL function by name HighestLLV().
So modify function name to fxHighestLLV two times in the code.
Also if you copy code then rather use copy button above of the code on right top side.

Other than that it would be more helpful if you would post exact error and with picture, please. (Also which AB version).

I do apologise fxshrat, didn't mean to offend
and i appreciate your response
there wasn't a syntax, it was a fat fingered user error

I wasn't offended.

Here is a better 2nd version using SumSince() and Flip() instead of cond2 of previous 2nd version.
Also renamed function to RisingLLV().

function RisingLLV(LLV_array, cross_array, period) {
	/// rising LLV (stopping if crossed by cross_array)
	/// @link https://forum.amibroker.com/t/value-not-going-lower/17927/8
	local ll1, ll2, cond1, crss, first_cross, flip_cond, result;
	ll1 = LLV(LLV_array,period);
	cond1 = ll1 > Ref(ll1,-1);
	ll2 = HighestSince(cond1, ll1);
	crss = Cross(Ref(ll2,-1), cross_array);
	first_cross = SumSince(cond1, crss) == 1;
	flip_cond = Flip(cond1, first_cross);
	result = IIf(flip_cond, ll2, Null);
	return result;
}

//SetBarsRequired(1000);

period = 10;
hllv = RisingLLV(L, C, period);

Plot( C, "Price", colorDefault, styleBar );
Plot(hllv, "hllv", colorOrange, styleStaircase );
//Plot(LLV(L,period), "llv", colorRed, styleStaircase );
4 Likes