Support Board
Date/Time: Fri, 07 Feb 2025 14:48:10 +0000
[Programming Help] - Bar based on midpoint
View Count: 704
[2022-01-07 14:00:19] |
Pedro7 - Posts: 25 |
Hi, Is there in Sierrachart the possibility to have a bar based on the midpoint between bid and ask or based on the bid instead of having it based on the last trade. Ex. bid is 100, ask 110, last trade is 95. The top green part (in case open is lower) of the bar and the price indicated on the chart is 105 instead of 95. Thanks Date Time Of Last Edit: 2022-01-07 18:27:33
|
[2022-01-07 17:58:32] |
Tony - Posts: 549 |
Just to clarify your question: I assume you want the candle body to be open and midpoint of bid-ask, instead of open and close? The colour of the candle body could be either red or green? depend on whether open is above midpoint or below? I think that can only be done for the last bar of the chart (with a custom study), all previous bars still have to form the candle body by using open-close value? What ever product you are trading, the bid-ask spread is terrible, unless the unit is cent, hope it is not a liquidity issue. Date Time Of Last Edit: 2022-01-07 19:24:24
|
[2022-01-07 18:26:55] |
Pedro7 - Posts: 25 |
That's correct Tony. It's a feature that i've seen in other programs.
|
[2022-01-07 18:57:17] |
Tony - Posts: 549 |
I wrote this code which is exactly what you need, //code start SCSFExport scsf_Open_MidPoint_At_Last_Bar(SCStudyInterfaceRef sc) { SCSubgraphRef MyBarTop = sc.Subgraph[0]; SCSubgraphRef MyBarBottom = sc.Subgraph[1]; if (sc.SetDefaults) { sc.GraphName = "Last Bar Open Midpoint"; sc.AutoLoop = 1; sc.GraphRegion = 0; sc.UpdateAlways = 1; MyBarTop.Name = "My Bar Top"; MyBarBottom.Name = "My Bar Bottom"; MyBarTop.DrawStyle = DRAWSTYLE_BAR_TOP; MyBarBottom.DrawStyle = DRAWSTYLE_BAR_BOTTOM; MyBarTop.LineWidth = 4; MyBarBottom.LineWidth = 4; return; } for (int IndexCount=0; IndexCount<=sc.Index; IndexCount++) { if (IndexCount==sc.Index) MyBarTop[IndexCount] = (sc.Bid + sc.Ask) / 2; else MyBarTop[IndexCount] = sc.Close[IndexCount]; MyBarBottom[IndexCount] = sc.Open[IndexCount]; if (MyBarTop[IndexCount]>MyBarBottom[IndexCount]) MyBarTop.DataColor[IndexCount] = RGB(0, 255, 0); else MyBarBottom.DataColor[IndexCount] = RGB(255, 0, 0); } } //code end 1, Remote build the above code, 2, Set Main Graph' graph draw type as HL bars and line width to 1 3, Load this custom study to your chart and make sure "Draw Study Underneath Main Price Graph" is unchecked Date Time Of Last Edit: 2022-01-07 19:10:51
|
[2022-01-07 19:10:29] |
Pedro7 - Posts: 25 |
Thanks Tony, will give it a try. Appreciate your help. |
[2022-01-07 19:22:44] |
Sawtooth - Posts: 4173 |
This can also be done with 4 native studies: 1. Add the Color Bar Based On Alert Condition study. - Put this formula on its Alerts tab: =C[1] This locates the current bar. 2. Add the Spreadsheet Formula study. - Check 'Hide Study' - Put this formula in its Formula field: =AVERAGE(BID,ASK) 3. Add another Color Bar Based On Alert Condition study. - Use a formula like this on its Alerts tab: =AND(ID1.SG1=0,ID2.SG1>O) [that's an O for Open, not a zero] where ID1.SG1 is the color bar study in #1 above, and ID2 is the spreadsheet formula study in #2 above. - Set the DrawStyle color for an up bar. 4. Duplicate the Color Bar Based On Alert Condition study of #3 above, with these changes: - Use this formula: =AND(ID1.SG1=0,ID2.SG1<O) - Set the DrawStyle color for a down bar. |
To post a message in this thread, you need to log in with your Sierra Chart account: