TJ --
Thank you for Explicitly saying, "There is NO difference what is on the left side . It does not matter if expression includes same variable as on right side. The entire (right-side) expression is FIRST EVALUATED COMPLETELY (all bars at once) and AFTER that resulting ARRAY is assigned."

I have read the link many many times, and in fact have recommended that others read it over and over again. Though it may have not been your intention, my reading of it led me to believe that the purpose, and therefore the implementation, of a *temporary* array was for speed, and speed alone.

If instead of MyV = (H+L)/2, the example had been MyV = H/2 or MyV = Ref(H, -1), or MyV = Ref(otherarray, -1), does AB still create a temporary array prior to assigning the results to MyV? One might assume, for speed sake, that no temporary array would be created for H/2 or Ref(H, -1). Though it might be necessary for Ref(otherarray, -1), depending on otherarray.

Sorry if I sound a bit like my three year old grandson, who keeps asking 'why' over and over again. But that is how some us, regardless of age, learn.

Thank you.
-- Keith

On 4/23/2010 13:07, Tomasz Janeczko wrote:

Correction:
"entire (left-side) expression"
should read
"entire (right-side) expression".

On 2010-04-23 19:05, Tomasz Janeczko wrote:

Hello,

There is NO difference what is on the left side . It does not matter if expression includes same variable as on right side. The entire (left-side) expression is FIRST EVALUATED COMPLETELY (all bars at once) and AFTER that resulting ARRAY is assigned.

If you read
http://www.amibroker.com/guide/h_understandafl.html

carefully enough you would notice this part:

Processing arrays - why is AFL so fast?

Lets see how the following statement is processed:

MyVariable = ( High + Low )/2;

When AFL is evaluating statement like this ( High + Low )/2 it does not need to re-interpret this code for each bar. *Instead it takes the High ARRAY and Low ARRAY and adds corresponding array elements in single stage. In other words + operator (and other operators too) work on arrays at once and it is executed at full compiled-code speed, then the resulting array (each element of it) is divided by 2 also in single stage.*

Let's look into the details - see fig 2.. When AFL engine looks at the ( High + Low )/2 it first takes High (1) and Low (2) arrays and *produces (in single compiled step) the temporary array (3).* Then it creates the final array (4) by dividing each element of temporary array by two. This result is assigned to myVariable Bar

(see Fig. 2 in the http://www.amibroker.com/guide/h_understandafl.html )

Best regards,
Tomasz Janeczko
amibroker.com

On 2010-04-23 18:57, Keith McCombs wrote:
Mike --
Yes, temporary arrays are discussed on the link you referred to.

However, the link does not explicitly discuss the situation where the the same array is on both left and right side of an equation, as in Buy = Ref(Buy, -1). It does implicitly discuss it with the AMA(Close, Factor) example, which does not show a temporary holding array for the AMA value and evaluates the AMA by moving _forward_ in time. The link also implies that the _reason_ for using a temporary array in calculating MyV = (H+L)/2 is speed, without reference to any other _reason_. IMHO, the link falls quite short of explaining when and when not a temporary array is used.

I will agree that forward looking can be a dangerous practice. However that does not necessarily mean that it is mathematically incorrect. Sword swallowing is also dangerous, unless you are very careful, and not prone to hiccups.

I must admit that I was unaware either bounds on BuyPrice, etc., or of the function "SetOption("PriceBoundChecking", false). And in fact I must now go back over and check much of my old code where I have used statements such as "SellPrice = somevalue - slippage;".

As always, thank you for your knowledgeable replies.
-- Keith


On 4/23/2010 02:19, Mike wrote:

Keith,

Yes, the construction of temporary arrays is discussed, with detailed examples, in the following help page:

http://www.amibroker.com/guide/h_understandafl.html <http://www.amibroker.com/guide/h_understandafl.html>

As for SellPrice = Ref(O, 1); It is not so much a problem of the value being out of range. But rather, that you would be forward looking (i.e. referring today to tomorrow's open).

The out of range behavior can be disabled via SetOption("PriceBoundChecking", false); But, again, it is the forward looking that is the bigger problem.

It is true that AFL can, at times, be difficult. It may sound trite. But, with power comes complexity. It's a price I've been happy to pay.

I find that repetition is the best way to stay fluent in any coding language. To that end, I try to constantly challenge my assumptions and work on many different problems until it becomes 2nd nature. Trying to work out answers to other people's questions is the best way that I've found to do that; I'm constantly referring to help, documentation, code samples and other people's posts. All in an attempt to validate anything I write, so as not to lead anyone astray.

Mike

--- In amibroker@yahoogroups.com <mailto:amibroker%40yahoogroups.com>, Keith McCombs <kmcco...@...> wrote:
>
> Mike --
> I didn't know that,
> "Buy = Ref( Buy, -1 ) is not ambiguous.
> It will behave exactly has you have proposed in your workaround (i.e. > will internally create a temporary array holding Ref(Buy, -1) which will
> then be assigned to Buy)."
>
> Is that explained somewhere in the User's guide or Help?
>
> BTW, I didn't really know "SellPrice = Ref(O, 1);" was wrong until I
> found out why in the User's Manual, page 141 (after about an hour of
> looking):
> "During back-testing AmiBroker will check if the values you assigned to > buyprice, sellprice, shortprice, coverprice fit into high-low range of
> given bar. If not, AmiBroker will adjust it to high price (if price
> array value is higher than high) or to the low price (if price array
> value is lower than low)"
>
> It's these kind of things that make AB harder than it should be.
> -- Keith
>
> On 4/22/2010 22:13, Mike wrote:
> >
> > Keith,
> >
> > Buy = Ref( Buy, -1 ) is not ambiguous.
> >
> > It will behave exactly has you have proposed in your workaround (i.e. > > will internally create a temporary array holding Ref(Buy, -1) which
> > will then be assigned to Buy).
> >
> > It does, however, require that Buy has already been initialized before
> > this statement.
> >
> > Mike
> >
> > --- In amibroker@yahoogroups.com <mailto:amibroker%40yahoogroups.com> <mailto:amibroker%40yahoogroups.com>,
> > Keith McCombs <kmccombs@> wrote:
> > >
> > > I gave this thread a new name because TJ's response brought up a much
> > > more general concern, for me, than the original title expressed.
> > >
> > > I thought that statements such as "Buy = ref( Buy, -1 );" were
> > ambiguous
> > > and therefore should not be used. The reason being that if the array > > > valuation moves forward in time (Buy[n] evaluated before Buy[n+1]) then > > > all Buys will be equal to Buy[0]. However if valuation moves backward > > > (Buy[n+1] before Buy[n]) then a much different result is produced.
> > >
> > > Therefore, one should instead use something like this:
> > > temp = ref(Buy, -1);
> > > Buy = temp;
> > >
> > > Hopefully someone will clear up my confusion.
> > > Thank you.
> > > -- Keith
> > >
> > > On 4/20/2010 19:10, Tomasz Janeczko wrote:
> > > >
> > > > Hello,
> > > >
> > > > >SellPrice = Ref(O, 1);
> > > >
> > > > Wrong advice.
> > > > Once again: NEVER move trading prices using ref().
> > > >
> > > > Instead delays SIGNALS
> > > > Buy = ref( Buy, -1 );
> > > > Sell = ref( Sell, -1 );
> > > >
> > > > Best regards,
> > > > Tomasz Janeczko
> > > > amibroker.com
> > > >
> > > > On 2010-04-21 00:54, hiscores wrote:
> > > > > There are numerous ways to do this, but here is a simple one
> > > > >
> > > > > Buy = C> MA(C, 20);
> > > > > BuyPrice = C;
> > > > >
> > > > > StopLoss = C< MA(C, 50);
> > > > > ProfitTarget = C> MA(C, 10);
> > > > >
> > > > > Sell = StopLoss OR ProfitTarget;
> > > > > // If we exit due to stop loss take the 50 MA otherwise
> > > > > // by process of elimination we exit at target 10 MA
> > > > > SellPrice = iif(StopLoss, MA(C, 50), MA(C, 10));
> > > > >
> > > > > This is here so you can learn how to code such rules, but I should > > > > point out that your strategy is unrealistic! You are making a rule > > > > where if at the END of a bar we are below an MA we should sell at a
> > > > price ABOVE the close (ie the MA price that price action is now
> > > > below). Furthermore the MA will not settle to its final value until > > > > the bar is finished (since the MA is calculated on closing prices). > > > > You should probably set your sell prices to the open of the next bar
> > > > >
> > > > > SellPrice = Ref(O, 1);
> > > > >
> > > > > -hi
> > > > >
> > > > > --- In amibroker@yahoogroups.com <mailto:amibroker%40yahoogroups.com>
> > <mailto:amibroker%40yahoogroups.com>
> > > > <mailto:amibroker%40yahoogroups.com>,
> > > > "dralexchambers"<dralexchambers@> wrote:
> > > > >
> > > > >> Hi,
> > > > >>
> > > > >> How would I put together a backtest for the following. My Buy
> > > > signal is:
> > > > >>
> > > > >> Buy = C>MA(C,20);
> > > > >>
> > > > >> How do I do a multiple sell signal for the following:
> > > > >>
> > > > >> StopLoss is hit is when C< MA(C,50) Stoploss price is MA50.
> > > > TakeProfit is when C> MA(C,10), and TP price is MA10.
> > > > >>
> > > > >> I can only see one Sell& Sellprice variable. How do I put both of
> > > > these conditions into Sell& Sellprice?
> > > > >>
> > > > >> Thanks,
> > > > >> Alex
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > > >
> > > > > ------------------------------------
> > > > >
> > > > > **** 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/ <http://www.amibroker.com/feedback/> > > <http://www.amibroker.com/feedback/ <http://www.amibroker.com/feedback/>> > > <http://www.amibroker.com/feedback/ <http://www.amibroker.com/feedback/> <http://www.amibroker.com/feedback/ <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/ <http://www.amibroker.com/devlog/> > > <http://www.amibroker.com/devlog/ <http://www.amibroker.com/devlog/>> <http://www.amibroker.com/devlog/ <http://www.amibroker.com/devlog/> > > <http://www.amibroker.com/devlog/ <http://www.amibroker.com/devlog/>>>
> > > > >
> > > > > Yahoo! Groups Links
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
>


Reply via email to