Support Board
Date/Time: Fri, 07 Feb 2025 15:01:10 +0000
Post From: ACSIL Custom Study HELP!
[2024-11-23 17:26:36] |
Frostation - Posts: 16 |
Hi SCEng! I am trying to make a custom study that displays the OHLC of candles where an alert condition is true. at present, i have: #include "sierrachart.h" and this works, in that i can choose a drawstyle that displays at the OHLC values ( screenshots attached, i used STAR and only for open prices for ease of visual), but what i wanted was a horiztonal line to display and extend to the right, with a user option of having said lines extend until future intersections, as id like to be able to refer to these OHLC values in color bar based on alert conditions formula, so would need to enable alerts? SCDLLName("Custom Study: OHLC Per Condition with Opening Types and Named Conditions") SCSFExport scsf_DisplayOHLCPerCondition(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "OHLC Per Condition with Opening Types and Named Conditions"; // Configure subgraphs for each condition (OHLC) const char* conditionNames[] = {"BLUEDOT", "REDDOT", "WHITEDOT", "WHITETRIANGLE", "PURPLETRIANGLE", "PURPLEDOT"}; for (int i = 0; i < 6; ++i) { char subgraphName[50]; snprintf(subgraphName, sizeof(subgraphName), "%s Open", conditionNames[i]); sc.Subgraph[i * 4 + 0].Name = subgraphName; sc.Subgraph[i * 4 + 0].DrawStyle = DRAWSTYLE_IGNORE; snprintf(subgraphName, sizeof(subgraphName), "%s High", conditionNames[i]); sc.Subgraph[i * 4 + 1].Name = subgraphName; sc.Subgraph[i * 4 + 1].DrawStyle = DRAWSTYLE_IGNORE; snprintf(subgraphName, sizeof(subgraphName), "%s Low", conditionNames[i]); sc.Subgraph[i * 4 + 2].Name = subgraphName; sc.Subgraph[i * 4 + 2].DrawStyle = DRAWSTYLE_IGNORE; snprintf(subgraphName, sizeof(subgraphName), "%s Close", conditionNames[i]); sc.Subgraph[i * 4 + 3].Name = subgraphName; sc.Subgraph[i * 4 + 3].DrawStyle = DRAWSTYLE_IGNORE; } // Inputs for enabling each condition for (int i = 0; i < 6; ++i) { char inputName[50]; snprintf(inputName, sizeof(inputName), "Enable %s", conditionNames[i]); sc.Input[i].Name = inputName; sc.Input[i].SetYesNo(true); } // Inputs for opening types sc.Input[6].Name = "Enable IVIRAB"; sc.Input[6].SetYesNo(true); sc.Input[7].Name = "Enable IVIRBE"; sc.Input[7].SetYesNo(true); sc.Input[8].Name = "Enable OVIRBVAL"; sc.Input[8].SetYesNo(true); sc.Input[9].Name = "Enable OVIRAVAH"; sc.Input[9].SetYesNo(true); sc.Input[10].Name = "Enable GAPUP"; sc.Input[10].SetYesNo(true); sc.Input[11].Name = "Enable GAPDOWN"; sc.Input[11].SetYesNo(true); sc.AutoLoop = 1; // Automatically process each bar return; } // Access bar data float openPrice = sc.Open[sc.Index]; float highPrice = sc.High[sc.Index]; float lowPrice = sc.Low[sc.Index]; float closePrice = sc.Close[sc.Index]; // Access external subgraphs SCFloatArray id1_sg1, id1_sg2, id8_sg1, id8_sg10, id8_sg12, id8_sg13, id8_sg41; sc.GetStudyArrayUsingID(1, 0, id1_sg1); // ID1 SG1 sc.GetStudyArrayUsingID(1, 1, id1_sg2); // ID1 SG2 sc.GetStudyArrayUsingID(8, 0, id8_sg1); // ID8 SG1 sc.GetStudyArrayUsingID(8, 9, id8_sg10); // ID8 SG10 sc.GetStudyArrayUsingID(8, 11, id8_sg12); // ID8 SG12 sc.GetStudyArrayUsingID(8, 12, id8_sg13); // ID8 SG13 sc.GetStudyArrayUsingID(8, 40, id8_sg41); // ID8 SG41 // Define opening type groups bool upwardOpeningType = sc.Input[7].GetYesNo() || sc.Input[8].GetYesNo() || sc.Input[10].GetYesNo(); bool downwardOpeningType = sc.Input[6].GetYesNo() || sc.Input[9].GetYesNo() || sc.Input[11].GetYesNo(); // Define upward conditions bool condition1 = upwardOpeningType && sc.Input[0].GetYesNo() && sc.Close[sc.Index - 1] > sc.Close[sc.Index - 2] && sc.Close[sc.Index] > id1_sg1[sc.Index] && sc.Close[sc.Index - 1] <= id1_sg1[sc.Index]; bool condition2 = upwardOpeningType && sc.Input[1].GetYesNo() && sc.Close[sc.Index - 1] > sc.Close[sc.Index - 2] && id8_sg1[sc.Index] > 0 && sc.Close[sc.Index] < id1_sg2[sc.Index] && sc.Close[sc.Index - 1] >= id1_sg2[sc.Index]; bool condition3 = upwardOpeningType && sc.Input[2].GetYesNo() && sc.Close[sc.Index] > sc.Open[sc.Index] && id8_sg1[sc.Index] > id8_sg1[sc.Index - 1] && id8_sg41[sc.Index] < id8_sg41[sc.Index - 1] && sc.Low[sc.Index] < sc.Low[sc.Index - 1] && id8_sg10[sc.Index] < 0 && ((id8_sg1[sc.Index] > id8_sg1[sc.Index - 1] && id8_sg10[sc.Index] > id8_sg10[sc.Index - 1]) || (id8_sg12[sc.Index] > id8_sg12[sc.Index - 1] && id8_sg13[sc.Index] > id8_sg13[sc.Index - 1])); // Define downward conditions bool condition4 = downwardOpeningType && sc.Input[3].GetYesNo() && sc.Close[sc.Index - 1] < sc.Close[sc.Index - 2] && sc.Close[sc.Index] < id1_sg2[sc.Index] && sc.Close[sc.Index - 1] >= id1_sg2[sc.Index]; bool condition5 = downwardOpeningType && sc.Input[4].GetYesNo() && sc.Close[sc.Index - 1] < sc.Close[sc.Index - 2] && id8_sg1[sc.Index] < 0 && sc.Close[sc.Index] > id1_sg1[sc.Index] && sc.Close[sc.Index - 1] <= id1_sg1[sc.Index]; bool condition6 = downwardOpeningType && sc.Input[5].GetYesNo() && sc.Close[sc.Index] < sc.Open[sc.Index] && id8_sg1[sc.Index] < id8_sg1[sc.Index - 1] && id8_sg41[sc.Index] > id8_sg41[sc.Index - 1] && sc.High[sc.Index] > sc.High[sc.Index - 1] && id8_sg10[sc.Index] > 0 && ((id8_sg1[sc.Index] < id8_sg1[sc.Index - 1] && id8_sg10[sc.Index] < id8_sg10[sc.Index - 1]) || (id8_sg12[sc.Index] > id8_sg12[sc.Index - 1] && id8_sg13[sc.Index] > id8_sg13[sc.Index - 1])); // Store OHLC values for each condition if (condition1) { sc.Subgraph[0][sc.Index] = openPrice; sc.Subgraph[1][sc.Index] = highPrice; sc.Subgraph[2][sc.Index] = lowPrice; sc.Subgraph[3][sc.Index] = closePrice; } if (condition2) { sc.Subgraph[4][sc.Index] = openPrice; sc.Subgraph[5][sc.Index] = highPrice; sc.Subgraph[6][sc.Index] = lowPrice; sc.Subgraph[7][sc.Index] = closePrice; } if (condition3) { sc.Subgraph[8][sc.Index] = openPrice; sc.Subgraph[9][sc.Index] = highPrice; sc.Subgraph[10][sc.Index] = lowPrice; sc.Subgraph[11][sc.Index] = closePrice; } if (condition4) { sc.Subgraph[12][sc.Index] = openPrice; sc.Subgraph[13][sc.Index] = highPrice; sc.Subgraph[14][sc.Index] = lowPrice; sc.Subgraph[15][sc.Index] = closePrice; } if (condition5) { sc.Subgraph[16][sc.Index] = openPrice; sc.Subgraph[17][sc.Index] = highPrice; sc.Subgraph[18][sc.Index] = lowPrice; sc.Subgraph[19][sc.Index] = closePrice; } if (condition6) { sc.Subgraph[20][sc.Index] = openPrice; sc.Subgraph[21][sc.Index] = highPrice; sc.Subgraph[22][sc.Index] = lowPrice; sc.Subgraph[23][sc.Index] = closePrice; } } Fairly novice with this so help/ corrections most welcome :) Thank you |
![]() |