Support Board
Date/Time: Fri, 22 Nov 2024 18:42:21 +0000
Post From: Input values getting automatically reset
[2013-05-15 21:25:23] |
User76625 - Posts: 49 |
#include "sierrachart.h" SCDLLName("code") SCSFExport scsf_code(SCStudyInterfaceRef sc) { SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0]; SCSubgraphRef BuyExitSubgraph = sc.Subgraph[1]; SCInputRef Enabled = sc.Input[0]; SCInputRef Position = sc.Input[1]; if (sc.SetDefaults) { sc.GraphName = "code"; sc.StudyDescription = "code"; sc.CalculationPrecedence = LOW_PREC_LEVEL; sc.GraphRegion = 0; sc.FreeDLL = 0; BuyEntrySubgraph.Name = "Buy Entry"; BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROWUP; BuyEntrySubgraph.PrimaryColor = RGB(0, 255, 0); BuyEntrySubgraph.LineWidth = 6; BuyEntrySubgraph.DrawZeros = false; BuyExitSubgraph.Name = "Buy Exit"; BuyExitSubgraph.DrawStyle = DRAWSTYLE_ARROWDOWN; BuyExitSubgraph.PrimaryColor = RGB(255, 0, 0); BuyExitSubgraph.LineWidth = 6; BuyExitSubgraph.DrawZeros = false; Enabled.Name = "Enabled"; Enabled.SetYesNo(1); Position.Name = "Open Position?"; Position.SetInt(0); sc.AllowMultipleEntriesInSameDirection = false; sc.MaximumPositionAllowed = 50000; sc.SupportReversals = false; sc.SendOrdersToTradeService = true; sc.AllowOppositeEntryWithOpposingPositionOrOrders = false; sc.SupportAttachedOrdersForTrading = false; sc.CancelAllOrdersOnEntriesAndReversals = false; sc.AllowEntryWithWorkingOrders = true; sc.CancelAllWorkingOrdersOnExit = false; sc.AllowOnlyOneTradePerBar = false; sc.MaintainTradeStatisticsAndTradesData = true; sc.AutoLoop = 1; return; } if (!Enabled.GetYesNo()) return; SCFloatArray SignalOrderArray; sc.GetStudyArrayUsingID(1, 0, SignalOrderArray); SCDateTime DateTime = sc.CurrentSystemDateTime; int CurrentTime = DateTime.GetTime(); int CurrentBarTime = sc.BaseDateTimeIn.TimeAt(sc.Index); s_SCNewOrder EntryOrder; if (Position.GetInt() == 1 && CurrentTime > HMS_TIME(13,50,00)) { sc.FlattenAndCancelAllOrders(); BuyExitSubgraph[sc.Index] = sc.Low[sc.Index]; Position.SetInt(0); } else if (Position.GetInt() == 0 && SignalOrderArray[sc.Index] < 0 && CurrentBarTime < HMS_TIME(13,00,00)) { if (SignalOrderArray[sc.Index] == -2) { EntryOrder.OrderQuantity = (50 / sc.Ask); int Result = sc.BuyEntry(EntryOrder); if (Result > 0) { BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index]; Position.SetInt(1); } } else if (SignalOrderArray[sc.Index] == -1) { EntryOrder.OrderQuantity = (25 / sc.Ask); int Result = sc.BuyEntry(EntryOrder); if (Result > 0) { BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index]; Position.SetInt(1); } } } else if (Position.GetInt() == 1 && SignalOrderArray[sc.Index] > 0) { sc.FlattenPosition(); BuyExitSubgraph[sc.Index] = sc.High[sc.Index]; Position.SetInt(0); } } The idea I'm going for is to have the Position input start at 0, then when an order is triggered, set the Position value to 1, then when exited, set to 0 again. And that works fine in most cases. The issue I'm having is that the study that this study is referencing (the one that provides values for the SignalOrderArray) relies on sc.CurrentSystemDateTime, so if I have to restart SC during the day, it can potentially lose the value that triggered the order in the first place (since the current system time may no longer satisfy the conditions). So, I want to manually set the Position input to 1 if I need to so that this code can exit if the conditions call for that. When I go into the settings for this study and change the input for Position from 0 to 1, it goes right back to 0 without doing anything. I'm likely not understanding how something works, code-wise. |