Remember that variables like ATR(period) are arrays.

Try something like:

StopPrice=BuyPrice - Ref(vaIStopVal, -BarsSince(Buy));

That will subtract the constant value of vaIStopVal on the Buy bar
from the BuyPrice so the StopPrice will be the same for every bar
since the Buy bar.

Bill
--- In [email protected], "Graham Johnson" <[EMAIL PROTECTED]> 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
> >
>


Reply via email to