@@ -3,13 +3,16 @@ import type { StrategyConfig } from "./types";
33
44export function compilePine ( config : StrategyConfig ) : string {
55 let code = compileBase ( config ) ;
6- const alignDivergenceEntries = config . name === "RSI Divergence Reversal" && config . outputMode === "indicator" ;
7-
8- if ( ! alignDivergenceEntries ) return code ;
9-
106 const paneAnchor = "// === Integrated RSI divergence pane ===" ;
117 const filtersAnchor = "// === Filters and triggers ===" ;
128 const alertsAnchor = "// === Alerts ===" ;
9+ const alignDivergenceEntries =
10+ config . outputMode === "indicator" &&
11+ config . momentum . divergenceEnabled &&
12+ code . includes ( paneAnchor ) ;
13+
14+ if ( ! alignDivergenceEntries ) return code ;
15+
1316 const paneStart = code . indexOf ( paneAnchor ) ;
1417 const alertsStart = code . indexOf ( alertsAnchor ) ;
1518
@@ -26,18 +29,16 @@ export function compilePine(config: StrategyConfig): string {
2629 }
2730 code = code . replace (
2831 legacyDivergencePattern ,
29- "// Entry divergence is shared with the integrated RSI pane below.\n\n"
32+ "// Entry divergence is shared with the integrated RSI pane below.\n" +
33+ "bullishDivergence = divRegularBullAlert\n" +
34+ "bearishDivergence = divRegularBearAlert\n\n"
3035 ) ;
3136
3237 const longSetup = "longSetup = rsiValue >= rsiLongLevel and bullishDivergence and confirmationOk" ;
3338 const shortSetup = "shortSetup = rsiValue <= rsiShortLevel and bearishDivergence and confirmationOk" ;
3439 if ( ! code . includes ( longSetup ) || ! code . includes ( shortSetup ) ) {
35- throw new Error ( "Compiler transform anchor missing: divergence reversal entry setup" ) ;
40+ throw new Error ( "Compiler transform anchor missing: divergence entry setup" ) ;
3641 }
3742
38- code = code
39- . replace ( longSetup , "longSetup = rsiValue >= rsiLongLevel and divRegularBullAlert and confirmationOk" )
40- . replace ( shortSetup , "shortSetup = rsiValue <= rsiShortLevel and divRegularBearAlert and confirmationOk" ) ;
41-
4243 return code . replace ( filtersAnchor , paneBlock + filtersAnchor ) ;
4344}
0 commit comments