This is my first message on the forum. I wish I had bought Amibroker a long time ago! Incredible the quality and versatility of this software!
I am a novice at AFL and I am trying to learn how to develop my custom indicators and strategies. I am trying to develop a very simple indicator, but I am having problems with it.
The rules of the indicator are very simple:
If the Close of this bar is equal the highest close of 20 bars ago the value of the indicator is 1.
If the Close of this bar is equal the lowest close of 20 bars ago the value of the indicator is -1.
As you can see I am trying to create a flag. That way the value of the indicator always has to be 1 or -1 and should keep and show the value of the indicator the last time that hit the upper band or the lower band.
I have tried with the next code, but unfortunately it does not work:
Valor = IIf(Close == HHV (Close,20), 1 , IIf(Close == LLV (Close,20), -1 , 0)); // Here the problem is that it shows the 0 value when it should show 1 or -1.
Plot( Valor, "Flag Indicator", colorWhite );
Perhaps is there a simple way of solving this problem? Any help would be very appreciate. Thank you!
simply calls Flip function with initial values of cond1, cond2 (arrays - so ALL bars are processed at once) and assigns result of Flip function BACK to cond1 variable OVERWRITING all previous values.
No, cond1 and cond2 get overwritten over the full size of the arrays (each bar gets overwritten with new element(s). So there are not arrays but there is/are element(s) of array(s) on each bar).
As you can see in the code after first assigments to cond1 and cond2 there are two immediate plot function calls to output those first two array variables (cond1 and cond2). AFL code execution is from top to bottom of what you see in editor. That's why first you see separate plot of cond1 and cond2 and then at the end there is a 3rd plot but this time plotting is based on new assignments of cond1 and cond2 after first two plots.
If you would place the first two plot lines after the two new assignments of cond1 and cond2 then those two plots would be differently.