Skip to content

Commit 90fcf47

Browse files
committed
feat: show confirmed entry price on signal labels
1 parent 8a893a6 commit 90fcf47

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

lib/compiler-v10.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,34 @@ import type { StrategyConfig } from "./types";
44
const profileLabel = (profile: StrategyConfig["visual"]["profile"]) =>
55
profile === "clean" ? "Clean" : profile === "enhanced" ? "Enhanced" : "Advanced";
66

7+
const replaceRequired = (source: string, search: string, replacement: string): string => {
8+
if (!source.includes(search)) throw new Error(`Compiler transform anchor missing: ${search.slice(0, 80)}`);
9+
return source.replace(search, replacement);
10+
};
11+
712
export function compilePine(config: StrategyConfig): string {
8-
const code = compileBase(config);
13+
let code = compileBase(config);
914
const label = profileLabel(config.visual.profile);
1015
const runtimeInput = `visualProfile = input.string("${label}", "Visual profile", options=["Clean", "Enhanced", "Advanced"])`;
1116
const bakedProfile = `visualProfile = "${label}" // Selected in PineForge Studio`;
1217

13-
if (!code.includes(runtimeInput)) throw new Error("Compiler transform anchor missing: visual profile input");
14-
return code.replace(runtimeInput, bakedProfile);
18+
code = replaceRequired(code, runtimeInput, bakedProfile);
19+
20+
if (config.direction !== "spot_buy_exit") {
21+
code = replaceRequired(
22+
code,
23+
'plotshape(longSignal, title="Long", style=shape.labelup, location=location.belowbar, color=color.lime, text="LONG", textcolor=color.black, size=size.normal)',
24+
'if longSignal\n label.new(bar_index, low, "LONG\\n" + str.tostring(close, format.mintick), style=label.style_label_up, color=color.lime, textcolor=color.black, size=size.normal)'
25+
);
26+
27+
if (config.direction === "long_short") {
28+
code = replaceRequired(
29+
code,
30+
'plotshape(shortSignal, title="Short", style=shape.labeldown, location=location.abovebar, color=color.red, text="SHORT", textcolor=color.white, size=size.normal)',
31+
'if shortSignal\n label.new(bar_index, high, "SHORT\\n" + str.tostring(close, format.mintick), style=label.style_label_down, color=color.red, textcolor=color.white, size=size.normal)'
32+
);
33+
}
34+
}
35+
36+
return code;
1537
}

0 commit comments

Comments
 (0)