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

Re: [amibroker] Re: Brain fried, How do I plot a zero line on my MACD



PureBytes Links

Trading Reference Links



Bruce,

Thanks for the comments.  I load 200,000 bars in my program, then use SetBarsRequired( DesiredHistory, 0 ) to speed up operation to just the bars I need at the time for my purposes.  When running realtime trading, I set my history to 5,000 to 10,000 bars to get all my calculations needed (5 to 10 days).  When setting parameters, I will use all 200,000 bars in a backtest equity mode in my indicators.  I switch back and forth many times during the day while developing systems (even while trading realtime -- in quiet periods).

In real time mode, depending on the system I am running, It can take seconds to run each update.  I can run up to 8 systems at the same time into one combined system for trading (when long and short are considered).  A second is a long time when you are trading one minute bars in a position that may only last 4 minutes on average.  I also use on chart buttons which really bog down when the refresh rate goes over a half second, so I obviously want fast executions.  

In backtest mode, I shut down all nonessential calculations and plots for normal refreshes, so I can change parameters, and only trigger a full calculation cycle with essential plots on command.  The quick mode is about 5-7 seconds, and the full cycle is about 20-30 seconds.

Now, here is the problem I face.  If I allow quick AFL mode, then it usually thinks it needs more bars than it does and runs slower.  With SBR it is better, but it is not so good in one respect.  If I just once increase my bars for a quick test, the SBR will never allow me to reduce them back to the lower number again without restarting the chart.  I usually restart the chart by applying a sham edit to the main chart AFL.  My loops will of course only use the number bars requested, so they behave well.  The number of bars used by AFL array operations is a peak detecting function.  If anything ever needs more bars (ATC for instance), then you are stuck with that minimum number forever.  That was a reason I could not use ATC operations before, and am glad to have the static array variables now.

I have complained about this BAD (for me) behavior many times, but so far it seems to have fallen on deaf ears.  Perhaps, I am the only one who notices or cares about this.  If this behavior were fixed so that SBR actually just took the number specified, or had a force mode to cause this to truly set the bars required, even if smaller than the last pass, then I would use more array operations in my AFL, and perhaps gain a speed advantage in the process.

BR,
Dennis


On Jun 28, 2009, at 1:00 PM, bruce1r wrote:



Dennis, all -

If you hadn't asked if you weren't missing something, I probably wouldn't post.  This is similar to something that Herman and I discussed a week or so back.  See those posts, but, IMO, your conclusion about looping is incorrect, and hey, I'll do anything to avoid yard work.

You said - "It seems like a waist of time to create an array of the Min/Max over that range for all bars, then just use the last value. I use loops when I only want a single number result related to the Min/Max value over the last n bars only (like the visible bar range). Am I missing an opportunity to approach this in a more efficient way?"

Let me try to state the bottom line succinctly -

Everyone will most likely eventually run into performance considerations in some application, sooner or later.  And, array logic will almost always be significantly faster than looping.  Eliminating loops is a good guideline for performance optimization.&nb sp; Plus, if you pay attention to QuickAFL, then speed can be maximized.

Tomasz has highly tuned array calculations.  Unless you are running them over many 10000's of bars, running over all data will probably out-perform even looping over only visible data - even if you only need the last bar.  If you want to consider only visible data and some number of bars, "N", before the first bar that are used to "stabilize" the calculation of indicators, then performance can be maximized.   Left on its own QuickAFL will conservatively over-estimate the number of bars required as Tomasz has explain in the KB.

If you understand the bar requirements, it is generally better to take control of QuickAFL and limit the all function calculations to "N" bars plus the visible bars.  This is done with -

SetBarsRequired( N, 0 );

The bottom line is that if you do this, array calculations of MACD in your example will outperform looping on visible bars by an order of magnitude or more.  And, all other calculations will be sped up considerably also.

-- BruceR



--- In amibroker@xxxxxxxxxxxxxxx, Dennis Brown <see3d@xxx> wrote:
>
> Maybe not...
> 
> Through this discussion, the problem has been reduced to aligning the 
> min/max range of a MACD styleOwnScale plot to another zero line 
> styleOwnScale plot statement. Therefore, the only way to do this is 
> to find the min/max values of the MACD function in the visible bars 
> range and use those numbers in both plot statements, or make the MACD 
> range symmetrical and then the zero line statement can be any 
> symmetrical range.
> 
> I am happy with my dual colored plot line at this point. However, to 
> complete the original idea, I could use a simple loop to find the min/ 
> max numbers of the MACD, but I am now wondering if the re is a "faster" 
> execution way using array logic instead?
> 
> It seems like a waist of time to create an array of the Min/Max over 
> that range for all bars, then just use the last value. I use loops 
> when I only want a single number result related to the Min/Max value 
> over the last n bars only (like the visible bar range). Am I missing 
> an opportunity to approach this in a more efficient way?
> 
> BR,
> Dennis
> 
> 
> On Jun 27, 2009, at 9:06 AM, gmorlosky wrote:
> 
> > maybe....
> >
> > IF ( MACDline == Signalline) // histogram value equals zero
> > X = lastvalue(MACDline-Signalline);
> > Plot (X,"", colorblack);
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, Dennis Brown see3d@ wrote:
> >>
> >> Yes, I have it set to 100%. The absolute values of the indicator 
> >> will
> ; >> vary wildly, depending on the price and volatility of the stock. I
> >> plot ES, so the values are quite large at times.
> >>
> >> BR,
> >> Dennis
> >>
> >> On Jun 26, 2009, at 5:58 PM, monitorit wrote:
> >>
> >>> If that's all you needed, the color change would be best. But, I
> >>> think the solution I suggested would work... you would still plot/
> >>> see value very high or low just within a section defined by pane*1/
> >>> minvalue [at least it has for me]. BTW, presently what is the upper
> >>> and lower bounds of the MACD in relationship to the height of the
> >>> pane? Is it 100% of the pane height?
> >>> Dan
> >>>
> >>> --- In amibroker@xxxxxxxxxxxxxxx, Dennis Brown <see3d@> wrote:
> >>>>
> >>>> ; Dan,
> >>>>
> >>>> This is what I usually do for indicators when I know the range of
> >>>> values. However, MACD is an unbounded indicator, so I don't know 
> >>>> how
> >>>> large the values are. It is only the zero crossings and relative
> >>>> peaks that are useful info here.
> >>>>
> >>>> I just thought there would be some simple shortcut to actually
> >>>> scanning the visible bars for the min/max values to use in the plot
> >>>> statements. I think I will just switch colors of the MACD from red
> >>>> to
> >>>> green if it is above or below zero instead of resorting to yet
> >>>> another
> >>>> loop.
> >>>>
> >>>> Thanks,
> >>>> Dennis
> >>>>< br>> >>>>
> >>>> On Jun 26, 2009, at 4:40 PM, monitorit wrote:
> >>>>
> >>>>> Dennis,
> >>>>> Hi. You might try this- Place a value in minvalue section but 
> >>>>> none
> >>>>> in maxvalue section [I think maybe a value like 2 equates to 1/2
> >>>>> pane height] of your MACD and zero plot statements.
> >>>>> Also,styleNoRescale in the zero plot statement. This worked for 
> >>>>> me
> >>>>> when I wanted to plot a histogram and a dot on the top of the
> >>>>> histogram. Not sure if it works with a line. If it doesn't, you
> >>>>> could try plotohlc with H=max(0,my#) and L=min(0,my#).
> >>>>>
> >>>>> Dan
> >>>>>
> >>>>> --- In ami broker@xxxxxxxxxxxxxxx, Dennis Brown <see3d@> wrote:
> >>>>>>
> >>>>>> Hello,
> >>>>>>
> >>>>>> This must be simple, but my AFL brain is fried today. I have an
> >>>>>> MACD
> >>>>>> plot on top of my main price chart, and I want to plot a zero 
> >>>>>> line
> >>>>>> over it. It is plotted as StyleOwnScale of course. I can't use
> >>>>>> StyleLeftAxis because I am using it for something else. I 
> >>>>>> guess I
> >>>>>> could do something to figure out where the visible high and low
> >>>>>> values
> >>>>>> of the MACD are, but it seems like it should be easier than that.
> >>>>>>
> >>>>>> TIA,
> > >>>>> Dennis
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> ------------------------------------
> >>>>>
> >>>>> **** 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 ANN OUNCEMENTS and other news always check DEVLOG:
> >>>>> http://www.amibroker.com/devlog/
> >>>>>
> >>>>> Yahoo! Groups Links
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>
> >>>
> >>>
> >>>
> >>> ------------------------------------
> >>>
> >>> **** 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 oth er channels won't be considered)
> >>>
> >>> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> >>> http://www.amibroker.com/devlog/
> >>>
> >>> Yahoo! Groups Links
> >>>
> >>>
> >>>
> >>
> >
> >
> >
> >
> > ------------------------------------
> >
> > **** 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 a nd other news always check DEVLOG:
> > http://www.amibroker.com/devlog/
> >
> > Yahoo! Groups Links
> >
> >
> >
>





__._,_.___


**** 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/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___