Support Board
Date/Time: Wed, 08 Oct 2025 06:19:26 +0000
[Programming Help] - code help
View Count: 38
[2025-10-07 20:22:10] |
User411320 - Posts: 345 |
hello all, trying to covert an MQL code to ASCIL and getting the following errors. - Starting remote build of Custom Studies Source files: snr.cpp. 64-bit -- 16:19:14 Allow time for the server to compile the files and build the DLL. Server: https://build.sierrachart.com The remote build is complete. The build failed. In file included from sierrachart.h:23, from snr.cpp:1: snr.cpp: In function 'void scsf_SNR(SCStudyInterfaceRef)': scstructures.h:119:28: error: expected unqualified-id before string constant 119 | #define SCDLLEXPORT extern "C" __declspec(dllexport) | ^~~ scstructures.h:119:28: note: in definition of macro 'SCDLLEXPORT' 119 | #define SCDLLEXPORT extern "C" __declspec(dllexport) | ^~~ snr.cpp:14:1: note: in expansion of macro 'SCDLLName' 14 | SCDLLName("Enhanced Signal-to-Noise Ratio") | ^~~~~~~~~ scstructures.h:119:28: error: expected unqualified-id before string constant 119 | #define SCDLLEXPORT extern "C" __declspec(dllexport) | ^~~ scstructures.h:119:28: note: in definition of macro 'SCDLLEXPORT' 119 | #define SCDLLEXPORT extern "C" __declspec(dllexport) | ^~~ snr.cpp:14:1: note: in expansion of macro 'SCDLLName' 14 | SCDLLName("Enhanced Signal-to-Noise Ratio") | ^~~~~~~~~ scstructures.h:119:28: error: expected unqualified-id before string constant 119 | #define SCDLLEXPORT extern "C" __declspec(dllexport) | ^~~ scstructures.h:119:28: note: in definition of macro 'SCDLLEXPORT' 119 | #define SCDLLEXPORT extern "C" __declspec(dllexport) | ^~~ snr.cpp:16:1: note: in expansion of macro 'SCSFExport' 16 | SCSFExport scsf_EnhancedSNR(SCStudyInterfaceRef sc) | ^~~~~~~~~~ snr.cpp:230:1: error: expected '}' at end of input 230 | } | ^ snr.cpp:10:1: note: to match this '{' 10 | { | ^ Failed to generate the dll file. -- End of Build -- 16:19:17 the following is the code #include "sierrachart.h"
SCDLLName("SNR") SCSFExport scsf_SNR(SCStudyInterfaceRef sc) { // Section 1 - Set the configuration variables and defaults #include "sierrachart.h" SCDLLName("Enhanced Signal-to-Noise Ratio") SCSFExport scsf_EnhancedSNR(SCStudyInterfaceRef sc) { // Input references SCInputRef Alpha = sc.Input[0]; SCInputRef EmaPeriod = sc.Input[1]; SCInputRef SmaPeriod = sc.Input[2]; SCInputRef Level1 = sc.Input[3]; SCInputRef Level2 = sc.Input[4]; // Subgraph references SCSubgraphRef SNR = sc.Subgraph[0]; SCSubgraphRef SMA = sc.Subgraph[1]; SCSubgraphRef EMA = sc.Subgraph[2]; // Internal arrays SCFloatArrayRef Q3 = sc.Subgraph[3].Arrays[0]; SCFloatArrayRef Noise = sc.Subgraph[3].Arrays[1]; SCFloatArrayRef Smooth = sc.Subgraph[3].Arrays[2]; SCFloatArrayRef Detrender = sc.Subgraph[3].Arrays[3]; SCFloatArrayRef I1 = sc.Subgraph[3].Arrays[4]; SCFloatArrayRef Q1 = sc.Subgraph[3].Arrays[5]; SCFloatArrayRef jI = sc.Subgraph[3].Arrays[6]; SCFloatArrayRef jQ = sc.Subgraph[3].Arrays[7]; SCFloatArrayRef I2 = sc.Subgraph[4].Arrays[0]; SCFloatArrayRef Q2 = sc.Subgraph[4].Arrays[1]; SCFloatArrayRef Re = sc.Subgraph[4].Arrays[2]; SCFloatArrayRef Im = sc.Subgraph[4].Arrays[3]; SCFloatArrayRef Per = sc.Subgraph[4].Arrays[4]; SCFloatArrayRef SmoothPeriod = sc.Subgraph[4].Arrays[5]; SCFloatArrayRef Price = sc.Subgraph[4].Arrays[6]; if (sc.SetDefaults) { sc.GraphName = "Enhanced Signal-to-Noise Ratio"; sc.StudyDescription = "Enhanced SNR with Hilbert Transform and adaptive period detection"; sc.AutoLoop = 0; sc.GraphRegion = 1; // Input defaults Alpha.Name = "Alpha (Smoothing)"; Alpha.SetFloat(0.33f); Alpha.SetFloatLimits(0.01f, 1.0f); EmaPeriod.Name = "EMA Period"; EmaPeriod.SetFloat(3.0f); EmaPeriod.SetFloatLimits(1.0f, 100.0f); SmaPeriod.Name = "SMA Period"; SmaPeriod.SetInt(12); SmaPeriod.SetIntLimits(1, 200); Level1.Name = "Level 1"; Level1.SetFloat(6.0f); Level2.Name = "Level 2"; Level2.SetFloat(0.0f); // Subgraph settings SNR.Name = "SNR"; SNR.DrawStyle = DRAWSTYLE_LINE; SNR.PrimaryColor = RGB(128, 128, 128); // Dark Gray SNR.LineWidth = 1; SNR.DrawZeros = false; SMA.Name = "SMA"; SMA.DrawStyle = DRAWSTYLE_DASH; SMA.PrimaryColor = RGB(255, 215, 0); // Gold SMA.LineWidth = 1; SMA.DrawZeros = false; EMA.Name = "EMA"; EMA.DrawStyle = DRAWSTYLE_LINE; EMA.PrimaryColor = RGB(30, 144, 255); // Dodger Blue EMA.LineWidth = 2; EMA.DrawZeros = false; return; } // Section 2 - Do data processing here // Calculation int MinBar = 7; int StartIndex = sc.UpdateStartIndex; if (StartIndex < MinBar) StartIndex = MinBar; for (int i = StartIndex; i < sc.ArraySize; i++) { // Calculate median price Price[i] = (sc.High[i] + sc.Low[i]) / 2.0f; // Hilbert Transform calculation if (i >= 6) { // Smooth price Smooth[i] = (4.0f * Price[i] + 3.0f * Price[i-1] + 2.0f * Price[i-2] + Price[i-3]) / 10.0f; if (i >= 6 && Per[i-1] > 0) { // Detrender Detrender[i] = (0.0962f * Smooth[i] + 0.5769f * Smooth[i-2] - 0.5769f * Smooth[i-4] - 0.0962f * Smooth[i-6]) * (0.075f * Per[i-1] + 0.54f); // InPhase and Quadrature components Q1[i] = (0.0962f * Detrender[i] + 0.5769f * Detrender[i-2] - 0.5769f * Detrender[i-4] - 0.0962f * Detrender[i-6]) * (0.075f * Per[i-1] + 0.54f); I1[i] = Detrender[i-3]; // Advance phase by 90 degrees jI[i] = (0.0962f * I1[i] + 0.5769f * I1[i-2] - 0.5769f * I1[i-4] - 0.0962f * I1[i-6]) * (0.075f * Per[i-1] + 0.54f); jQ[i] = (0.0962f * Q1[i] + 0.5769f * Q1[i-2] - 0.5769f * Q1[i-4] - 0.0962f * Q1[i-6]) * (0.075f * Per[i-1] + 0.54f); // Phasor Addition I2[i] = I1[i] - jQ[i]; Q2[i] = Q1[i] + jI[i]; // Smooth I and Q components I2[i] = 0.2f * I2[i] + 0.8f * I2[i-1]; Q2[i] = 0.2f * Q2[i] + 0.8f * Q2[i-1]; // Homodyne Discriminator Re[i] = I2[i] * I2[i-1] + Q2[i] * Q2[i-1]; Im[i] = I2[i] * Q2[i-1] - Q2[i] * I2[i-1]; Re[i] = 0.2f * Re[i] + 0.8f * Re[i-1]; Im[i] = 0.2f * Im[i] + 0.8f * Im[i-1]; // Calculate period if (Im[i] != 0 && Re[i] != 0) Per[i] = 2.0f * (float)M_PI / atan(Im[i] / Re[i]); else Per[i] = Per[i-1]; // Limit period changes if (Per[i] > 1.5f * Per[i-1]) Per[i] = 1.5f * Per[i-1]; if (Per[i] < 0.67f * Per[i-1]) Per[i] = 0.67f * Per[i-1]; if (Per[i] < 6) Per[i] = 6; if (Per[i] > 50) Per[i] = 50; Per[i] = 0.2f * Per[i] + 0.8f * Per[i-1]; SmoothPeriod[i] = Alpha.GetFloat() * Per[i] + (1.0f - Alpha.GetFloat()) * SmoothPeriod[i-1]; } else { Per[i] = 10.0f; SmoothPeriod[i] = 10.0f; } // Calculate Q3 Q3[i] = 0.5f * (Smooth[i] - Smooth[i-2]) * (0.1759f * SmoothPeriod[i] + 0.4607f); // Calculate I3 int sp = (int)ceil(SmoothPeriod[i] / 2.0f); if (sp == 0) sp = 1; if (sp > i) sp = i; float i3 = 0.0f; for (int j = 0; j < sp; j++) { i3 += Q3[i-j]; } i3 = (1.57f * i3) / (float)sp; // Calculate signal and noise float signal = pow(i3, 2) + pow(Q3[i], 2); Noise[i] = 0.1f * pow((sc.High[i] - sc.Low[i]), 2) * 0.25f + 0.9f * Noise[i-1]; // Calculate SNR if (Noise[i] != 0.0f && signal != 0.0f) { SNR[i] = Alpha.GetFloat() * (10.0f * log10(signal / Noise[i])) + (1.0f - Alpha.GetFloat()) * SNR[i-1]; } else { SNR[i] = SNR[i-1]; } } // Calculate SMA if (i >= SmaPeriod.GetInt() - 1) { float sum = 0.0f; for (int j = 0; j < SmaPeriod.GetInt(); j++) { sum += SNR[i-j]; } SMA[i] = sum / (float)SmaPeriod.GetInt(); } // Calculate EMA if (i == MinBar) { EMA[i] = SNR[i]; } else { float emaAlpha = 2.0f / (1.0f + EmaPeriod.GetFloat()); EMA[i] = emaAlpha * SNR[i] + (1.0f - emaAlpha) * EMA[i-1]; } } // Set reference lines sc.Subgraph[0].LineLabel = SC_LL_DISPLAY_VALUE | SC_LL_VALUE_ALIGN_VALUES_SCALE; sc.Subgraph[1].LineLabel = SC_LL_DISPLAY_VALUE | SC_LL_VALUE_ALIGN_VALUES_SCALE; sc.Subgraph[2].LineLabel = SC_LL_DISPLAY_VALUE | SC_LL_VALUE_ALIGN_VALUES_SCALE; } the following is the original code #property indicator_buffers 3
#property indicator_color1 clrDarkGray #property indicator_color2 clrGold #property indicator_color3 clrDodgerBlue #property indicator_width3 2 #property indicator_style2 STYLE_DOT #property indicator_levelcolor clrSlateGray #property indicator_levelstyle STYLE_DOT input double Alpha = 0.33; //Default 0.33 input double EmaPeriod = 3.0; input int SmaPeriod = 12; input double Level1 = 6.0; input double Level2 = 0.0; double snr[]; double sma[]; double q3[], noise[]; double ema[]; double Smooth[], Detrender[], I1[], Q1[], jI[], jQ[], I2[], Q2[], Re[], Im[], Per[], SmoothPeriod[], price[]; static int MINBAR = 7; int OnInit() { IndicatorBuffers(18); SetIndexBuffer(0,snr,INDICATOR_DATA); SetIndexBuffer(1,sma,INDICATOR_DATA); SetIndexBuffer(2,ema,INDICATOR_DATA); SetIndexBuffer(3,q3,INDICATOR_CALCULATIONS); SetIndexBuffer(4,noise,INDICATOR_CALCULATIONS); SetIndexBuffer(5,Smooth,INDICATOR_CALCULATIONS); SetIndexBuffer(6,Detrender,INDICATOR_CALCULATIONS); SetIndexBuffer(7,I1,INDICATOR_CALCULATIONS); SetIndexBuffer(8,Q1,INDICATOR_CALCULATIONS); SetIndexBuffer(9,jI,INDICATOR_CALCULATIONS); SetIndexBuffer(10,jQ,INDICATOR_CALCULATIONS); SetIndexBuffer(11,I2,INDICATOR_CALCULATIONS); SetIndexBuffer(12,Q2,INDICATOR_CALCULATIONS); SetIndexBuffer(13,Re,INDICATOR_CALCULATIONS); SetIndexBuffer(14,Im,INDICATOR_CALCULATIONS); SetIndexBuffer(15,Per,INDICATOR_CALCULATIONS); SetIndexBuffer(16,SmoothPeriod,INDICATOR_CALCULATIONS); SetIndexBuffer(17, price, INDICATOR_CALCULATIONS); IndicatorSetDouble(INDICATOR_LEVELVALUE,0,Level1); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,Level2); ArrayInitialize(snr, EMPTY_VALUE); //ArrayInitialize(cf, 0); ArrayInitialize(q3, 0); ArrayInitialize(noise, 0); ArrayInitialize(Smooth,0); ArrayInitialize(Detrender,0); ArrayInitialize(I1,0); ArrayInitialize(Q1,0); ArrayInitialize(jI,0); ArrayInitialize(jQ,0); ArrayInitialize(I2,0); ArrayInitialize(Q2,0); ArrayInitialize(Re,0); ArrayInitialize(Im,0); ArrayInitialize(Per,0); ArrayInitialize(SmoothPeriod,0); ArrayInitialize(price,0); IndicatorSetString(INDICATOR_SHORTNAME,"Enhanced SignalNoiseRatio"+" Alpha :"+DoubleToStr(Alpha,4)); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if(rates_total <= 4) return 0; int i=rates_total-prev_calculated+1; if (i>=rates_total) i=rates_total-1; for (; i>=0 && !_StopFlag; i--){ price[i] = (high[i] + low[i]) / 2; Hilbert(i); GetValue(high, low, i); double sum; for(int z =0; z<SmaPeriod; z++) sum += snr[i+z]; sma[i] = sum/SmaPeriod; double emaalpha =2.0/(1.0+EmaPeriod); ema[i] = emaalpha*snr[i] + (1.0-emaalpha)*ema[i+1]; } return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double ZerroIfEmpty(double value) { if (value >= EMPTY_VALUE || value <= -EMPTY_VALUE) return 0.0; return value; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Hilbert(int i) { Smooth[i] = (4 * price[i] + 3 * price[i + 1] + 2 * price[i + 2] + price[i + 3]) / 10; Detrender[i] = (0.0962 * Smooth[i] + 0.5769 * Smooth[i + 2] - 0.5769 * Smooth[i + 4] - 0.0962 * Smooth[i + 6]) * (0.075 * Per[i + 1] + 0.54); //InPhase and Quadrature components Q1[i] = (0.0962 * Detrender[i] + 0.5769 * Detrender[i + 2] - 0.5769 * Detrender[i + 4] - 0.0962 * Detrender[i + 6]) * (0.075 * Per[i + 1] + 0.54); I1[i] = Detrender[i + 3]; //Advance the phase of I1 and Q1 by 90 degrees jI[i] = (0.0962 * I1[i] + 0.5769 * I1[i + 2] - 0.5769 * I1[i + 4] - 0.0962 * I1[i + 6]) * (0.075 * Per[i + 1] + 0.54); jQ[i] = (0.0962 * Q1[i] + 0.5769 * Q1[i + 2] - 0.5769 * Q1[i + 4] - 0.0962 * Q1[i + 6]) * (0.075 * Per[i + 1] + 0.54); //Phasor Addition I2[i] = I1[i] - jQ[i]; Q2[i] = Q1[i] + jI[i]; //Smooth the I and Q components before applying the discriminator I2[i] = 0.2 * I2[i] + 0.8 * I2[i + 1]; Q2[i] = 0.2 * Q2[i] + 0.8 * Q2[i + 1]; //Homodyne Discriminator Re[i] = I2[i] * I2[i] + Q2[i] * Q2[i + 1]; Im[i] = I2[i] * Q2[i + 1] - Q2[i] * I2[i + 1]; Re[i] = 0.2 * Re[i] + 0.8 * Re[i + 1]; Im[i] = 0.2 * Im[i] + 0.8 * Im[i + 1]; if(Im[i]!=0 && Re[i]!=0) Per[i] = 2 * M_PI / (MathArctan(Im[i] / Re[i]) ); else Per[i] = 0; if(Per[i] > 1.5 * Per[i + 1]) Per[i] = 1.5 * Per[i + 1]; if(Per[i] < 0.67 * Per[i + 1]) Per[i] = 0.67 * Per[i + 1]; if(Per[i] < 6) Per[i] = 6; if(Per[i] > 50) Per[i] = 50; Per[i] = 0.2 * Per[i] + 0.8 * Per[i + 1]; SmoothPeriod[i] = Alpha * Per[i] + (1.0 - Alpha) * SmoothPeriod[i + 1]; //SmoothPeriod[i] = 0.33 * Per[i] + 0.67 * SmoothPeriod[i + 1]; }// void Hilbert(i) //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetValue(const double& h[], const double& l[], int i) { q3[i] = 0.5 * (Smooth[i] - Smooth[i + 2]) * (0.1759 * SmoothPeriod[i] + 0.4607); double i3 = 0.0; int sp = (int)MathCeil(SmoothPeriod[i] / 2); if (sp == 0) sp = 1; for (int j = 0; j < sp; j++) { i3 += q3[j + i]; } i3 = (1.57 * i3) / sp; double signal = MathPow(i3, 2) + MathPow(q3[i], 2); noise[i] = 0.1 * MathPow((h[i] - l[i]), 2) * 0.25 + 0.9 * noise[i + 1]; if (noise[i] != 0.0 && signal != 0) { double s = ZerroIfEmpty(snr[i + 1]); snr[i] = Alpha * (10*MathLog(signal / noise[i]) / MathLog(10)) + (1.0-Alpha) * s; //snr[i] = 0.33 * (10*MathLog(signal / noise[i])) / MathLog(10) + 0.67 * s; } else { snr[i] = 0; } return snr[i]; } //------------------------------------------------------------------- // //------------------------------------------------------------------- // // // void iCleanPoint(int i,double& first[],double& second[]) { if (i>=Bars-3) return; if ((second[i] != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE)) second[i+1] = EMPTY_VALUE; else if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE)) first[i+1] = EMPTY_VALUE; } void iPlotPoint(int i,double& first[],double& second[],double& from[]) { if (i>=Bars-2) return; if (first[i+1] == EMPTY_VALUE) if (first[i+2] == EMPTY_VALUE) { first[i] = from[i]; first[i+1] = from[i+1]; second[i] = EMPTY_VALUE; } else { second[i] = from[i]; second[i+1] = from[i+1]; first[i] = EMPTY_VALUE; } else { first[i] = from[i]; second[i] = EMPTY_VALUE; } } |
[2025-10-08 01:45:54] |
User688525 - Posts: 327 |
See if this works for you: #include "sierrachart.h" SCDLLName("Enhanced Signal-to-Noise Ratio") SCSFExport scsf_EnhancedSNR(SCStudyInterfaceRef sc) { // Input references SCInputRef Alpha = sc.Input[0]; SCInputRef EmaPeriod = sc.Input[1]; SCInputRef SmaPeriod = sc.Input[2]; SCInputRef Level1 = sc.Input[3]; SCInputRef Level2 = sc.Input[4]; // Subgraph references SCSubgraphRef SNR = sc.Subgraph[0]; SCSubgraphRef SMA = sc.Subgraph[1]; SCSubgraphRef EMA = sc.Subgraph[2]; // Internal arrays SCFloatArrayRef Q3 = sc.Subgraph[3].Arrays[0]; SCFloatArrayRef Noise = sc.Subgraph[3].Arrays[1]; SCFloatArrayRef Smooth = sc.Subgraph[3].Arrays[2]; SCFloatArrayRef Detrender = sc.Subgraph[3].Arrays[3]; SCFloatArrayRef I1 = sc.Subgraph[3].Arrays[4]; SCFloatArrayRef Q1 = sc.Subgraph[3].Arrays[5]; SCFloatArrayRef jI = sc.Subgraph[3].Arrays[6]; SCFloatArrayRef jQ = sc.Subgraph[3].Arrays[7]; SCFloatArrayRef I2 = sc.Subgraph[4].Arrays[0]; SCFloatArrayRef Q2 = sc.Subgraph[4].Arrays[1]; SCFloatArrayRef Re = sc.Subgraph[4].Arrays[2]; SCFloatArrayRef Im = sc.Subgraph[4].Arrays[3]; SCFloatArrayRef Per = sc.Subgraph[4].Arrays[4]; SCFloatArrayRef SmoothPeriod = sc.Subgraph[4].Arrays[5]; SCFloatArrayRef Price = sc.Subgraph[4].Arrays[6]; if (sc.SetDefaults) { sc.GraphName = "Enhanced Signal-to-Noise Ratio"; sc.StudyDescription = "Enhanced SNR with Hilbert Transform and adaptive period detection"; sc.AutoLoop = 0; sc.GraphRegion = 1; // Input defaults Alpha.Name = "Alpha (Smoothing)"; Alpha.SetFloat(0.33f); Alpha.SetFloatLimits(0.01f, 1.0f); EmaPeriod.Name = "EMA Period"; EmaPeriod.SetFloat(3.0f); EmaPeriod.SetFloatLimits(1.0f, 100.0f); SmaPeriod.Name = "SMA Period"; SmaPeriod.SetInt(12); SmaPeriod.SetIntLimits(1, 200); Level1.Name = "Level 1"; Level1.SetFloat(6.0f); Level2.Name = "Level 2"; Level2.SetFloat(0.0f); // Subgraph settings SNR.Name = "SNR"; SNR.DrawStyle = DRAWSTYLE_LINE; SNR.PrimaryColor = RGB(128, 128, 128); // Dark Gray SNR.LineWidth = 1; SNR.DrawZeros = false; SMA.Name = "SMA"; SMA.DrawStyle = DRAWSTYLE_DASH; SMA.PrimaryColor = RGB(255, 215, 0); // Gold SMA.LineWidth = 1; SMA.DrawZeros = false; EMA.Name = "EMA"; EMA.DrawStyle = DRAWSTYLE_LINE; EMA.PrimaryColor = RGB(30, 144, 255); // Dodger Blue EMA.LineWidth = 2; EMA.DrawZeros = false; return; } // Section 2 - Do data processing here // Calculation int MinBar = 7; int StartIndex = sc.UpdateStartIndex; if (StartIndex < MinBar) StartIndex = MinBar; for (int i = StartIndex; i < sc.ArraySize; i++) { // Calculate median price Price[i] = (sc.High[i] + sc.Low[i]) / 2.0f; // Hilbert Transform calculation if (i >= 6) { // Smooth price Smooth[i] = (4.0f * Price[i] + 3.0f * Price[i-1] + 2.0f * Price[i-2] + Price[i-3]) / 10.0f; if (i >= 6 && Per[i-1] > 0) { // Detrender Detrender[i] = (0.0962f * Smooth[i] + 0.5769f * Smooth[i-2] - 0.5769f * Smooth[i-4] - 0.0962f * Smooth[i-6]) * (0.075f * Per[i-1] + 0.54f); // InPhase and Quadrature components Q1[i] = (0.0962f * Detrender[i] + 0.5769f * Detrender[i-2] - 0.5769f * Detrender[i-4] - 0.0962f * Detrender[i-6]) * (0.075f * Per[i-1] + 0.54f); I1[i] = Detrender[i-3]; // Advance phase by 90 degrees jI[i] = (0.0962f * I1[i] + 0.5769f * I1[i-2] - 0.5769f * I1[i-4] - 0.0962f * I1[i-6]) * (0.075f * Per[i-1] + 0.54f); jQ[i] = (0.0962f * Q1[i] + 0.5769f * Q1[i-2] - 0.5769f * Q1[i-4] - 0.0962f * Q1[i-6]) * (0.075f * Per[i-1] + 0.54f); // Phasor Addition I2[i] = I1[i] - jQ[i]; Q2[i] = Q1[i] + jI[i]; // Smooth I and Q components I2[i] = 0.2f * I2[i] + 0.8f * I2[i-1]; Q2[i] = 0.2f * Q2[i] + 0.8f * Q2[i-1]; // Homodyne Discriminator Re[i] = I2[i] * I2[i-1] + Q2[i] * Q2[i-1]; Im[i] = I2[i] * Q2[i-1] - Q2[i] * I2[i-1]; Re[i] = 0.2f * Re[i] + 0.8f * Re[i-1]; Im[i] = 0.2f * Im[i] + 0.8f * Im[i-1]; // Calculate period if (Im[i] != 0 && Re[i] != 0) Per[i] = 2.0f * (float)M_PI / atan(Im[i] / Re[i]); else Per[i] = Per[i-1]; // Limit period changes if (Per[i] > 1.5f * Per[i-1]) Per[i] = 1.5f * Per[i-1]; if (Per[i] < 0.67f * Per[i-1]) Per[i] = 0.67f * Per[i-1]; if (Per[i] < 6) Per[i] = 6; if (Per[i] > 50) Per[i] = 50; Per[i] = 0.2f * Per[i] + 0.8f * Per[i-1]; SmoothPeriod[i] = Alpha.GetFloat() * Per[i] + (1.0f - Alpha.GetFloat()) * SmoothPeriod[i-1]; } else { Per[i] = 10.0f; SmoothPeriod[i] = 10.0f; } // Calculate Q3 Q3[i] = 0.5f * (Smooth[i] - Smooth[i-2]) * (0.1759f * SmoothPeriod[i] + 0.4607f); // Calculate I3 int sp = (int)ceil(SmoothPeriod[i] / 2.0f); if (sp == 0) sp = 1; if (sp > i) sp = i; float i3 = 0.0f; for (int j = 0; j < sp; j++) { i3 += Q3[i-j]; } i3 = (1.57f * i3) / (float)sp; // Calculate signal and noise float signal = pow(i3, 2) + pow(Q3[i], 2); Noise[i] = 0.1f * pow((sc.High[i] - sc.Low[i]), 2) * 0.25f + 0.9f * Noise[i-1]; // Calculate SNR if (Noise[i] != 0.0f && signal != 0.0f) { SNR[i] = Alpha.GetFloat() * (10.0f * log10(signal / Noise[i])) + (1.0f - Alpha.GetFloat()) * SNR[i-1]; } else { SNR[i] = SNR[i-1]; } } // Calculate SMA if (i >= SmaPeriod.GetInt() - 1) { float sum = 0.0f; for (int j = 0; j < SmaPeriod.GetInt(); j++) { sum += SNR[i-j]; } SMA[i] = sum / (float)SmaPeriod.GetInt(); } // Calculate EMA if (i == MinBar) { EMA[i] = SNR[i]; } else { float emaAlpha = 2.0f / (1.0f + EmaPeriod.GetFloat()); EMA[i] = emaAlpha * SNR[i] + (1.0f - emaAlpha) * EMA[i-1]; } } // Set reference lines sc.Subgraph[0].LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_VALUES_SCALE; sc.Subgraph[1].LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_VALUES_SCALE; sc.Subgraph[2].LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_VALUES_SCALE; } |
To post a message in this thread, you need to log in with your Sierra Chart account: