Stochastic hook ..code needed

Dear Seniors ,

Please help in coding two lines marked as **

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,
kindly please reply .

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.

Thanks sir for reply...
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>;
Buy = H > ValueWhen(BuySetup,H) AND
      BarsSince(BuySetup) <= 5;

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 :+1:
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 ;

Buy = H > ValueWhen(BuySetup,H) AND BarsSince(BuySetup) <= 5;

Hmmm, code is perfect, and yet you didn't mark it as the solution or even "like" it? Perhaps you should go back and read TJ's posts on how to use this site.

As for your exit conditions, you can use the same AmiBroker functions and very similar logic to what's already been provided. Try to implement a solution using these tools, and if it doesn't work on the first try, then do some debugging with an Exploration or the built-in AmiBroker debugger. If you still can't get it, come back and show us your work, and someone will no doubt be happy to point you in the right direction.

2 Likes