I think its still not right. Maybe i describle not clearly. So i write Amibroker code:
FractalUp = ValueWhen(Ref(C,-2)==HHV(C,5) ,Ref(C,-2) ,1);
FractalDown=ValueWhen(Ref(C,-2)==LLV(C,5), Ref(C,-2), 1);
Buy = Cross(C,fractalup) AND C>=EMA(C,20);
Sell = Cross(fractaldown,C) AND C<=EMA(C,20);
/*
ValueWhen(EXPRESSION, ARRAY, n = 1): Returns the value of the ARRAY when the EXPRESSION was true on the n -th most recent occurrence. Note: this function allows also 0 and negative values for n - this enables referencing future
HHV( ARRAY, periods ): example the formula "hhv( close, 4)" returns the highest closing price over the preceding four periods; "hhv( high, 8)" returns the highest high price over the preceding eight periods.
LLV( ARRAY, periods ): example the formula "LLV( close, 14 )" returns the lowest closing price over the preceding 14 periods.
*/
Can you repair the code again?
Many thanks!