Login Page - Create Account

Support Board


Date/Time: Sun, 28 Apr 2024 19:04:34 +0000



[Programming Help] - Help for Alert Condition Formula - Gold Star for the Correct Answer and a thank you ;-)

View Count: 748

[2019-09-11 10:12:34]
User513662 - Posts: 90
Hello,

The crux of my question (I think) is coming up with a statement for an Exit alert condition "Hold for at least the bar the trade occurred on" or "don't exit on the same bar the trade occurred in" - something like that.

I have a custom study which outputs 1 or 0 depending on whether certain conditions are met. My entry and exits depend on the study being on or off using the "Trading System Based on Alert Condition" study.

The study outputs 1 or 0 in real time i.e. it is not calculated end of bar which means it can potentially flick on and off several times over the course of a bar. Here is what I want to do:

Enter | at any point when the condition is activated - ID5.SG2=1 in this case - easy.
Exit | Hold for at least the bar the output 1 activates (so I don't get shaken out by the study flicking off), then exit at any point when it goes to zero after the bar the trade occurred on. All I have is this ID5.SG2<>1 for the Buy Exit however I am missing the part "Hold for at least the bar the trade occurred on" or "don't exit on the same bar the trade occurred in" - something like that.

I can't reference the custom study with a -1 bar reference because sometimes by the end of the bar the trade occurred in it is 0 when it has obviously been 1 at some point in the bar for me to take the auto trade.

I just need to somehow reference the bar the trade is taken on as being true (trade is taken on this bar) or false (trade is not on this bar). I've looked through studies and documentation and have hit a dead end.

Can anyone please help?
[2019-09-11 14:58:56]
Sawtooth - Posts: 3980
Try this:

Add the Trading: Position Quantity study, and reference its value in your exit formula:
=AND(YourExitConditions,ID6.SG1[-1]>0)
where the Trading: Position Quantity study is ID6.
[2019-09-12 01:20:13]
User513662 - Posts: 90
Hi Tomgilb.

This works perfectly! Many thanks! Greatly appreciated.

As promised please find attached :-)
imageGold Star.jpg / V - Attached On 2019-09-12 01:19:46 UTC - Size: 9.64 KB - 189 views

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account