Support Board
Date/Time: Sat, 19 Apr 2025 10:35:01 +0000
Post From: C2447 error when compiling Advanced Custom Studies
[2025-03-24 15:04:38] |
cmet - Posts: 689 |
Incorrect study initialization. Not using valid ACSIL members. This is one of the main issues when using GPT to help with ACSIL (along with green check emojis in notes ✅ 😶). Make sure when you use it, you're forcing valid syntax. This is not checked for functionality but it compiles and might get you thinking about the solutions you need: #include "sierrachart.h"
SCDLLName("Trade Logic Strategy"); SCSFExport scsf_TradeLogicStrategy(SCStudyInterfaceRef sc) { //inputs SCInputRef Input_Level = sc.Input[0]; SCInputRef Input_StartTime = sc.Input[1]; SCInputRef Input_Stop = sc.Input[3]; SCInputRef Input_Target = sc.Input[4]; SCInputRef Input_Quantity = sc.Input[5]; if (sc.SetDefaults) { sc.GraphName = "Trade Logic Strategy"; sc.StudyDescription = "Automated strategy using predefined levels and opening range."; sc.AutoLoop = 1; Input_Level.Name = "Predefined Level"; Input_Level.SetFloat(4000.0f); Input_StartTime.Name = "Opening Range Start Time"; Input_StartTime.SetTime(HMS_TIME(9, 30, 0)); sc.Input[2].Name = "Tick Bar Size"; sc.Input[2].SetInt(2000); Input_Stop.Name = "Stop Loss (Ticks)"; Input_Stop.SetInt(10); Input_Target.Name = "Target Profit (Ticks)"; Input_Target.SetInt(20); Input_Quantity.Name = "Order Quantity"; Input_Quantity.SetInt(1); sc.AllowMultipleEntriesInSameDirection = false; sc.MaximumPositionAllowed = 1; sc.SupportReversals = false; sc.SendOrdersToTradeService = false; return; } if (sc.Index == 0) return; float predefinedLevel = Input_Level.GetFloat(); int orderQuantity = Input_Quantity.GetInt(); int stopLossTicks = Input_Stop.GetInt(); int targetProfitTicks = Input_Target.GetInt(); //opening range const int date = sc.BaseDateTimeIn[sc.Index].GetDate(); int& r_LastDate = sc.GetPersistentInt(0); float& r_High = sc.GetPersistentFloat(0); float& r_Low = sc.GetPersistentFloat(1); int& r_OpeningRangeSet = sc.GetPersistentInt(2); //reset range on new session if (date != r_LastDate) { r_LastDate = date; r_OpeningRangeSet = 0; r_High = sc.High[sc.Index]; r_Low = sc.Low[sc.Index]; } //opening range SCDateTime now = sc.BaseDateTimeIn[sc.Index]; SCDateTime openingRangeStartTime = Input_StartTime.GetTime(); SCDateTime openingRangeEndTime = openingRangeStartTime + 3600; if (r_OpeningRangeSet == 0 && now >= openingRangeStartTime && now < openingRangeEndTime) { r_High = sc.High[sc.Index] > r_High ? sc.High[sc.Index] : r_High; r_Low = sc.Low[sc.Index] < r_Low ? sc.Low[sc.Index] : r_Low; } else if (now >= openingRangeEndTime) { r_OpeningRangeSet = 1; } //wait for range set if (r_OpeningRangeSet == 0) return; //trade conditions float lastPrice = sc.Close[sc.Index]; bool isAboveConditions = (lastPrice > predefinedLevel) && (lastPrice > r_High); bool isBelowConditions = (lastPrice < predefinedLevel) && (lastPrice < r_Low); bool tradeConditionsMet = isAboveConditions || isBelowConditions; //execution if (tradeConditionsMet) { s_SCNewOrder NewOrder; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.OrderQuantity = orderQuantity; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; NewOrder.Target1Offset = targetProfitTicks * sc.TickSize; NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT; NewOrder.Stop1Offset = stopLossTicks * sc.TickSize; NewOrder.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP; if (isAboveConditions) sc.BuyEntry(NewOrder); else if (isBelowConditions) sc.SellEntry(NewOrder); } } Date Time Of Last Edit: 2025-03-24 15:05:00
|