Support Board
Date/Time: Mon, 07 Jul 2025 10:52:11 +0000
Post From: Help with a chatGPT built study
[2025-06-21 19:03:35] |
User294249 - Posts: 1 |
Hey all I'm no coder first and foremost, so please bear with me. I wanted a study that assisted in calculating my R:R while taking into account position size and multiple targets. So naturally I used ChatGPT but of course things are never that easy, the coded is obviously not compatible and I'm unable to figure out the remedy. Any suggestion would be appreciated. #include "sierrachart.h" SCDLLName("Multi-Target R:R (Ticks Compatible Final)") SCSFExport scsf_MultiTargetRiskRewardTicks(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "Multi-Target Risk-Reward (Ticks)"; sc.AutoLoop = 0; return; } float TickSize = (float)sc.TickSize; // ✅ FIXED: Correctly use reference, not pointer s_SCPositionData PositionData; sc.GetTradePosition(PositionData); int PositionSize = (int)PositionData.PositionQuantity; float EntryPrice = (float)PositionData.AveragePrice; if (PositionSize == 0 || EntryPrice == 0.0f || TickSize <= 0.0f) { sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_ALL); return; } float StopPrice = 0.0f; struct TargetInfo { float Price; float Weight; }; std::vector<TargetInfo> Targets; for (int i = 0; i < 100; ++i) { s_UseTool Tool; Tool.Clear(); // ✅ FIXED: correct argument count and types if (sc.GetUserDrawnChartDrawing(sc.ChartNumber, i, Tool, 0) == 0) break; const char* label = Tool.Text.GetChars(); if (strstr(label, "Stop") || strstr(label, "stop")) { StopPrice = (float)Tool.BeginValue; } else if (strstr(label, "Target") || strstr(label, "target")) { TargetInfo t; t.Price = (float)Tool.BeginValue; t.Weight = 100.0f; const char* colon = strchr(label, ':'); if (colon != NULL) { t.Weight = (float)atof(colon + 1); } Targets.push_back(t); } } if (StopPrice == 0.0f || Targets.empty()) return; float RiskTicks = fabs(EntryPrice - StopPrice) / TickSize; if (RiskTicks == 0.0f) return; float WeightedRR = 0.0f; float TotalWeight = 0.0f; SCString Output; Output.Format("Entry: %.2f | Stop: %.2f | Risk: %.1f ticks\n", EntryPrice, StopPrice, RiskTicks); for (size_t i = 0; i < Targets.size(); ++i) { float RewardTicks = fabs(Targets.Price - EntryPrice) / TickSize; float RR = RewardTicks / RiskTicks; float Weight = Targets.Weight / 100.0f; WeightedRR += RR * Weight; TotalWeight += Weight; Output += SCString().Format("Target %.2f (%.0f%%): R:R %.2f (%.1f ticks)\n", Targets.Price, Targets.Weight, RR, RewardTicks); } float AvgRR = (TotalWeight > 0) ? (WeightedRR / TotalWeight) : 0.0f; Output += SCString().Format("Weighted Avg R:R: %.2f | Pos: %d", AvgRR, PositionSize); s_UseTool Display; Display.Clear(); Display.ChartNumber = sc.ChartNumber; Display.DrawingType = DRAWING_TEXT; Display.Text = Output; Display.FontSize = 12; Display.Color = RGB(255, 215, 0); Display.Region = 0; Display.UseRelativeVerticalValues = 1; Display.BeginDateTime = sc.BaseDateTimeIn[sc.ArraySize - 1]; Display.BeginValue = sc.Close[sc.ArraySize - 1] + 4 * TickSize; Display.AddMethod = UTAM_ADD_OR_ADJUST; Display.LineNumber = 7777; sc.UseTool(Display); } |
![]() Attachment Deleted. |