Support Board
Date/Time: Mon, 06 May 2024 01:51:10 +0000
[Programming Help] - Trial user: only able to apply study against current bar
View Count: 563
[2019-12-13 04:20:45] |
mm3599 - Posts: 13 |
Hello - I am trialing SC. I have written a custom function that is referenced by a custom study that I added to ExampleCustomStudies.cpp. The study only appears to be passing in the current bar's data and not starting from bar zero. The logging I have written only shows the last bar's index in the Message Log UI. /*===============================================================================
MACDP Fast Function */ SCFloatArrayRef MACDPFast(SCStudyGraphRef sc, SCBaseDataRef BaseDataIn, SCFloatArrayRef Out, int Index, float Fast) { //fastEMA[0]=((2.0 / (1 + Fast)) * Close[0] + (1 - (2.0 / (1 + Fast))) * fastEMA[1]); // fast_part_1_calc = (2.0 / (1 + Fast)) * Close[0] // fast_part_2_calc = (1 - (2.0 / (1 + Fast))) // fast_part_3_value = Subgraph_MACDP_Fast[1] SCString Output; sc.FormatString(Output, "Index=%i,Fast=%f", Index,Fast); sc.AddMessageToLog(Output, 0); if (Index <= Fast) Out[Index] = BaseDataIn[SC_LAST][Index]; else if (Index > Fast) { float fast_part_1_calc = (2.0 / (1 + Fast)) * BaseDataIn[SC_LAST][Index-1]; float fast_part_2_calc = (1 - (2.0 / (1 + Fast))); Out[Index] = fast_part_1_calc + (fast_part_2_calc * Out[Index - 1]); } return Out; } Here's the calling code: SCSFExport scsf_MACDP(SCStudyGraphRef sc)
{ SCSubgraphRef Subgraph_MACDP = sc.Subgraph[0]; SCFloatArrayRef Array_MACDP_Fast = sc.Subgraph[0].Arrays[0]; //SCSubgraphRef Subgraph_SMA_Demin = sc.Subgraph[4]; if (sc.SetDefaults) { sc.GraphName = "MACDP Rev 1"; sc.StudyDescription = "MACDP calc test."; sc.AutoLoop = 1; // true sc.FreeDLL = 0; sc.GraphRegion = 0; Subgraph_MACDP.Name = "MACDP"; Subgraph_MACDP.PrimaryColor = RGB(255,0,0); // Red Subgraph_MACDP.DrawStyle = DRAWSTYLE_LINE; return; } float fast, slow, smooth, macdp_value; fast = 8.3897; slow = 17.5185; smooth = 9.0503; macdp_value = 0.0; //calculate the fast value for the macdp sc.DataStartIndex = 18; MACDPFast(sc, sc.BaseDataIn, Array_MACDP_Fast, sc.Index, fast); SCString Output; sc.FormatString(Output, "Array_MACDP_Fast[sc.Index]=%f,Array_MACDP_Fast[sc.Index-1]=%f", Array_MACDP_Fast[sc.Index],Array_MACDP_Fast[sc.Index-1]); sc.AddMessageToLog(Output, 0); } Here a sample log output: Chart: ES-201912-GLOBEX 30000 Trades #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=inf,Array_MACDP_Fast[sc.Index-1]=inf | 2019-12-12 23:17:09.508
Chart: ES-201912-GLOBEX 30000 Trades #1 | Study: MACDP Rev 1 | Index=1317,Fast=8.389700 | 2019-12-12 23:17:10.526 |
[2019-12-13 16:28:25] |
User907968 - Posts: 802 |
I just copied and pasted your code, then compiled, seems to work as intended (starts calculation from index = 0). This is an example of what I see, after scrolling almost to the top of the message log: Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=0,Fast=8.389700 | 2019-12-13 10:22:12.621
Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.070000,Array_MACDP_Fast[sc.Index-1]=59.070000 | 2019-12-13 10:22:12.621 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=1,Fast=8.389700 | 2019-12-13 10:22:14.327 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.070000,Array_MACDP_Fast[sc.Index-1]=59.070000 | 2019-12-13 10:22:14.327 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=2,Fast=8.389700 | 2019-12-13 10:22:14.895 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.059998,Array_MACDP_Fast[sc.Index-1]=59.070000 | 2019-12-13 10:22:14.895 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=3,Fast=8.389700 | 2019-12-13 10:22:15.071 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.070000,Array_MACDP_Fast[sc.Index-1]=59.059998 | 2019-12-13 10:22:15.071 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=4,Fast=8.389700 | 2019-12-13 10:22:15.319 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.079998,Array_MACDP_Fast[sc.Index-1]=59.070000 | 2019-12-13 10:22:15.319 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=5,Fast=8.389700 | 2019-12-13 10:22:15.497 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.070000,Array_MACDP_Fast[sc.Index-1]=59.079998 | 2019-12-13 10:22:15.497 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=6,Fast=8.389700 | 2019-12-13 10:22:15.685 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.079998,Array_MACDP_Fast[sc.Index-1]=59.070000 | 2019-12-13 10:22:15.685 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=7,Fast=8.389700 | 2019-12-13 10:22:15.875 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.079998,Array_MACDP_Fast[sc.Index-1]=59.079998 | 2019-12-13 10:22:15.875 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=8,Fast=8.389700 | 2019-12-13 10:22:16.048 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.070000,Array_MACDP_Fast[sc.Index-1]=59.079998 | 2019-12-13 10:22:16.048 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=9,Fast=8.389700 | 2019-12-13 10:22:16.234 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.070000,Array_MACDP_Fast[sc.Index-1]=59.070000 | 2019-12-13 10:22:16.234 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Index=10,Fast=8.389700 | 2019-12-13 10:22:16.474 Chart: CLF20[M] 1 Min #1 | Study: MACDP Rev 1 | Array_MACDP_Fast[sc.Index]=59.072128,Array_MACDP_Fast[sc.Index-1]=59.070000 | 2019-12-13 10:22:16.474 Date Time Of Last Edit: 2019-12-13 16:29:52
|
[2019-12-15 17:58:42] |
mm3599 - Posts: 13 |
Seems I did not remove and re-add. Looks like I need to do that. Thank-you |
To post a message in this thread, you need to log in with your Sierra Chart account: