JavaScript generated from your Pine script. It is what runs on your candles, bar by bar.
"use strict";
const R = rt;
let i = 0, S = null;
const INIT = 100000;
let $fastLen = NaN;
let $slowLen = NaN;
let $atrLen = NaN;
let $atrMult = NaN;
let $rr = NaN;
const _s1 = new R.Ema();
let $fast = NaN;
const _s2 = new R.Ema();
let $slow = NaN;
const _s3 = new R.Atr();
let $atr = NaN;
const _s4 = new R.Cross();
const _s5 = new R.Cross();
return {
onBar(idx, s) {
i = idx; S = s;
$fastLen = R.inNum(inputs, "fastLen", 9, true);
$slowLen = R.inNum(inputs, "slowLen", 21, true);
$atrLen = R.inNum(inputs, "atrLen", 14, true);
$atrMult = R.inNum(inputs, "atrMult", 1.5);
$rr = R.inNum(inputs, "rr", 2);
$fast = _s1.n(d.close[i], $fastLen);
$slow = _s2.n(d.close[i], $slowLen);
$atr = _s3.n(d, i, $atrLen);
if (_s4.n($fast, $slow, 1)) {
R.strat.entry(S, "Long", "long", undefined, undefined, undefined, { qty: undefined, ocaName: undefined, ocaType: undefined });
R.strat.exit(S, "Long exit", "Long", { profit: undefined, limit: (d.close[i] + (($atr * $atrMult) * $rr)), loss: undefined, stop: (d.close[i] - ($atr * $atrMult)), trailPrice: undefined, trailPoints: undefined, trailOffset: undefined, qty: undefined, qtyPercent: undefined }, undefined);
}
if (_s5.n($fast, $slow, -1)) {
R.strat.entry(S, "Short", "short", undefined, undefined, undefined, { qty: undefined, ocaName: undefined, ocaType: undefined });
R.strat.exit(S, "Short exit", "Short", { profit: undefined, limit: (d.close[i] - (($atr * $atrMult) * $rr)), loss: undefined, stop: (d.close[i] + ($atr * $atrMult)), trailPrice: undefined, trailPoints: undefined, trailOffset: undefined, qty: undefined, qtyPercent: undefined }, undefined);
}
}
};