Support Board
Date/Time: Fri, 29 Nov 2024 03:56:49 +0000
[Programming Help] - Acsil SCDateTime
View Count: 620
[2023-03-04 19:30:45] |
Tahir - Posts: 35 |
Hi everyone, I'm trying to write a code that plots overnight low with conditional statement but I cant seem to get my head around SCDateTime variables. this code code doesn't seem to work, it stops plotting too early. If I take the minute out then it plots it at 09 but the minute variable messes things up. Help would be appreciated! SCDateTime BarDateTime = sc.BaseDateTimeIn; int Hour = BarDateTime.GetHour(); int Minute =BarDateTime.GetMinute(); if (Hour < 09 && Minute <30) { if (thisLow < prevLow) { dailyLow= sc.Low; } } |
[2023-03-04 22:27:30] |
ondafringe - Posts: 286 |
Change this: SCDateTime BarDateTime = sc.BaseDateTimeIn;
To this: SCDateTime BarDateTime = sc.BaseDateTimeIn[sc.Index];
But you don't need the minute (depending on what you're trying to accomplish). And your nested "if" doesn't make sense because you haven't assigned anything to those variables. And instead of constantly checking for lows, you might want to consider only checking sc.Low at the end of the bar. Date Time Of Last Edit: 2023-03-04 22:38:36
|
[2023-03-04 23:04:00] |
Tahir - Posts: 35 |
thank you @ondafringe I was using sc.BaseDateTimeIn; as it was in a loop and changing it to sc.Index didn't work. This is part a of a much longer code and it's in a loop with sc.GetBarHasClosedStatus(i)==BHCS_BAR_HAS_CLOSED, and I didn't bother sharing the whole thing. These have been assigned to variables in the code. I realise my logic for finding the low is flawed but I'll rework on that once I figure out this time issue :) So how would I tell it to stop at 0930 without using minutes? you can only use 2 digits for BarDateTime.GetHour() |
[2023-03-05 00:06:07] |
ondafringe - Posts: 286 |
From my perspective, your study is already looping on every tick, so no need to add another loop (assuming that's what you meant). If you want to find the lowest low between 0000 (midnight) and 0930, and if you want to check the low at the end of every bar, and you want it to stop at 0930, you are going to have to use bars that are 1 minute or less in duration. You could create a global bool and set it to true. At the end of every bar, check that bool is true and hour is less than 10. If so, check the low. Then, at 0930, set the bool to false. Edit: If you want to check the lows from one time to another, say, from 2000 to 0930, one way of doing it: Create a global bool and initialize it to false. Create a global float to hold the lowest low and initialize it to 999999. Set up three conditionals: if/else-if/else-if If the hour and minute equals 2000, set the bool to true. Else-If the hour and minute equals 0930, set the bool to false and reset the float to 999999. Else-If the bool is true, check the low. Date Time Of Last Edit: 2023-03-05 16:18:36
|
[2023-03-06 12:39:46] |
Tahir - Posts: 35 |
thank you for that but my question still remains on how to actually do that. whats the code? |
[2023-03-06 13:40:03] |
User907968 - Posts: 823 |
Why not take a look at the source code for "High/Low for Time Period - Extended", you can find it in studies6.cpp. It is an example on similar lines to what you are doing, so you should be able to work it out from that. How to Build an Advanced Custom Study from Source Code |
[2023-03-06 13:44:39] |
Tahir - Posts: 35 |
@user907969 thank you that will do the job :) |
To post a message in this thread, you need to log in with your Sierra Chart account: