[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] loops and lastvalue part I



PureBytes Links

Trading Reference Links

Herman
Thanks for this tutorial !!, good to know that NumToStr performs a 
selectedvalue.
about lastvalue, I agree that lastvalue ( array) in a loop must be avoid,
i asked that question because a code in cpp translated in afl does not 
returns the same results
because of lastvalue.

thanks one more time herman.

stephane

> hello stephane,
>
> Lastvalue() works on the last value of the Barindex() while Barcount 
> changes
> with QuickAFL.
>
> Also, in general I try to stay away from using array functions inside 
> loops.
> I think this is also better from the performance viewpoint. In your 
> example
> it may be better to define an array RSI14 = RSI(14) and then inside 
> the loop
> access the last value with RSI14[barcount-1]. I copy below some comments
> from TJ on this topic.
>
> best regards,
> herman
>
>
>
>
> ----------------------------------------------------------------------------
> ----
> QuickAFL & Barindex by Tomasz
>
> Herman,
> Because you probably will ask this question anyway:
> what if you really, really have to use array index operator and barindex?
> That's simple too. As you can see from the picture below actual array item
> corresponding to bar index can be found this way:
> Bar Index 0 1 2 3 4 5 6 7 8 9 10 11 12
> Array element 0 1 2 3 4 5
> bi = BarIndex();
> item = SelectedValue( bi ) - bi[ 0 ];
> Title = NumToStr(MyCustomArray[ item ] ,1.2);
> Best regards,
> Tomasz Janeczko
> amibroker.com
> Herman,
> Short story:
> Your code does NOT really need index addressing, setbarsrequired, barindex
> at all.
> Somehow you managed to complicate thing when it is very, very simple 
> and can
> be coded in 2 lines:
> MyCustomArray = EMA(C,3);
> Title = "NumberFromMyCustomIndicator ="+NumToStr(MyCustomArray ,1.2);
> Long story:
> Take a look at picture below:
> Bar Index 0 1 2 3 4 5 6 7 8 9 10 11 12
> Array element 0 1 2 3 4 5
>
> You see: Bar index represents ENTIRE data set you have.
> Array may be actually smaller than your entire data set (if visible 
> area for
> indicator is small) and
> may have LESS elements than entire data set you have.
> Array in indicator builder when QuickAFL is on may include only 
> visible part
> (plus some extra bars).
> Now selected bar is shown with red color. As you can see although it has a
> bar index of 8,
> the actual array element has the number of 4.
> That's why you can not use barindex to address your arrays directly.
> Instead use SelectedValue directly on array, by simply typing:
> MyCustomArray = EMA(C,3);
> NumberFromMyCustomIndicator = SelectedValue( MyCustomArray );
> It is way simpler than your code and works always and you do not need to
> bother about quickafl and setbarsrequired at all.
> In fact NumToStr already performs "selected value" so you code can be
> simplified to 2 lines:
> MyCustomArray = EMA(C,3);
> Title = "NumberFromMyCustomIndicator ="+NumToStr(MyCustomArray ,1.2);
> It performs as you wanted it to perfom and takes 2 lines instead of 5.
> It is all actually simpler than you think.
> Best regards,
> Tomasz Janeczko
> amibroker.com
>
>
>
> ----------------------------------------------------------------------------
> ----
>
>
>
>
> -----Original Message-----
> From: Stephane Carrasset [mailto:s.carrasset@xxxxxxxxxxx]
> Sent: Wednesday, September 15, 2004 12:53 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] loops and lastvalue part I
>
>
> Hello all,
> that's many times that I ask me if the usage of lastvalue in a loop
> returns expected results, as lastvalue returns the scalar value of
> the last bar of an array and can be used in a loop.
> the example below confirms, I suppose, that we must take care of
> lastvalue in a loop.
> I think I am right?
>
> Stephane
>
>
> myMFI = MFI( 14 );
> myRSI=RSI(14);
> average=averageLV=0;
> for( i = 0 ; i < BarCount; i++ )
> {
> if(  myMFI[i] > myRsi[i] )
> average ++;
> if(  myMFI[i] > LastValue(RSI(14)) )
> averageLV ++;
>
> result[i]=average;
> resultLV[i]=averageLV;
> }
>
> Plot(result,"",2,1);
> Plot(resultLV,"",3,1);
>
>
>
> Check AmiBroker web page at:
> http://www.amibroker.com/
>
> Check group FAQ at:
> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
>
> Yahoo! Groups Sponsor
> ADVERTISEMENT
>
>
>
>
>
>
> Yahoo! Groups Links
>
> To visit your group on the web, go to:
> http://groups.yahoo.com/group/amibroker/
>
> To unsubscribe from this group, send an email to:
> amibroker-unsubscribe@xxxxxxxxxxxxxxx
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>
> [Non-text portions of this message have been removed]
>
>
>
> Check AmiBroker web page at:
> http://www.amibroker.com/
>
> Check group FAQ at: 
> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
>
> *Yahoo! Groups Sponsor*
> ADVERTISEMENT
> click here 
> <http://us.ard.yahoo.com/SIG=129gf0deh/M=295196.4901138.6071305.3001176/D=groups/S=1705632198:HM/EXP=1095354927/A=2128215/R=0/SIG=10se96mf6/*http://companion.yahoo.com> 
>
>
>
> ------------------------------------------------------------------------
> *Yahoo! Groups Links*
>
>     * To visit your group on the web, go to:
>       http://groups.yahoo.com/group/amibroker/
>        
>     * To unsubscribe from this group, send an email to:
>       amibroker-unsubscribe@xxxxxxxxxxxxxxx
>       <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
>        
>     * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>       Service <http://docs.yahoo.com/info/terms/>.
>
>
>
>
> __________ NOD32 1.869 (20040913) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.nod32.com




[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/