Support Board
Date/Time: Mon, 25 Nov 2024 22:46:03 +0000
Post From: Request for ASCIL Code
[2024-02-01 17:19:24] |
User719760 - Posts: 6 |
I have tried implementing this way but it is placing orders even when I am not in position. Can You please share me the full code. #include "sierrachart.h" SCDLLName("Target with SLs") SCSFExport scsf_TargetStopLossInTicks(SCStudyInterfaceRef sc) { static bool ordersPlaced = false; // Static variable to track if orders have been placed if (sc.SetDefaults) { // Set the study name and other properties sc.GraphName = "Target and Stop Loss in Ticks"; sc.StudyDescription = "Place target and stop loss in ticks for working orders"; sc.AutoLoop = 1; sc.FreeDLL = 1; // Define inputs for target and stop loss in ticks sc.Input[0].Name = "Target in Ticks"; sc.Input[0].SetInt(70); // Set a default value sc.Input[1].Name = "Stop Loss in Ticks"; sc.Input[1].SetInt(40); // Set a default value return; } s_SCPositionData PositionData; if (sc.PositionData.PositionQuantity >= 1) { // Check if orders are already placed if (!ordersPlaced) { // Create an s_SCNewOrder object. s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_LIMIT; NewOrder.TextTag = "Position Taken of 1 Qty"; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; NewOrder.Stop1Offset = sc.Input[1].GetInt() * sc.TickSize; NewOrder.Target1Offset = sc.Input[0].GetInt() * sc.TickSize; // Place the orders sc.SellEntry(NewOrder); sc.BuyEntry(NewOrder); // Set the flag to true to indicate that orders have been placed ordersPlaced = true; } } else { // Reset the flag when there is no position ordersPlaced = false; } } |