Support Board
Date/Time: Sun, 15 Jun 2025 07:09:16 +0000
[Programming Help] - ACSIL - Get Candlestick Type (Bull/Bear)
View Count: 292
[2025-05-27 16:15:03] |
Dennzisme - Posts: 26 |
Hello, Is there a function to get the candlestick type after a bar closure - bull or bear? Thanks in advance. Best regards, Dennz |
[2025-05-27 17:08:07] |
cmet - Posts: 706 |
What does this mean? Up or Dn close? Candlestick Pattern? Some other measurement?
|
[2025-05-27 17:27:18] |
Dennzisme - Posts: 26 |
Hello, Could you let me know whether ACSIL provides a function to determine the candlestick type (e.g., Up/Down, Bullish/Bearish, or Green/Red)? I have included an attachment for reference. Thank you for your assistance. Best regards, Dennz |
![]() |
[2025-05-27 18:14:49] |
cmet - Posts: 706 |
Here's one, for up/dn/unchanged void CalculateBarCloseStates(SCFloatArrayRef OpenArray, SCFloatArrayRef CloseArray, SCFloatArrayRef OutputArray, int StartIndex, int EndIndex)
{ for (int i = StartIndex; i <= EndIndex; ++i) { if (CloseArray[i] > OpenArray[i]) OutputArray[i] = 1.0f; else if (CloseArray[i] < OpenArray[i]) OutputArray[i] = -1.0f; else OutputArray[i] = 0.0f; } } |
[2025-05-27 18:37:08] |
Dennzisme - Posts: 26 |
Hello, Thanks for your reply, this solution sadly did not fix my issue. I don't understand how sierra chart is determining a bullish or bearish candle. I was going by this logic from another forum post: 1. If the close is below the open, then the bar is down.
2. If the close is above the open, then the bar is up. 3. If the close is the same as the open, then we look at the difference between the current close and the prior close. If the current close is below the prior close, then the bar is down. If the current close is above the prior close, the bar is up. If the current close is the same as the prior close, repeat the algorithm using the next previous bar. And this is the code that I am currently using to trying to replicate sierra charts bullish/bearish candlesticks: bool bull = false, bear = false;
// Determine bull/bear candle if (C < O) // close below open → bearish { bear = true; } else if (C > O) // close above open → bullish { bull = true; } else // C == O (doji) → look at earlier bars { int checkIndex = i - 1; bool foundDiff = false; // Walk backwards until we find a bar whose close differs while (checkIndex >= 0) { float priorClose = sc.Close[checkIndex]; if (C < priorClose) // current close lower than a previous → bearish { bear = true; foundDiff = true; break; } else if (C > priorClose) // current close higher than a previous → bullish { bull = true; foundDiff = true; break; } else { --checkIndex; // still equal – keep looking further back } } // Still no difference? Default to bullish if (!foundDiff) bull = true; } But this is sadly not replicating how sierra chart displays bullish/bearish candlesticks (I have added an attachment below ; the green arrow is pointing to the candle that is bearish, but when I run my code it is bullish) That is why I was wondering if they have a function in ACSIL to determine which candlestick type it is. Any help would be greatly appreciated. |
![]() |
[2025-05-27 21:01:48] |
cmet - Posts: 706 |
Not really sure what you're after. The code I posted determines if the bar close was up, down or equal to the open and returns a value. Are you trying to create custom bars? |
[2025-05-28 07:51:55] |
Dennzisme - Posts: 26 |
I'm trying to figure out how sierra chart is determining if a doji candle (OPEN = CLOSE) is either bullish or bearish. This solution here that I found in another forum post is not correct: If the close is the same as the open, then we look at the difference between the current close and the prior close. If the current close is below the prior close, then the bar is down. If the current close is above the prior close, the bar is up. If the current close is the same as the prior close, repeat the algorithm using the next previous bar.
Help would greatly be appreciated. Best regards, Dennz |
[2025-05-28 10:39:35] |
Tr00pz - Posts: 22 |
Check out the studies4.cpp file in the ACS_Source folder in the SC installation folder. This file has the code on the Candlestick Patterns study. I found this in a quick search of the file (I recommend looking through more of the code to fully understand how it's being used): inline bool IsDoji(SCStudyInterfaceRef sc, const s_CandleStickPatternsFinderSettings& settings, int index) { const double Doji_BodyPercent = 5.0; SCBaseDataRef InData = sc.BaseData; if (BodyLength(InData, index) <= PercentOfCandleLength(InData, index, Doji_BodyPercent)) { return true; } return false; } |
[2025-05-28 12:31:05] |
Sawtooth - Posts: 4226 |
Here's a spreadsheet formula to determine bar color, including doji candles: Spreadsheet Example Formulas and Usage: Formula that Matches the Coloring of Up and Down Price Bars |
To post a message in this thread, you need to log in with your Sierra Chart account: