Support Board
Date/Time: Sat, 30 Nov 2024 05:28:03 +0000
[Programming Help] - ACSIL study in real-time vs slow market replay
View Count: 802
[2022-12-08 16:05:36] |
User907967 - Posts: 54 |
Hi support team, I have played with a code that transforms DRAWING_RECTANGLE_EXT_HIGHLIGHT drawings into DRAWING_RECTANGLEHIGHLIGHT s_UseTool items, when the latest price cuts across the entire height of an item. When I am satisfied that sc.High[sc.Index] > Tool.BeginValue (and equally to the lower side), I am setting EndDateTime to become sc.Index and convert from the former to the latter s_UseTool type. Here are some of the definitions of the study: sc.AutoLoop = 1;
sc.UpdateAlways = 1; When I use replay mode, everything works well. When I load the study in real-time, occasionally, it processes the change at the next candle. The example below is brilliant because I have three shapes, and the price crosses across all of them. The first and third transition well, yet the second one transitions at the next candle. Thoughts? |
Screenshot 2022-12-08 154546.png / V - Attached On 2022-12-08 16:03:51 UTC - Size: 79.73 KB - 149 views Screenshot 2022-12-08 154734.png / V - Attached On 2022-12-08 16:03:55 UTC - Size: 86.84 KB - 214 views |
[2022-12-08 18:21:11] |
John - SC Support - Posts: 36350 |
The only thing that we can think of as to why you would see a difference between Replay and Real-Time is the type of Replay you are running. Particularly if you are using "Calculate at Every Tick/Trade", which would call your study more often than real-time. You would want to use "Standard Replay" to be the most realistic. From there, it will depend on your code as to what is occurring and why. For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2022-12-09 08:20:27] |
User907967 - Posts: 54 |
Thank you for your message. The problem I am raising is not the Market Reply method. The study does cut the s_UseTool items correctly if I use Market Reply. I don't understand why the logic behind the study fails for some of the past candles if I load the study in real-time. New candles will be processed correctly as well if I leave the study on for several minutes/hours, but some past candles are affected. I simplified the code to the bare minimum to identify the issue. I am still investigating.
|
[2022-12-09 14:41:38] |
John - SC Support - Posts: 36350 |
If it is not working as expected then it is related to the code and we have no way to know what exactly the problem may be. We also do not give Programming Help.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2022-12-09 22:34:55] |
User907967 - Posts: 54 |
Hi support -- please note I am not asking for programming support as such. I am raising a bug. I have a series of DRAWING_RECTANGLE_EXT_HIGHLIGHT shapes, and I am converting them all to DRAWING_RECTANGLEHIGHLIGHT using the same code as soon as the candle crosses them completely. Here's another example: one is closed on the next candle. If I test this in any market reply modes, the results are correct, i.e. all DRAWING_RECTANGLEHIGHLIGHT shapes end on the same candle. It seems to have something to do with the shapes if they overlap. If one shape overlaps another, the one that overlaps is printed on the next candle rather than the first one.
Date Time Of Last Edit: 2022-12-09 22:40:41
|
Screenshot 2022-12-09 223351.png / V - Attached On 2022-12-09 22:34:34 UTC - Size: 13.99 KB - 98 views |
[2022-12-11 12:10:10] |
User907967 - Posts: 54 |
Hi support, I've converted the drawing method from ACS to UserDrawing in the hope that the type of drawing is the reason for the bug, but the outcome is the same. Primarily when drawings overlap, something goes wrong when the study loads in real-time. If I leave the study on and allow the new data feed to land naturally, the latest data causes no problems. Also, if I run any market reply method, there are no problems. If it had not worked in the market reply mode, I would have accepted my code as the issue. I simplified the code as much as possible to spot any issues. The only thing I haven't done was to try to run the code with true user drawings, but that defeats the purpose. I need these drawings to be created automatically. Thoughts? |
Screenshot 2022-12-11 120109.png / V - Attached On 2022-12-11 12:03:30 UTC - Size: 142.34 KB - 84 views |
[2022-12-11 12:44:25] |
User431178 - Posts: 545 |
Not support, but I can tell you that I am doing this in multiple studies, using either/both ACS and UserDrawn drawings, and have zero problems. code that transforms DRAWING_RECTANGLE_EXT_HIGHLIGHT drawings into DRAWING_RECTANGLEHIGHLIGHT s_UseTool items, when the latest price cuts across the entire height of an item.
There must be a problem with your code that you are not seeing and it is difficult to offer any advice without actually seeing the code that you are using. If you don't want to share publicly then you are welcome to message directly. |
[2022-12-12 08:06:44] |
User907967 - Posts: 54 |
Thanks for your messages. I narrowed down the source of the issue. If anyone wishes to create a new study with the code below, search for a succession of two candles where [0] is the latest and [1] is the one before the latest, where the latest one is both lower and higher than the one before it, i.e. Low[0]<Low[1] && High[0]>High[1]. You will see the second rectangle (associated with the low end of the latest candle does not end where required. However, if one suspends this code, it will see that the second rectangle does end where it should. /* if (sc.High[Bar]==DrawingObject.BeginValue && sc.GetHighest(sc.High, sc.Index-Bar)>DrawingObject.BeginValue){
DrawingObject2.Clear(); DrawingObject2.BeginDateTime = DrawingObject.BeginDateTime; DrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject2.BeginValue=DrawingObject.BeginValue; DrawingObject2.EndValue=DrawingObject.EndValue; DrawingObject2.SecondaryColor = RGB(200, 100, 220); DrawingObject2.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; sc.UseTool(DrawingObject2); sc.DeleteACSChartDrawing(0, TOOL_DELETE_CHARTDRAWING, DrawingObject.LineNumber); } */ I am sorry to labour the point. Perhaps it has something to do with the use of persistent values. SCSFExport scsf_Demo(SCStudyInterfaceRef sc)
{ // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { sc.GraphName = "Demo"; sc.AutoLoop = 1; sc.UpdateAlways = 1; sc.GraphRegion = 0; return; } // Section 2 - Do data processing here if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED){ if (sc.GetACSDrawingsCount(0, 1) < 100 && sc.Index % 5 == 0){ s_UseTool DrawingObject; DrawingObject.Clear(); DrawingObject.DrawingType = DRAWING_RECTANGLE_EXT_HIGHLIGHT; DrawingObject.BeginDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.EndDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.SecondaryColor = RGB(10, 200, 120); DrawingObject.BeginValue=sc.High[sc.Index]; DrawingObject.EndValue=sc.High[sc.Index]-10; sc.UseTool(DrawingObject); DrawingObject.Clear(); DrawingObject.DrawingType = DRAWING_RECTANGLE_EXT_HIGHLIGHT; DrawingObject.BeginDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.EndDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.SecondaryColor = RGB(100, 20, 50); DrawingObject.BeginValue=sc.Low[sc.Index]+10; DrawingObject.EndValue=sc.Low[sc.Index]; sc.UseTool(DrawingObject); } } s_UseTool DrawingObject; for (int Counter=0; Counter<(sc.GetACSDrawingsCount(sc.ChartNumber, 1)); Counter++){ sc.GetACSDrawingByIndex(sc.ChartNumber, Counter, DrawingObject, 1); int Bar = sc.GetNearestMatchForSCDateTime(sc.ChartNumber, DrawingObject.BeginDateTime.GetAsDouble()); s_UseTool DrawingObject2; if (DrawingObject.DrawingType==DRAWING_RECTANGLE_EXT_HIGHLIGHT){ if (sc.High[Bar]==DrawingObject.BeginValue && sc.GetHighest(sc.High, sc.Index-Bar)>DrawingObject.BeginValue){ DrawingObject2.Clear(); DrawingObject2.BeginDateTime = DrawingObject.BeginDateTime; DrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject2.BeginValue=DrawingObject.BeginValue; DrawingObject2.EndValue=DrawingObject.EndValue; DrawingObject2.SecondaryColor = RGB(200, 100, 220); DrawingObject2.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; sc.UseTool(DrawingObject2); sc.DeleteACSChartDrawing(0, TOOL_DELETE_CHARTDRAWING, DrawingObject.LineNumber); } if (sc.Low[Bar]==DrawingObject.EndValue && sc.GetLowest(sc.Low, sc.Index-Bar)<DrawingObject.EndValue){ DrawingObject2.Clear(); DrawingObject2.BeginDateTime = DrawingObject.BeginDateTime; DrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject2.BeginValue=DrawingObject.BeginValue; DrawingObject2.EndValue=DrawingObject.EndValue; DrawingObject2.SecondaryColor = RGB(50, 150, 110); DrawingObject2.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; sc.UseTool(DrawingObject2); sc.DeleteACSChartDrawing(0, TOOL_DELETE_CHARTDRAWING, DrawingObject.LineNumber); } } } } Date Time Of Last Edit: 2022-12-12 08:14:49
|
Screenshot 2022-12-12 081320.png / V - Attached On 2022-12-12 08:14:40 UTC - Size: 178.55 KB - 94 views Screenshot 2022-12-12 081418.png / V - Attached On 2022-12-12 08:14:44 UTC - Size: 187.2 KB - 93 views |
[2022-12-12 11:32:44] |
User431178 - Posts: 545 |
Did you test that sample code before posting.....?
Date Time Of Last Edit: 2022-12-12 11:32:52
|
rectangles.png / V - Attached On 2022-12-12 11:32:37 UTC - Size: 40.39 KB - 98 views |
[2022-12-12 16:03:37] |
User907967 - Posts: 54 |
I apologise unreservedly; I forgot to mention -- please load using 8000V on NQ. Of course, I tested the script before posting. I forgot to mention the period. I am sharing two new screenshots, one with the complete view and another with an example of where the issue occurs. For clarity, the problem is rare and is described above in my detailed post.
|
Screenshot 2022-12-12 154903.png / V - Attached On 2022-12-12 15:52:20 UTC - Size: 704.86 KB - 88 views Screenshot 2022-12-12 155044.png / V - Attached On 2022-12-12 15:52:24 UTC - Size: 194.5 KB - 87 views |
[2022-12-12 16:24:22] |
User431178 - Posts: 545 |
Whatever the original problem, the sample code is not working correctly (even applied to 8kV chart), see image. So how can possibly help with actual problem when sample is not working? |
rectangles.png / V - Attached On 2022-12-12 16:22:18 UTC - Size: 41.96 KB - 85 views |
[2022-12-12 19:01:47] |
User907967 - Posts: 54 |
Genuinely don’t know why it behaves like that on your instance. I’m compiling it remotely, using the latest instance of SC. Perhaps support can help on both matters.
|
[2022-12-13 02:02:19] |
User907967 - Posts: 54 |
Mystery solved. If one attempts to process two drawings with the same starting bar, if using the above code, somehow, by the time the second drawing is reviewed sc.Index is incremented. I don't know why this happens because, as I said, the replay mode causes no issues. So I amended this: DrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.Index];
into thisDrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.GetIndexOfHighestValue(sc.High, sc.Index-Bar)]; orDrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.GetIndexOfLowestValue(sc.Low, sc.Index-Bar)]; Depending on the case.All in all, here is the demo code for those that hit the same thread. SCSFExport scsf_Demo(SCStudyInterfaceRef sc)
{ // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { sc.GraphName = "Demo"; sc.AutoLoop = 1; sc.UpdateAlways = 1; sc.GraphRegion = 0; return; } // Section 2 - Do data processing here if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED){ if (sc.GetACSDrawingsCount(0, 1) < 100 && sc.Index % 5 == 0){ s_UseTool DrawingObject; DrawingObject.Clear(); DrawingObject.DrawingType = DRAWING_RECTANGLE_EXT_HIGHLIGHT; DrawingObject.BeginDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.EndDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.SecondaryColor = RGB(10, 200, 120); DrawingObject.BeginValue=sc.High[sc.Index]; DrawingObject.EndValue=sc.High[sc.Index]-10; sc.UseTool(DrawingObject); DrawingObject.Clear(); DrawingObject.DrawingType = DRAWING_RECTANGLE_EXT_HIGHLIGHT; DrawingObject.BeginDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.EndDateTime = sc.BaseDateTimeIn[sc.Index]; DrawingObject.SecondaryColor = RGB(100, 20, 50); DrawingObject.BeginValue=sc.Low[sc.Index]+10; DrawingObject.EndValue=sc.Low[sc.Index]; sc.UseTool(DrawingObject); } } s_UseTool DrawingObject; for (int Counter=0; Counter<(sc.GetACSDrawingsCount(sc.ChartNumber, 1)); Counter++){ sc.GetACSDrawingByIndex(sc.ChartNumber, Counter, DrawingObject, 1); int Bar = sc.GetNearestMatchForSCDateTime(sc.ChartNumber, DrawingObject.BeginDateTime.GetAsDouble()); s_UseTool DrawingObject2; if (DrawingObject.DrawingType==DRAWING_RECTANGLE_EXT_HIGHLIGHT){ if (sc.High[Bar]==DrawingObject.BeginValue && sc.GetHighest(sc.High, sc.Index-Bar)>DrawingObject.BeginValue){ DrawingObject2.Clear(); DrawingObject2.BeginDateTime = DrawingObject.BeginDateTime; DrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.GetIndexOfHighestValue(sc.High, sc.Index-Bar)]; DrawingObject2.BeginValue=DrawingObject.BeginValue; DrawingObject2.EndValue=DrawingObject.EndValue; DrawingObject2.SecondaryColor = RGB(200, 100, 220); DrawingObject2.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; DrawingObject2.Text = Text; DrawingObject2.Color = RGB(200, 100, 220); sc.UseTool(DrawingObject2); sc.DeleteACSChartDrawing(0, TOOL_DELETE_CHARTDRAWING, DrawingObject.LineNumber); } if (sc.Low[Bar]==DrawingObject.EndValue && sc.GetLowest(sc.Low, sc.Index-Bar)<DrawingObject.EndValue){ DrawingObject2.Clear(); DrawingObject2.BeginDateTime = DrawingObject.BeginDateTime; DrawingObject2.EndDateTime = sc.BaseDateTimeIn[sc.GetIndexOfLowestValue(sc.Low, sc.Index-Bar)]; DrawingObject2.BeginValue=DrawingObject.BeginValue; DrawingObject2.EndValue=DrawingObject.EndValue; DrawingObject2.SecondaryColor = RGB(50, 150, 110); DrawingObject2.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; DrawingObject2.Text = Text; DrawingObject2.Color = RGB(200, 100, 220); sc.UseTool(DrawingObject2); sc.DeleteACSChartDrawing(0, TOOL_DELETE_CHARTDRAWING, DrawingObject.LineNumber); } } } } Wishing everyone a productive rest of the week. Date Time Of Last Edit: 2022-12-13 02:03:08
|
To post a message in this thread, you need to log in with your Sierra Chart account: