# Stochastic hook ..code needed

Dear Seniors ,

Buy = Stochastic (15,3) > Ref(Stochastic(15,3),-1) AND Ref(Stochastic(15,3),-1) < Ref(Stochastic(15,3),-2)
AND ROC (EMA(C,50),5)>0.2|
** with this buy setup gets active…now buy should be triggered as soon as price goes above the bar that activated buy setup on same or subsequent bars .
** stop loss would be below buy setup activation BAR|

Dear Senior members,

You did not specify how long the Buy Setup remains active. This statement is also ambiguous:

buy should be triggered as soon as price goes above the bar that activated buy setup on same or subsequent bars

If you mean that the High should be greater than the High of the Buy Setup bar, then it is impossible for that to happen on the same bar as the Setup as you have stated.

Stating your problem clearly will help others to help you. Also, have you made any attempt to solve this yourself? You might find the `ValueWhen()` and `BarsSince()` functions helpful.

Buy setup activation = when above mentioned two conditions met .
Buy setup trigger = when close is greater than buy setup activation bar.
Bar to hold setup activated = 5 bar

You're still not being specific enough, but you can start with something like this and modify it to fit your needs:

``````BuySetup = <your logic here>;
``````

There are many other ways to solve this as well. In addition to the above, I recommend looking at the functions `Hold()`, `Sum()`, and `HHV()`.

1 Like

Hi Sir,
Thanks for valuable support , now below code is perfect
kindly help for stoploss also .

Condition : stop loss would be low of buy setup activation BAR

BuySetup = Stochastic (15,3) > Ref(Stochastic(15,3),-1) AND Ref(Stochastic(15,3),-1) < Ref(Stochastic(15,3),-2)
AND ROC (EMA(C,50),5) > 0.2 ;