Support Board
Date/Time: Thu, 06 Mar 2025 09:05:02 +0000
[Programming Help] - How to create my own class and use it correctly?
View Count: 614
[2022-01-29 15:06:22] |
Diego - Posts: 3 |
I test these: in "Waves.h" class SmallWaves { public: SmallWaves(); ~SmallWaves(); void test(); }; SmallWaves::SmallWaves() {} SmallWaves::~SmallWaves() {} void SmallWaves::test() { float temp = 0; } #include "Waves.h" #include "sierrachart.h" SCDLLName("My Studies") SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc) { SCSubgraphRef SmallWavesTop = sc.Subgraph[0]; SCSubgraphRef SmallWavesBottom = sc.Subgraph[1]; SCFloatArrayRef Open = sc.BaseData[SC_OPEN]; SCFloatArrayRef Close = sc.BaseData[SC_LAST]; SCFloatArrayRef High = sc.BaseData[SC_HIGH]; SCFloatArrayRef Low = sc.BaseData[SC_LOW]; // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { sc.GraphName = "威科夫波浪"; sc.AutoLoop = 1; //Automatic looping is enabled. SmallWavesTop.Name = "上升浪"; SmallWavesTop.DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_RECTANGLE_TOP; SmallWavesTop.PrimaryColor = RGB (50, 91, 212); SmallWavesBottom.Name = "下降浪"; SmallWavesBottom.DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_RECTANGLE_BOTTOM; SmallWavesBottom.PrimaryColor = RGB (255, 0, 255); //sc.Input[0].Name = "Float Input"; //sc.Input[0].SetFloat(0.0f); return; } SmallWaves wave(); wave.test(); } Wave.cpp: In function 'void scsf_TemplateFunction(SCStudyInterfaceRef)': Wave.cpp:35:7: error: request for member 'test' in 'wave', which is of non-class type 'SmallWaves()' 35 | wave.test(); | ^~~~ |
[2022-01-29 23:25:39] |
Tony - Posts: 552 |
我不是程序员,刚刚用ACSIL两年,没有办法回答你关于Class的问题,只是说说你代码里其他比较 明显的问题: 背景:ACSIL最基本的概念就是所有的K线作为数组来处理,比如你有100条K线,那么数组的编号就是 从[0]到[99],最后一条K线的编号可以用 sc.Index来代替,具体到我们这个例子,sc.Index的数 值就是99,如果有新的K线(比如5分钟图的下一个5分钟)那sc.Index的数值会自动跟新,就是100, 101..依次排下去。开盘价、收盘价、最高价和最低价不需要专门定义,直接调用就可以,比如,如果 你想知道第67根K线的最高价:sc.High[67],或者最后一条K线的收盘价:sc.Close[sc.Index]。 有了背景知识,你要添加的任何指标,实际上就是在已有的K线数组上添加新的数组而已,编号一样,具 体到你的代码里,从 SmallWavesTop[0] 到 SmallWavesTop[sc.Index],以及从 SmallWavesBottom[0] 到 SmallWavesBottom[sc.Index]都要有数据,不然就算编译通过了,你在图上也看不到任何结果。 威科夫波浪有很强的主观性,如果没有具体的公式,很难在K线图上表达出来。 DRAWSTYLE_TRANSPARENT_FILL_RECTANGLE_TOP 和 DRAWSTYLE_TRANSPARENT_FILL_RECTANGLE_BOTTOM 是作为一对数据来用的,用来显示一条信息。你的代码里好像有两条信息:上升浪和下降浪,应该需要两对 上下对应的 DRAWSTYLE 才对。 另外,根据我的经验,用function可能比用class要方便,而且放在同一个.cpp文件即可,如果有 其他指标,也都可以放在同一个.cpp文件。 Date Time Of Last Edit: 2022-01-29 23:54:39
|
[2022-01-30 01:07:25] |
Diego - Posts: 3 |
我不是程序员,刚刚用ACSIL两年,没有办法回答你关于Class的问题,只是说说你代码里其他比较
哇塞,竟然有同胞,你提到的前边的几个问题我都清楚,K线序列、高开低收、配对DRAWSTYLE。我使用class的原因是必须要使用面向对象,因为我之前在MT4里面写的缠论的笔段指标是通过周期递归实现的,如果改成面向过程的话会有大量重复代码,可能会到几千行,非常的麻烦。使用class只需要500行就可以了。
明显的问题: |
[2022-01-30 01:14:52] |
Diego - Posts: 3 |
The bug has been solved,change SmallWaves wave(); toSmallWaves wave;
|
To post a message in this thread, you need to log in with your Sierra Chart account: