Login Page - Create Account

Support Board


Date/Time: Thu, 28 Nov 2024 08:53:39 +0000



[Programming Help] - How to display Daily Breakeven Line??

View Count: 366

[2023-05-12 03:01:23]
User61168 - Posts: 403
Hello SC Users,

Wondering if anyone can help me figure out what is wrong with this logic. I am trying to implement a horizontal line on the chart to display where my open position would breakeven for the day when I have floating PnL and Realized PnL from past trades taken intraday. My knowledge is limited to simple alerts so I am hoping use of "Spreadsheet Formula" study would do the trick for NQ emini.

I have the following Studies:
ID7.SG1 = Position Qty
ID9.SG1 = Position Average Price
ID10.SG1 = Daily Profit/Loss (this is my realized pnl in Points
ID40.SG1 = Spreadsheet Formula Study (mentioned here... Spreadsheet Formula )
with this formula below, Number of Bars to calculate = 1000 and Draw Zero values = Yes

=OR(AND(ID7.SG1>0,C+((C-ID9.SG1)*ID7.SG1+ID10.SG1)),AND(ID7.SG1<0,C+((ID9.SG1-C)*ABS(ID7.SG1)+ID10.SG1)) )

There are no syntax errors and no horizontal line is created on the chart. What am I doing wrong? is there a better way to know how far I am from breaking even for the day to exit my trades and stop trading? I don't have ASCIL or "spreadsheet for trading" knowledge.

I would really appreciate your assistance.

Edit: Please know that my realized profit could be +/- and my floating profit could also be in +/- above or below my realized profit. I scale in and out of trades so ID9.SG1 as my Average Price line is always accurately displayed on the chart. My Simple alert automated trading strategy will use this DayBE line to close all positions when C=dayBE and stop auto trading until session close.

Edit1: Perhaps some more clarity on what I am trying to achieve.
When C touches the DayBE line, my realized pnl + floating pnl should be 0 points (ignoring trading costs). This will allow me to place my SL or TP near DayBE line and avoid watching charts when trade is open. In essence, I need to draw a line at C+/- "NPL" (the value displayed in the trade ticket window) automatically when a trade is open.
Date Time Of Last Edit: 2023-05-12 04:20:38
[2023-05-13 01:28:38]
Sawtooth - Posts: 4120
In essence, I need to draw a line at C+/- "NPL" (the value displayed in the trade ticket window) automatically when a trade is open.
I'm not sure this can be done without a spreadsheet study because you need to find the current bar, and make every other value a persistent absolute reference from that bar.

(Note: Despite it's name, the Spreadsheet Formula study is not a spreadsheet study. It uses Alert syntax, not spreadsheet syntax.)

Don't let the spreadsheet study syntax intimidate you.
You've written a complex Alert formula, so you can readily use a spreadsheet study.

C= E3
ID7.SG1 = ID7.SG1@3
ID9.SG1 = ID9.SG1@3
ID10.SG1 = ID10.SG1@3

The @3 is the row number, and row 3 is the current bar, with previous bars in rows below.
e.g, the previous bar is @4, instead of [-1]

So, try this:
Add the Spreadsheet Study study
- Give it a name in the Spreadsheet Name field
- Set the Chart Region to 1
- Click OK, a spreadsheet sheet will appear.
- Use this formula in cell K3:
=IF(ID7.SG1@$3=0,0,IF(ID7.SG1@3>0,E$3+(E$3-ID9.SG1@$3)*ID7.SG1@$3+ID10.SG1@$3,K4))
- Use this formula in cell L3:
=IF(ID7.SG1@$3=0,0,IF(ID7.SG1@3<0,E$3+(ID9.SG1@$3-E$3)*ABS(ID7.SG1@$3)+ID10.SG1@$3,L4))

These are your formulas, converted to spreadsheet syntax, with absolute references (using $) to the current bar, and made persistent by using the IF function referring to the previous value (K4/L4), with an added IF to clear the line if flat.

Column K is SG1, Column L is SG2. Set the line colors on the Subgraphs tab.
Date Time Of Last Edit: 2023-05-13 02:26:10
[2023-05-13 05:29:30]
User61168 - Posts: 403
Thanks Tom for encouragement me one more time to move to Spreadsheets. I tried several times and it is surely intimidating for numerous reasons mostly in the way I have designed all my study collections. Since my strategies are scalable to any instrument and thinking longer term, running them within the SC platform is quite limiting as the platform clocks with just 5+ charts during NYSE open.

Once my algo mature, I rather invest in developing a solution that does not require visual display of charts. Something that runs in the background in 'stealth' mode 24x5 monitored by a remote/virtual assistant in India and Mexico (instead of me!). I have no idea what that solution would look like and whether it is even possible to do it all using ASCIL. Security features in Sierra Chart is just not adequate for allowing a remote admin to monitor my algos in read-only mode to the platform.

Thanks again for the sample code. I will most certainly try it out.

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

Login

Login Page - Create Account