Support Board
Date/Time: Thu, 28 Nov 2024 22:32:43 +0000
Post From: Pine script to Sierra Chart issue
[2023-04-04 07:45:07] |
User897008 - Posts: 48 |
Hello, I use ChatGPT converted a pine script to Sierra Chart, but cannot compile success. Can anyone help me fix it? Many thanks! #include "sierrachart.h" SCDLLName("Cong Adaptive Moving Average") SCSFExport scsf_CongAdaptiveMovingAverage(SCStudyInterfaceRef sc) { SCSubgraphRef CAMA = sc.Subgraph[0]; SCInputRef Length = sc.Input[0]; SCInputRef Source = sc.Input[1]; if (sc.SetDefaults) { sc.GraphName = "Cong Adaptive Moving Average"; sc.GraphRegion = 0; sc.AutoLoop = 1; CAMA.Name = "CAMA"; CAMA.PrimaryColor = RGB(70, 187, 241); CAMA.DrawStyle = DRAWSTYLE_LINE; CAMA.LineWidth = 4; Length.Name = "Length"; Length.SetInt(20); Length.SetIntLimits(1, MAX_STUDY_LENGTH); Source.Name = "Source"; Source.SetInputDataIndex(SC_LAST); return; } int length = Length.GetInt(); int sourceIndex = Source.GetInputDataIndex(); sc.DataStartIndex = length - 1; float result = 0.0f, effort = 0.0f, smoothingFactor = 0.0f, cama = 0.0f; SCFloatArray source = sc.BaseDataIn[sourceIndex]; result = sc.GetHighest(sc.High, length, sc.Index) - sc.GetLowest(sc.Low, length, sc.Index); effort = sc.GetSummation(sc.TrueRange, length, sc.Index); if (effort != 0.0f) { smoothingFactor = result / effort; } else { smoothingFactor = 0.0f; } cama = smoothingFactor * source[sc.Index] + (1.0f - smoothingFactor) * CAMA.Arrays[0][sc.Index - 1]; CAMA.Arrays[0][sc.Index] = cama; if (CAMA.Arrays[0][sc.Index] >= CAMA.Arrays[0][sc.Index - 1]) { CAMA.DataColor[sc.Index] = RGB(70, 187, 241); } else { CAMA.DataColor[sc.Index] = RGB(231, 19, 136); } CAMA[sc.Index] = CAMA.Arrays[0][sc.Index]; } Pine Script: //Copyright © 2023, Centaur //@version=5 indicator(title = "Cong Adaptive Moving Average", shorttitle="CAMA", overlay=true, timeframe="", timeframe_gaps=true) length = input(title="Length", defval=20) src = input(close, title="Source") result = 0.0, effort = 0.0, smoothing_factor = 0.0, cama = 0.0 result := ta.highest(high, length) - ta.lowest(low, length) effort := math.sum(ta.tr, length) smoothing_factor := result / effort cama := smoothing_factor * src + (1 - smoothing_factor) * nz(cama[1]) plot(cama,"CAMA",color = cama >= cama[1] ? color.rgb(70, 187, 241) : color.rgb(231, 19, 136),linewidth = 4) Date Time Of Last Edit: 2023-04-04 07:46:24
|