Dynamic Stop-Loss for Auto Analysis

#1
For this simple code of

Buy = StochK(5,3) Crosses StochD(5,3,3)
Sell = StochD(5,3,3) Crosses StochK(5,3)

how to write a dynamic SL in AFL code itself?
When i buy on the above rule, I want the SL to be the low of the candle on which the buy signal is triggered.
When i Sell, SL to be High of the candle on which the sell signal is given.

And Targets are to be booked as per the range of the bar on which the signal is given.

Suppose Buy signal given on a Bar with:-
High of the signal bar Rs 250
Low of the signal bar Rs 248
SL is to be Rs < 248
Profit 1 is Rs 252(diff between high and low of the signal bar)
Profit 2 is Rs 254(range * 2)

I usually make use of Settings window in Auto analyser window. But it has only fixed SLs based on Points, percentages etc.

Some good heart plz help me out

Rgds
Boona
 
#4
Dear rpc

Thanx for ur help, may God bess u in trading

slvalue = ValueWhen(Buy,L,1);
sl = Cross(slvalue,L);
Sell = sl;

1. Just for my understanding, in the 2nd line of the above code(sl = Cross(slvalue,L)) is it not that when the Low crosses the "slvalue", SL is triggered?? It appears as if SL is triggered when "slvalue" crosses the Low.....

2. Is the code below for SL for Short trades correct??
slvalue = ValueWhen(Short,H,1);
sl = Cross(slvalue,H);
Cover = sl;

3. This code plots multiple SL hits. How to prevent that?
For eg, When there is buy at 250, SL at 248, SL hit is plotted whenever Low breaches/touches 248. It is plotted whenever
the Low is touched on multiple occasions until the next Buy call is triggered.

Thanks again

plz dont mind these layman questions...i have very little exp in programming

Rgds
Boona
 
Last edited:

Similar threads