Support Board
Date/Time: Fri, 22 Nov 2024 13:25:22 +0000
Input values getting automatically reset
View Count: 1951
[2013-05-15 14:48:02] |
User76625 - Posts: 49 |
I'm having an issue with a value in my code being automatically reset to the default input value anytime I manually try to change it while it's running. It starts at 0 (the default value), then gets changed to different values as the code runs and different things happen. Sometimes I want to change that value manually (through the settings in the Chart Studies window), but then as soon as I hit apply, it automatically changes back to 0. I have a similar setup on another study that's also running and it works fine to manually change the value during the day and it stays the value I changed it to. The only difference I can think of between the two is that the one that reverts back to the default value is used to enter and manage trades. Can you change defaults while the code is actively managing trades? EDIT: Both codes actually revert back to the default if I try to manually change a value - not just the one running trades. Date Time Of Last Edit: 2013-05-15 14:59:41
|
[2013-05-15 19:46:08] |
Sierra Chart Engineering - Posts: 104368 |
Provide us all of the source code that you have that works with the particular Input you are making reference to.
Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2013-05-15 19:46:40
|
[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. |
[2013-05-16 17:27:22] |
Sierra Chart Engineering - Posts: 104368 |
We really cannot offer much help with this since we do not provide programming help. What we can see is that outside of the sc.SetDefaults code block you have lines like this: Position.SetInt(0); This must be what is causing the input to change unexpectedly. Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: