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

[amibroker] Re: Identify bar for actual Buy



PureBytes Links

Trading Reference Links

> vaInitStop = 0;
> vaInitStop = IIf(((Buy == 1) AND (Ref(vaInitStop, -1) == 0)) , 
BuyPrice - (Ref(vaIStopVal, -1)), Ref(vaInitStop, -1));

AFL array maths doesn't allow you to have iterative statements like
that. In the definition of vaInitStop, you're trying to base it on the
value of the same variable at the previous bar. You can't do that. All
references to vaInitStop during that definition actually reference the
value set at the previous statement, ie. zero.

If AFL works like other programming languages, that's because the
assignment operation (ie. the '=') is the very last thing that
happens, so the whole resulting array is calculated in some temporary
hidden variable using the last assigned values of vaInitStop (ie. all
zero), and as the very last step that resulting array is copied into
vaInitStop overwriting all the zeroes.

You need to use a loop so that you can work through the array bar by
bar. The loop also makes it easy to remove redundant buy signals.

Also, it would probably be better to initialise the array to Null
rather than zero, so that when you plot it you won't get lines
dropping down to zero between purchases.

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "Graham Johnson" <grahamj@xxx> wrote:
>
> Hi
> 
> The bottom line with this is that I want to be able to set a stop and 
> have control over it.
> 
> After thinking it through, I decided that the first step was to set 
> the stop for the first Buy signal and keep it at the same value until 
> a Sell signal and then set it to 0 again.
> 
> Seemed like a great theory but the stop value is reset at each bar 
> and therefore does not maintain a constant value.  Maybe it is a 
> mindset thing - my professional experience was with procedural 
> languages and AFL taxes my thinking processes sometimes - maybe 
> something about teaching an old dog new tricks...
> 
> Anyway, the snippet of code for setting the stop is as follows
> 
> Buy = Ref(vaValidEntry,-1) AND Low <= Ref(vaLimitEntry, -1);
> BuyPrice = Min(Open, Ref(vaLimitEntry, -1));
> vaIStopVal = ATR(vISATRPer) * vISMult;
> vaInitStop = 0;
> vaInitStop = IIf(((Buy == 1) AND (Ref(vaInitStop, -1) == 0)) , 
> BuyPrice - (Ref(vaIStopVal, -1)), Ref(vaInitStop, -1));
> _TRACE(" | buy: " + Buy + " | stop: " + vaInitStop + " | PrevStop: " 
> + Ref(vaInitStop, -1));
> 
> Any ideas as to where I've gone wrong and why it is resetting the 
> value each bar, please.
> 
> Graham
> 
> > I'm sure that a solution for this has been on the forum, but - 
> after 
> > much searching......
> > 
> > Code is for a Long system that does not pyramid.
> > 
> > I am looking to manually code the disaster stop, so need to be able 
> to 
> > set the stop on the day that the trade is actually entered, and not 
> > have the water muddied by subsequent signals that are not taken 
> because 
> > the system does not pyramid.
> > 
> > I know that the ApplyStop function is available, but I need to 
> acquire 
> > the technique for controlling stops programatically.
> > 
> > Hopefully, this is clear.
> > 
> > Graham
> >
>




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

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

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

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