Support Board
Date/Time: Sat, 01 Mar 2025 04:36:54 +0000
Post From: Executing orders at bar close
[2020-12-19 16:40:48] |
User820318 - Posts: 40 |
Many thanks 907968. I havent tested your code but will do now. I ended up writing the below which seems to work. I put all the variables to subgraphs so I could see then update in the spreadsheet and it seems to do the trick. I went down the path of converting various time variables to integers and working with those. Code pasted below for reference - it will draw a line at when there are x (defined in settings) seconds remaining until the bar close. Obvious the stud itself is useless but general idea might serve useful for executingf commands at or before (defined by offset) candle close. #include "sierrachart.h"
SCDLLName("BarTime") SCSFExport scsf_BarTime(SCStudyInterfaceRef sc) { // Inputs SCInputRef CloseOffset = sc.Input[0]; // Outputs SCSubgraphRef BarTime = sc.Subgraph[0]; SCSubgraphRef BarStartTime = sc.Subgraph[1]; SCSubgraphRef CurrentTime = sc.Subgraph[2]; SCSubgraphRef CloseSig = sc.Subgraph[3]; if (sc.SetDefaults) { sc.StudyVersion = 20201219; sc.GraphName = "Bar Time"; sc.AutoLoop = 1; //Automatic looping is enabled. sc.GraphRegion = 0; sc.UpdateAlways = 1; // Set this study to continuously update // Inputs CloseOffset.Name = "Offset from Close (secs)"; CloseOffset.SetInt(1); CloseOffset.SetDescription("CloseOffset"); // Outputs BarTime.Name = "BarTime"; BarTime.DrawStyle = DRAWSTYLE_HIDDEN; BarStartTime.Name = "BarStartTime"; BarStartTime.DrawStyle = DRAWSTYLE_HIDDEN; CurrentTime.Name = "CurrentTime"; CurrentTime.DrawStyle = DRAWSTYLE_HIDDEN; CloseSig.Name = "Signal Bar Close"; CloseSig.DrawStyle = DRAWSTYLE_DASH; CloseSig.PrimaryColor = RGB(221, 160, 221); CloseSig.LineWidth = 2; CloseSig.DrawZeros = false; return; } // Section 2 - Do data processing here // Declare variables int& SecondsPerBar = sc.GetPersistentInt(1); int& NowTime = sc.GetPersistentInt(2); int& BarStart = sc.GetPersistentInt(3); SCDateTime CurrentDateTime; // Price Data at Index float Cl = sc.Close[sc.Index]; // Get the DateTime at the current index. SCDateTime BarDateTime = sc.BaseDateTimeIn[sc.Index]; BarStart = BarDateTime.GetTimeInSeconds(); BarStartTime[sc.Index] = BarStart; // to subgraph // Get bar period n_ACSIL::s_BarPeriod BarPeriod; sc.GetBarPeriodParameters(BarPeriod); if (BarPeriod.ChartDataType == INTRADAY_DATA && BarPeriod.IntradayChartBarPeriodType == IBPT_DAYS_MINS_SECS) { SecondsPerBar = BarPeriod.IntradayChartBarPeriodParameter1; } BarTime[sc.Index] = SecondsPerBar; // to subgraph // Get current time if (sc.IsReplayRunning()) CurrentDateTime = sc.CurrentDateTimeForReplay; else CurrentDateTime = sc.CurrentSystemDateTime; NowTime = CurrentDateTime.GetTimeInSeconds(); CurrentTime[sc.Index] = NowTime; // to subgraph if (NowTime >= BarStart + SecondsPerBar - CloseOffset.GetInt()) { CloseSig[sc.Index] = Cl; } } Date Time Of Last Edit: 2020-12-19 16:44:01
|