Support Board
Date/Time: Sun, 24 Nov 2024 14:06:37 +0000
code help
View Count: 287
[2024-06-01 23:07:44] |
User411320 - Posts: 289 |
Hello, I'm not a developer but I'm trying to write a code for sierra and can't figure out what I'm doing wrong. Any help would be greatly appreciated The top of every source code file must include this line
#include "sierrachart.h" // For reference, refer to this page: // Advanced Custom Study Interface and Language (ACSIL) // This line is required. Change the text within the quote // marks to what you want to name your group of custom studies. SCDLLName("Ocean") //This is the basic framework of a study function. Change the name 'TemplateFunction' to what you require. SCSFExport scsf_TemplateFunction(SCStudyInterfaceRef sc) { // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { #include <iostream> #include <vector> #include <cmath> // Function to calculate EMA std::vector<double> calculateEMA(const std::vector<double>& values, int length) { std::vector<double> ema(values.size()); double alpha = 2.0 / (length + 1); ema[0] = values[0]; // Initialize the first value of EMA with the first value in the series for (size_t i = 1; i < values.size(); ++i) { ema[i] = alpha * values[i] + (1 - alpha) * ema[i - 1]; } return ema; } int main() { // Example source data (e.g., closing prices) std::vector<double> src = {1.0, 1.1, 1.2, 1.3, 1.4, 1.5}; // Replace with actual data int length = 14; // Length period // Step 1: Calculate ln (logarithm of source data scaled by 1000) std::vector<double> ln(src.size()); for (size_t i = 0; i < src.size(); ++i) { ln[i] = std::log(src[i]) * 1000; } // Step 2: Calculate oi std::vector<double> oi(src.size(), 0.0); // Initialize with zeros for (size_t i = 1; i < src.size(); ++i) { oi[i] = (ln[i] - ln[i - 1]) * 100; } // Step 3: Calculate nmrSum std::vector<double> nmrSum(src.size(), 0.0); for (size_t i = 0; i < src.size(); ++i) { if (i > 0) { nmrSum[i] = nmrSum[i - 1] + oi[i] * (std::sqrt(i + 1) - std::sqrt(i)); } else { nmrSum[i] = oi[i] * std::sqrt(1); } } // Step 4: Calculate the first EMA of nmrSum std::vector<double> ema1 = calculateEMA(nmrSum, length); // Step 5: Calculate the second EMA of the first EMA std::vector<double> ema2 = calculateEMA(ema1, length); // Output the result for (size_t i = 0; i < ema2.size(); ++i) { std::cout << "ema2[" << i << "] = " << ema2[i] << std::endl; } return 0; } // Section 2 - Do data processing here } |
[2024-06-02 11:32:46] |
User431178 - Posts: 541 |
Suggest looking at the examples that can be found in the ACS_Source folder of your Sierra Chart installation. Once you've done that you should have a better idea of how to structure the study. Information here: How to Build an Advanced Custom Study from Source Code: Searching for Source Code for Sierra Chart Built-In Studies An example of what you can expect to find is shown below, there are 100's of examples in the various files. /*============================================================================ This study displays the simple, exponential, and adaptive moving averages. ----------------------------------------------------------------------------*/ SCSFExport scsf_MovingAverageExample1(SCStudyInterfaceRef sc) { SCSubgraphRef Subgraph_SimpleMA = sc.Subgraph[0]; SCSubgraphRef Subgraph_ExponentialMA = sc.Subgraph[1]; SCSubgraphRef Subgraph_AdaptiveMA = sc.Subgraph[2]; // Set configuration variables if (sc.SetDefaults) { // Set defaults sc.GraphName = "Moving Average Example 1"; sc.StudyDescription = ""; sc.GraphRegion = 0; Subgraph_SimpleMA.Name = "Simple Moving Average"; Subgraph_SimpleMA.DrawStyle = DRAWSTYLE_LINE; Subgraph_SimpleMA.PrimaryColor = RGB(0,255,0); Subgraph_ExponentialMA.Name = "Exponential Moving Average"; Subgraph_ExponentialMA.DrawStyle = DRAWSTYLE_LINE; Subgraph_ExponentialMA.PrimaryColor = RGB(255,0,255); Subgraph_AdaptiveMA.Name = "Adaptive Moving Average"; Subgraph_AdaptiveMA.DrawStyle = DRAWSTYLE_LINE; Subgraph_AdaptiveMA.PrimaryColor = RGB(255,255,0); sc.AutoLoop = 1; return; } // Do data processing // Simple moving average in the first subgraph sc.SimpleMovAvg(sc.Close, Subgraph_SimpleMA, 10); // Exponential moving average in the second subgraph sc.ExponentialMovAvg(sc.Close, Subgraph_ExponentialMA, 10); // Adaptive moving average in the third subgraph sc.AdaptiveMovAvg(sc.Close, Subgraph_AdaptiveMA, 10, 2.0f, 30.0f); } |
[2024-06-02 19:03:04] |
User411320 - Posts: 289 |
thanks will do
|
To post a message in this thread, you need to log in with your Sierra Chart account: