Support Board
Date/Time: Thu, 28 Nov 2024 20:49:57 +0000
[Programming Help] - ACSIL help please. :)
View Count: 1270
[2023-03-30 00:11:58] |
TriStar Trading - Posts: 142 |
I am trying to determine if the delta difference for the current bar is the greatest amount of difference over the last X number of bars. The hitch I am running in to is that if the current bars delta is positive I only want to compare that to X number of positive delta difference bars lokking backwards. So I'm trying to compare positve delta to only positive delta and negative delta to only negative delta. I have this mostly working in a For loop but looping back I don't know how distinguish the positive and negative delta dif bars so as not increment the counter for example if the current bar is positive delta dif and a bar looking back is negative delta. If this is the case I would want to skip that bar and not increment the counter. Right now it only goes back X number of bars regardless of positive ir negative delta dif. Thanks! Mike
|
[2023-03-30 00:47:18] |
ondafringe - Posts: 286 |
Not sure if I understood that completely, but read up on 2-dim arrays and see if that might work for you.
Date Time Of Last Edit: 2023-03-30 01:26:46
|
[2023-03-30 05:07:35] |
TriStar Trading - Posts: 142 |
Thanks. I was thinking along those lines. Like maybe looping through the whole array and creating an array of positive delta difs and an array of negative delta difs. Then it would be simple enough to look back X number of items without the need to bypass an item.
|
[2023-03-30 13:53:49] |
ondafringe - Posts: 286 |
You don't actually need two arrays, just one with two dimensions. First dimension contains two elements, one for positive D and one for negative D. Second dimension contains X sub-elements for the look-back period. At the end of every bar, you could use a for-loop to move each sub-element value back one place (9 to 10, 8 to 9... 1 to 2, 0 to 1), then put the current bar's value into the first sub-element at 0. That would give you a rolling X bar look-back period.
Date Time Of Last Edit: 2023-03-30 14:07:10
|
[2023-03-30 14:20:29] |
User907968 - Posts: 823 |
Example: Count back over previous bars until you have 5 positive delta bars // manual looping example for (auto index = sc.UpdateStartIndex; index < sc.ArraySize; index++) { auto i = index; auto countPos{ 0 }; // start at current index and decrement index value // until when we have reached 5 pos delta bars // or until index 0 is reached while (i > 0 && countPos < 5) { if (sc.AskVolume[i] > sc.BidVolume[i]) countPos++; i--; } } |
[2023-03-31 04:52:36] |
TriStar Trading - Posts: 142 |
Thanks so much for the guidance ondafringe and User907968. I think I have the study working but its late and I want to test a bit yet. Once I have the code commented properly I'll share. Thanks again! Mike
|
[2023-03-31 18:56:02] |
TriStar Trading - Posts: 142 |
Here is the finished product. Thanks again for the help. Likely there are more efficient ways to do this. I'm newer to c++. Started coding with COBOL. LOL! Mike // Description: This study looks back the inputed number of bars to find the highest
https://www.sierrachart.com/image.php?Image=1680288699272.png// positive delta or the lowest negative delta for a price bar. It compares only a // current positive delta bar to positive delta bars or a current negative delta bar // to negative delta bars. If the current price bar has positive delta // greater than any individual price bar positive delta in the lookback range the // current bar is deemed extreme positive delta. If the current price bar has negative // delta less than any individual price bar negative delta in the lookback range the // current bar is deemed extreme negative delta. Also, if a current price bar is an up bar // with negative delta a negative divergence signal is set. If a current price bar is a // down bar with positive delta a positive divergence signal is set. // This line is required at the top of every source code file. #include "sierrachart.h" // This line is required. The name of the group of custom studies. SCDLLName("TriStar_ExtDeltaDifSignals_v3") // This line is required. The name of the custom study. SCSFExport scsf_ExtDeltaDifSignals_v3(SCStudyInterfaceRef sc) { // Section 1 - Set the configuration variables and defaults. SCSubgraphRef PosDeltaExtreme = sc.Subgraph[0]; SCSubgraphRef NegDeltaExtreme = sc.Subgraph[1]; SCSubgraphRef ZeroLine = sc.Subgraph[2]; SCSubgraphRef BullDivergence = sc.Subgraph[3]; SCSubgraphRef BearDivergence = sc.Subgraph[4]; SCSubgraphRef PosDeltaArray = sc.Subgraph[5]; SCSubgraphRef NegDeltaArray = sc.Subgraph[6]; SCInputRef LookbackNumBars = sc.Input[0]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "TST Extreme DeltaDif Signals v3"; sc.AutoLoop = 0; sc.GraphRegion = 1; // Not Main Region sc.GlobalDisplayStudySubgraphsNameAndValue = 0; sc.DisplayStudyInputValues = 0; sc.ValueFormat = 0; // Define the Subgraphs PosDeltaExtreme.Name = "Positive Delta Extreme"; PosDeltaExtreme.DrawStyle = DRAWSTYLE_COLORBAR; PosDeltaExtreme.PrimaryColor = RGB(226,214,181); // MN Wild Wheat NegDeltaExtreme.Name = "Negative Delta Extreme"; NegDeltaExtreme.DrawStyle = DRAWSTYLE_COLORBAR; NegDeltaExtreme.PrimaryColor = RGB(237,170,0); // MN Wild Gold ZeroLine.Name = "Zero Line"; ZeroLine.DrawStyle = DRAWSTYLE_LINE; ZeroLine.LineStyle = LINESTYLE_SOLID; ZeroLine.LineWidth = 1; ZeroLine.PrimaryColor = COLOR_DIMGRAY; ZeroLine.DrawZeros = true; BullDivergence.Name = "Bull Divergence"; BullDivergence.DrawStyle = DRAWSTYLE_TRIANGLE_UP; BullDivergence.LineWidth = 5; BullDivergence.PrimaryColor = RGB(226,214,181); // MN Wild Wheat BearDivergence.Name = "Bear Divergence"; BearDivergence.DrawStyle = DRAWSTYLE_TRIANGLE_DOWN; BearDivergence.LineWidth = 5; BearDivergence.PrimaryColor = RGB(237,170,0); // MN Wild Gold PosDeltaArray.DrawStyle = DRAWSTYLE_IGNORE; NegDeltaArray.DrawStyle = DRAWSTYLE_IGNORE; // Define the inputs LookbackNumBars.Name = "Number of Lookback Bars"; LookbackNumBars.SetInt(5); LookbackNumBars.SetIntLimits(1, INT_MAX); return; } // manual looping example for (auto index = sc.UpdateStartIndex; index < sc.ArraySize; index++) { // Init required variables int CurrentBarDeltaDif = sc.AskVolume[index] - sc.BidVolume[index]; // Capture the current price bar delta auto i = index-1; // Set the index one bar back to ignore the current bar auto countPos{ 0 }; // Set the while loop position counter to zero // start at current index and decrement index value // until when we have reached 5 pos delta bars // or until index 0 is reached while (i > 0 && countPos < LookbackNumBars.GetInt()) { // Populate the pos/neg delta arrays depending on pos/neg delta of current bar if (CurrentBarDeltaDif > 0 && // Current bar positive delta sc.AskVolume[i] > sc.BidVolume[i]) // Add to array if bar at i is delta positive { PosDeltaArray[countPos] = sc.AskVolume[i] - sc.BidVolume[i]; // Populate the positive array at i countPos++; // Increment the array position counter } else if (CurrentBarDeltaDif < 0 && // Current bar negative delta sc.AskVolume[i] < sc.BidVolume[i]) // Add to array if bar at i is delta negative { NegDeltaArray[countPos] = sc.AskVolume[i] - sc.BidVolume[i]; // Populate the negative array at i countPos++; // Increment the array position counter } i--; // Decrement the while loop index counter } // Init required variables int n = LookbackNumBars.GetInt(); // Get the size of the pos/neg delta array int PosDeltaArrayMax = 0; // Init the positive delta array max variable int NegDeltaArrayMin = 0; // Init the negative delta array min variable // Loop through the delta arrays to get either the max positive bar delta or min negative bar delta for (int pos = 0; pos < n; pos++) { if (CurrentBarDeltaDif > 0 && // Current bar delta GT zero PosDeltaArray[pos] > PosDeltaArrayMax) // Check bar[pos] to see if GT current max delta PosDeltaArrayMax = PosDeltaArray[pos]; // If GT current max delta assign new max delta else if (CurrentBarDeltaDif < 0 && // Current bar delta LT zero NegDeltaArray[pos] < NegDeltaArrayMin) // Check bar[pos] to see if LT current min delta NegDeltaArrayMin = NegDeltaArray[pos]; // If LT current min delta assign new min delta } // Compare the current price bar delta to either the max or min delta array to determine if extreme or not if (CurrentBarDeltaDif > 0) // Current bar has positive delta { if (CurrentBarDeltaDif > PosDeltaArrayMax) // Current bar positive delta is GT max bar delta in lookback range PosDeltaExtreme[index] = 1; // Paint the extreme positive delta signal else // Current bar positive delta is LT/EQ max bar delta in lookback range PosDeltaExtreme[index] = 0; // DO NOT paint the extreme positive delta signal } else if (CurrentBarDeltaDif < 0) // Current bar has negative delta { if (CurrentBarDeltaDif < NegDeltaArrayMin) // Current bar negative delta is LT min bar delta in lookback range NegDeltaExtreme[index] = 1; // Paint the extreme negative delta signal else // Current bar negative delta is GT/EQ min bar delta in lookback range NegDeltaExtreme[index] = 0; // DO NOT paint the extreme negative delta signal } //Calculate delta/price divergences if (sc.AskVolume[index] > sc.BidVolume[index]) //Positive delta { if ( sc.Close[index] < sc.Open[index]) //Down price bar BearDivergence[index] = 1; //Bearish delta/price divergence else BearDivergence[index] = 0; //NOT bearish delta/price divergence } else if (sc.AskVolume[index] < sc.BidVolume[index]) //Negative delta { if (sc.Close[index] > sc.Open[index]) //Up price bar BullDivergence[index] = 1; //Bullish delta/price divergence else BullDivergence[index] = 0; //NOT Bullish delta/price divergence } } } //SCString Message1; //Message1.Format("BivVolatPrice: %f",bidVolumeAtPriceLevel); //sc.AddMessageToLog(Message1,1); |
To post a message in this thread, you need to log in with your Sierra Chart account: