Support Board
Date/Time: Sun, 24 Nov 2024 03:05:30 +0000
Post From: Who can code this Indi for Sierras ?
[2015-02-12 18:55:47] |
ehlaban - Posts: 50 |
As I don't know Metatrader i looked at http://www.traderji.com/amibroker/74960-triangular-moving-average-tma-bands.html for a reference. But i'm afraid i can't get it correctly coded. The last part is always wrong. Perhaps somebody else can figure it out. // The top of every source code file must include this line #include <math.h> #include "sierrachart.h" // This line is required. Change the text within the quote // marks to what you want to name your group of custom studies. SCDLLName("ehlTMABands") SCSFExport scsf_ehlTMABands(SCStudyInterfaceRef sc) { // Reference the Plots and the inputs SCSubgraphRef midBand = sc.Subgraph[0]; SCSubgraphRef topBand = sc.Subgraph[1]; SCSubgraphRef lowBand = sc.Subgraph[2]; SCFloatArrayRef sma = midBand.Arrays[0]; SCFloatArrayRef iatr = midBand.Arrays[1]; SCInputRef HalfLength = sc.Input[0]; SCInputRef ATRPeriod = sc.Input[1]; if (sc.SetDefaults) { // Section 1 - Set the configuration variables and defaults sc.GraphName = "ehlTMAbands"; // Name in study overview sc.StudyDescription = "TMA Bands Indicator"; sc.GraphRegion = 0; // Set the Chart Region to draw the graph in. Region 0 is the main price graph sc.FreeDLL = 1; // During dev set this flag to 1, so DLL can be rebuilt without restarting Sierra sc.AutoLoop = 0; //Auto looping is enabled. // Reference the Plots and the inputs and define them midBand.Name = "midBand"; midBand.DrawStyle = DRAWSTYLE_LINE; // Look in scconstants.h for other draw styles midBand.PrimaryColor = RGB(0, 128, 0); // Red midBand.LineWidth = 2; topBand.Name = "topBand"; topBand.DrawStyle = DRAWSTYLE_POINT; // Look in scconstants.h for other draw styles topBand.PrimaryColor = RGB(255, 0, 0); // Light Green topBand.LineWidth = 1; lowBand.Name = "lowBand"; lowBand.DrawStyle = DRAWSTYLE_POINT; // Look in scconstants.h for other draw styles lowBand.PrimaryColor = RGB(0, 128, 0); // Green lowBand.LineWidth = 1; HalfLength.Name = "Length"; HalfLength.SetInt(20); HalfLength.SetIntLimits(1, 300); ATRPeriod.Name = "Forecast"; ATRPeriod.SetInt(100); ATRPeriod.SetIntLimits(1, INT_MAX); return; } // Section 2 - Do data processing here float dSum, sumw; int j = 1, k, limit; int intHalfLength = HalfLength.GetInt(); int intATRPeriod = ATRPeriod.GetInt(); limit = sc.ArraySize - 1; for (int i = 0; i < sc.ArraySize; i++) //for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++) { dSum = (intHalfLength + 1) * sc.BaseDataIn[SC_LAST][i]; sumw = (intHalfLength + 1); for (j = 1, k = intHalfLength; j <= intHalfLength; j++, k--) { if (i + j >= sc.ArraySize) break; dSum += k * sc.BaseDataIn[SC_LAST][i + j]; sumw += k; if (j <= i) { dSum += k * sc.BaseDataIn[SC_LAST][i - j]; sumw += k; } } midBand[i] = (dSum / sumw) ; float ATR = sc.Subgraph[4][i]; topBand[i] = midBand[i] + (2 * ATR); lowBand[i] = midBand[i] - (2 * ATR); // ATR; } return; } |