Support Board
Date/Time: Fri, 29 Nov 2024 14:42:32 +0000
[Programming Help] - Help with ACSIL
View Count: 287
[2023-02-02 18:34:23] |
User538264 - Posts: 26 |
Hello, I have written this code for one of my studies. The code is working fine after one cycle of crossovers(See the code) is completed and it gives me correct levels. But when I initially apply this to the chart, the values are wrong and only one level is being plotted. What am I missing here? int barsSinceCross(SCConstFloatArrayRef arr, int occurence) { int bars = 1; int reps = 1; for (int i = arr.GetArraySize() - 1; i > 0; i--) { if (arr[i] == 0.0) { bars++; } else if (reps < occurence) { reps++; bars++; } else { break; } } return bars; } SCSFExport scsf_AZA_MACDCrossoverLevels(SCStudyInterfaceRef sc) { /* SCSubgraphRef Buy = sc.Subgraph[0]; SCSubgraphRef Sell = sc.Subgraph[1]; SCSubgraphRef MACDData = sc.Subgraph[2]; */ SCSubgraphRef Subgraph_MACDLine = sc.Subgraph[0]; SCSubgraphRef Subgraph_SignalLine = sc.Subgraph[1]; SCSubgraphRef Subgraph_MACDData = sc.Subgraph[2]; SCSubgraphRef Subgraph_Histogram = sc.Subgraph[3]; SCSubgraphRef Subgraph_MACDCross = sc.Subgraph[4]; SCFloatArrayRef Array_CrossUp = sc.Subgraph[4].Arrays[4]; SCFloatArrayRef Array_CrossDn = sc.Subgraph[4].Arrays[5]; SCInputRef Input_InputData = sc.Input[0]; SCInputRef Input_FastLen = sc.Input[1]; SCInputRef Input_SlowLen = sc.Input[2]; SCInputRef Input_MACDLen = sc.Input[3]; SCInputRef Input_MAType = sc.Input[4]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "AZA MACD Levels Script"; sc.GraphRegion = 1; sc.AutoLoop = 1; /* Buy.Name = "Buy"; Buy.PrimaryColor = RGB(0, 255, 0); // green Buy.DrawStyle = DRAWSTYLE_ARROWUP; Buy.LineWidth = 2; //Width of arrow Buy.DrawZeros = 0; Sell.Name = "Sell"; Sell.DrawStyle = DRAWSTYLE_ARROWDOWN; Sell.PrimaryColor = RGB(255, 0, 0); // red Sell.LineWidth = 2; //Width of arrow Sell.DrawZeros = 0; Subgraph_MACDCross.Name = "Cross"; Subgraph_MACDCross.PrimaryColor = RGB(0, 255, 0); Subgraph_MACDCross.DrawStyle = DRAWSTYLE_ARROWDOWN; Subgraph_MACDCross.LineWidth = 1; */ Subgraph_SignalLine.Name = "Signal Line"; Subgraph_SignalLine.PrimaryColor = RGB(0, 255, 0); Subgraph_SignalLine.DrawStyle = DRAWSTYLE_LINE; Subgraph_SignalLine.LineWidth = 1; Subgraph_MACDLine.Name = "MACD Line"; Subgraph_MACDLine.PrimaryColor = RGB(250, 0, 0); Subgraph_MACDLine.DrawStyle = DRAWSTYLE_LINE; Subgraph_MACDLine.LineWidth = 1; Subgraph_Histogram.Name = "Histogram"; Subgraph_Histogram.PrimaryColor = RGB(255, 255, 0); Subgraph_Histogram.DrawStyle = DRAWSTYLE_BAR; Subgraph_Histogram.LineWidth = 2; Subgraph_Histogram.AutoColoring = AUTOCOLOR_POSNEG; Input_InputData.Name = "Input Data"; Input_InputData.SetInputDataIndex(SC_LAST); Input_FastLen.Name = "Fast Moving Average Length"; Input_FastLen.SetInt(12); Input_FastLen.SetIntLimits(1, MAX_STUDY_LENGTH); Input_SlowLen.Name = "Slow Moving Average Length"; Input_SlowLen.SetInt(26); Input_SlowLen.SetIntLimits(1, MAX_STUDY_LENGTH); Input_MACDLen.Name = "MACD Moving Average Length"; Input_MACDLen.SetInt(9); Input_MACDLen.SetIntLimits(1, MAX_STUDY_LENGTH); Input_MAType.Name = "Moving Average Type"; Input_MAType.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL); return; } if (sc.IsFullRecalculation && sc.Index == 0) sc.ClearAllPersistentData(); // Do data processing sc.MACD(sc.BaseDataIn[Input_InputData.GetInputDataIndex()], Subgraph_MACDData, sc.Index, Input_FastLen.GetInt(), Input_SlowLen.GetInt(), Input_MACDLen.GetInt(), Input_MAType.GetInt()); Subgraph_MACDLine[sc.Index] = Subgraph_MACDData.Data[sc.Index]; Subgraph_SignalLine[sc.Index] = Subgraph_MACDData.Arrays[2][sc.Index]; Subgraph_Histogram[sc.Index] = Subgraph_MACDLine[sc.Index] - Subgraph_SignalLine[sc.Index]; int barsSinceCrossUp = 0; int barsSinceCrossDn = 0; float swingHigh; float swingLow; float &highLevel = sc.GetPersistentFloat(0); float &lowLevel = sc.GetPersistentFloat(1); int swingHighIndex; int swingLowIndex; int &highIndex = sc.GetPersistentInt(2); int &lowIndex = sc.GetPersistentInt(3); if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) { if (sc.CrossOver(Subgraph_SignalLine, Subgraph_MACDLine) == CROSS_FROM_BOTTOM) { Array_CrossDn[sc.Index] = 1; swingHigh = sc.GetHighest(sc.High, sc.Index - barsSinceCross(Array_CrossDn, 1)+1, barsSinceCross(Array_CrossUp, 1) - barsSinceCross(Array_CrossDn, 1)); swingHighIndex = sc.GetIndexOfHighestValue(sc.High, sc.Index - barsSinceCross(Array_CrossDn, 1) + 1, barsSinceCross(Array_CrossUp, 1) - barsSinceCross(Array_CrossDn, 1)); sc.SetPersistentFloat(0, swingHigh); sc.SetPersistentInt(2, swingHighIndex); } else if (sc.CrossOver(Subgraph_SignalLine, Subgraph_MACDLine) == CROSS_FROM_TOP) { Array_CrossUp[sc.Index] = 1; swingLow = sc.GetLowest(sc.Low, sc.Index - barsSinceCross(Array_CrossUp, 1)+1, barsSinceCross(Array_CrossDn, 1) - barsSinceCross(Array_CrossUp, 1)); swingLowIndex = sc.GetIndexOfLowestValue(sc.Low, sc.Index - barsSinceCross(Array_CrossUp, 1) + 1, barsSinceCross(Array_CrossDn, 1) - barsSinceCross(Array_CrossUp, 1)); sc.SetPersistentFloat(1, swingLow); sc.SetPersistentInt(3, swingLowIndex); } else { Array_CrossDn[sc.Index] = 0; Array_CrossUp[sc.Index] = 0; } SCString logText; logText.Format("lowindex = %d \n low = %f \n highindex = %d \n high = %f", lowIndex, lowLevel, highIndex, highLevel); sc.AddMessageToLog(logText, 0); s_UseTool Tool1; int &r_LineNumber = sc.GetPersistentInt(4); //sc.SetPersistentInt(4, 1); if (r_LineNumber != 0) Tool1.LineNumber = r_LineNumber; Tool1.LineNumber = 1; Tool1.ChartNumber = sc.ChartNumber; Tool1.Region = 0; Tool1.DrawingType = DRAWING_HORIZONTAL_RAY; Tool1.DisplayHorizontalLineValue = 1; Tool1.BeginValue = highLevel; Tool1.BeginDateTime = sc.BaseDateTimeIn[highIndex]; Tool1.Color = RGB(255, 0, 0); Tool1.LineWidth = 2; Tool1.AddMethod = UTAM_ADD_OR_ADJUST; sc.UseTool(Tool1); r_LineNumber = Tool1.LineNumber; s_UseTool Tool2; int &s_LineNumber = sc.GetPersistentInt(5); //sc.SetPersistentInt(5, 2); if (s_LineNumber != 0) Tool2.LineNumber = s_LineNumber; Tool2.LineNumber = 2; Tool2.BeginValue = lowLevel; Tool2.BeginDateTime = sc.BaseDateTimeIn[lowIndex]; Tool2.Color = RGB(0, 255, 0); Tool2.ChartNumber = sc.ChartNumber; Tool2.Region = 0; Tool2.DrawingType = DRAWING_HORIZONTAL_RAY; Tool2.DisplayHorizontalLineValue = 1; Tool2.LineWidth = 2; Tool2.AddMethod = UTAM_ADD_OR_ADJUST; sc.UseTool(Tool2); s_LineNumber = Tool2.LineNumber; } else { return; } } Thanks in advance. |
To post a message in this thread, you need to log in with your Sierra Chart account: