Hello Brian, I think, I have a case for using looping where current bar value of a variable is calculated using the previous bar value of that same variable.
For instance ; OSarray[current bar] = Alpha * Close[current bar] + (1 + Alpha) * OSarray[previous bar]; Can you please help me out with an example which illustrates this scenario? Is this a case for using "for" loop? Kind Regards Richard --- In [email protected], "brian_z111" <brian_z...@...> wrote: > > Rich, > > Having fun with HTML character code/WordPress conflict. > > I added a text file near the top of the post "CurrentPivots". > > I will upload AFL (text files) for the other examples later this > weekend. > > Right click >> SaveAs or left click to view. > > Download files courtesy of Richard Dale, Norgate Investor Services > who offered to host for free so that I don't have to display adds > with the downloads. > > Cheers, > > Brian. > > --- In [email protected], "richpach2" <richpach2@> wrote: > > > > Hello Brian, > > > > This is fantastic. I like the idea of counting bars since last > pivot. > > All examples however have small errors (missing operators) and do > not > > compile. Do you mind qualifying these lines; > > > > MPK = PKV2 PKV0 ;//MajorPeak > > > > and > > > > TR = ROC(C,1) 0 ;//TroughRight > > > > > > Regards > > Richard > > > > > > --- In [email protected], "brian_z111" <brian_z111@> wrote: > > > > > > Hello Rich, > > > > > > I have done this using variations of the code at the bottom of > the > > > Pivots post (not so called 'Pivots' at the top which are really > > > volatility bands). > > > > > > I have quantified ROC(pivots) and identified serial pivots using > > > Valuewhen(Pivot,1) etc.... that was a while ago ... the memory > fades. > > > > > > Note this version is sophisticated enought to 'count'bars with == > > > lows or highs but I have also used simpler versions with only > three > > > bars that have differential H or L. > > > > > > > > > > > > http://zboard.wordpress.com/ > > > > > > > > > > > > > > > --- In [email protected], "richpach2" <richpach2@> wrote: > > > > > > > > G'Day Graham, > > > > > > > > Thank you for your comprehensive reply. All the rules you have > > > listed > > > > seem logical as a statement. I learn by example so, I need to > > > analyze > > > > a few examples to gain a better understanding of looping > functions. > > > > > > > > I am trying to write a code which will detect first higher low > > > trough > > > > after a downtrend move which can be defined as two lower low > troughs > > > > and two lower low peaks. I am not sure if Zig function is best > to do > > > > that. Should I consider loops for this or use existing Zig > function. > > > > I could not locate anything in the library of similar nature > so, I > > > can > > > > use is as an example of such a trend detection pattern. > > > > Are you aware of any existing AFLs which addresses this or > similar > > > > pattern detection? > > > > > > > > Kind Regards > > > > Richard > > > > > > > > --- In [email protected], Graham <kavemanperth@> wrote: > > > > > > > > > > As a general rule I use loops when > > > > > > > > > > 1. Existing AB functions cannot fulfil requirements. > > > > > eg use of AMA, Zig, Cum, or ApplyStop functions, or one > of > > > the > > > > > many others available > > > > > > > > > > 2. The current bar value of a variable is calculated using the > > > > > previous bar value of that same variable. > > > > > eg EMA if that was not already a built in function in > AB > > > > > > > > > > 3. The value of a variable is determined from a specific > > > occurrence of > > > > > a true condition, where that condition can have true values > after > > > that > > > > > specific occurrence. > > > > > eg trail stop value after Buy signal, that is not one > of > > > the > > > > > existing ApplyStop function possibilities. > > > > > This could be one that if could write simply would > be > > > > > HighestSince( Buy, H - ATR( 10 ) ), but this gets reset by any > > > > > subsequent buy signals that you may not want to remove > > > > > AB Applystop (ModePoint) currently has 2 > possibilities > > > if > > > > > my memory is correct, they are > > > > > A: Non-Volatile HighestSince( Buy, H ) - > ValueWhen > > > ( > > > > > buy, ATR( 10 ) ); and > > > > > B: Volatile HighestSince( Buy, H ) - ATR > ( > > > 10 ); > > > > > These bits of code would vary if you have a entry > delay > > > > after signal. > > > > > > > > > > 4. Loop through a set number series that have no direct > relation > > > to > > > > > bar array identification as normally used in bar loops > > > > > eg for( n=1; n<=5; n=n+2 ) > > > > > > > > > > 5. Probably some others as well, but have written so many > cannot > > > > > always remember everything. > > > > > > > > > > Hopefully my examples of code above are correct, I just typed > them > > > > > into here from my poor memory > > > > > > > > > > -- > > > > > Cheers > > > > > Graham Kav > > > > > AFL Writing Service > > > > > http://www.aflwriting.com > > > > > > > > > > > > > > > > > > > > 2009/2/20 richpach2 <richpach2@>: > > > > > > Hello, > > > > > > > > > > > > Can some please expain use of loop (if, while etc) > expression > > > in AFL? > > > > > > When do one need to use a loop and when can one just rely on > > > > > > processing of the array bar-by-bar. I am still learining > AFL > > > language > > > > > > and this area is a bit grey. > > > > > > > > > > > > I noticed many Stop processing AFL use "for" loop but I > don't > > > > > > understand why. > > > > > > Also, if I can use this statement toi define EMA; > > > > > > > > > > > > P = ParamField("Price field",-1); > > > > > > Periods = Param("Periods", 15, 2, 300, 1, 10 ); > > > > > > Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor > ( "Color", > > > > > > colorCycle ), ParamStyle("Style") ); > > > > > > > > > > > > why would I try this AFL doc example; > > > > > > > > > > > > myema[ 0 ] = Close[ 0 ]; > > > > > > for( i = 1; i < BarCount; i++ ) > > > > > > { > > > > > > myema[ i ] = 0.1 * Close[ i ] + 0.9 * myema[ i - 1 ]; > > > > > > } > > > > > > This example iterates all bars of close array to calculate > > > > > > exponential moving average. > > > > > > > > > > > > Regards > > > > > > Richard > > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------ > > > > > > > > > > > > **** IMPORTANT PLEASE READ **** > > > > > > This group is for the discussion between users only. > > > > > > This is *NOT* technical support channel. > > > > > > > > > > > > TO GET TECHNICAL SUPPORT send an e-mail directly to > > > > > > SUPPORT {at} amibroker.com > > > > > > > > > > > > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at > > > > > > http://www.amibroker.com/feedback/ > > > > > > (submissions sent via other channels won't be considered) > > > > > > > > > > > > For NEW RELEASE ANNOUNCEMENTS and other news always check > > > DEVLOG: > > > > > > http://www.amibroker.com/devlog/ > > > > > > > > > > > > Yahoo! Groups Links > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
