#include "sierrachart.h" SCDLLName("VectorAI - Minimal Playback Test") // This is wrong, remove the 'void' as that is already added by SCSFExport // SCSFExport void scsf_VectorAITestPlayback(SCStudyInterfaceRef sc) SCSFExport scsf_VectorAITestPlayback(SCStudyInterfaceRef sc) { SCInputRef ProfitTicks = sc.Input[0]; SCSubgraphRef EntrySignal = sc.Subgraph[0]; if (sc.SetDefaults) { sc.GraphName = "VectorAI - Minimal Playback Test"; sc.StudyDescription = "Simple test: enter long on upward close, exit at profit target."; sc.AutoLoop = 1; ProfitTicks.Name = "Profit Target (Ticks)"; ProfitTicks.SetInt(10); ProfitTicks.SetIntLimits(1, 100); EntrySignal.Name = "Entry Signal Marker"; EntrySignal.DrawStyle = DRAWSTYLE_ARROW_UP; EntrySignal.PrimaryColor = RGB(0, 255, 0); EntrySignal.LineWidth = 3; sc.AllowOnlyOneTradePerBar = true; sc.MaintainTradeStatisticsAndTradesData = true; return; } // no need to run on every bar during recalculation if (sc.IsFullRecalculation) return; // If sim mode is active, set the SendOrdersToTradeService to 0 sc.SendOrdersToTradeService = sc.GlobalTradeSimulationIsOn ? 0 : 1; s_SCPositionData position; sc.GetTradePosition(position); double TickSize = sc.TickSize; double targetPrice; // Entry Condition: Close > Close[1] if (position.PositionQuantity == 0 && sc.Close[sc.Index] > sc.Close[sc.Index - 1]) { s_SCNewOrder order; order.OrderType = SCT_ORDERTYPE_MARKET; order.OrderQuantity = 1; order.TextTag = "Buy"; int Result = sc.BuyEntry(order); EntrySignal[sc.Index] = sc.Low[sc.Index] - (2 * TickSize); sc.AddMessageToLog("BUY Entry triggered", 0); } // Exit Condition: Fixed profit target if (position.PositionQuantity > 0) { targetPrice = position.AveragePrice + ProfitTicks.GetInt() * TickSize; s_SCNewOrder exit; exit.OrderType = SCT_ORDERTYPE_LIMIT; exit.OrderQuantity = position.PositionQuantity; exit.Price1 = targetPrice; exit.TextTag = "ProfitTarget"; // This is wrong as you are wanting to exit a buy position not a sell position // int Result = sc.SellExit(exit); int Result = sc.BuyExit(exit); } }