Support Board
Date/Time: Sat, 01 Mar 2025 05:39:59 +0000
[Programming Help] - Detecting OnPriceChanged Intrabar
View Count: 428
[2021-09-11 20:18:49] |
silvereagle - Posts: 23 |
Hi friends, I'm a little stuck on where to start with some code for my ACS, so any snippets or pointers to appropriate documentation and or ACS_Source files is much appreciated. The Goal: I'm searching for some code that would essentially act as an OnPriceChanged() event within the current bar. The closest study that seems to do something like this that I've found, is the CurrentPriceLine study, which displays a horizontal line on the chart that goes up and down based on price changes. So, obviously, this study is detecting price changes intrabar. Unfortunately, the code in that study is a bit confusing to me at present, I'm not sure exactly which parts I might be able to canabalize to have the equivalent functionality in my ACS. Alternatively, the thought occurred to me that it might be possible to duplicate the CurrentPriceLine study, customize it somehow to expose something, a counter or flag like PRICE_CHANGED or something that my ACS might be able to reference. I'm speculating, as I'm still wrapping my brain around a lot of the api and what is possible... so, I'm hoping some folks with more api experience can point me down the right road instead of me losing weeks going down a wrong rabbit hole. Any help is much appreciated on how to detect something like OnPriceChanged() intrabar. Thanks everyone. :) |
[2021-09-12 03:09:51] |
silvereagle - Posts: 23 |
I think my brain panicked a little after looking at some of that code, but after digging around a little and some experimentation and a cold beer, I think the key line of code I was looking for was: sc.LastTradePrice
Basically, to get OnPriceChanged functionality, 1. create a persistant float to house the prior price value 2. get the last trade price, float ltp = sc.LastTradePrice 3. if PriorPrice != ltp, then ... the price changed. 4. set priorprice to ltp I also found sc.GetLastPriceForTrading(). Not sure if I should use that or sc.LastTradePrice, or if it really matters. In the logging, it looks the same. Hope this helps someone someday. :) |
To post a message in this thread, you need to log in with your Sierra Chart account: