@davoodmehraban89 / VELYQOR / commits / 0c1a70f
Fork 0

Intelligence, Advanced Charting & Trading Platform

feat(paper): non-predictive trend telemetry and initial risk-reward estimator

davoodmehraban89 committed Oct 14, 2026 at 23:56 UTC 0c1a70f93307b7bf25f286f4a3ae482fc576c986
1 file changed +39
packages/market-domain/src/paper-trend.mjs new
+39
@@ -0,0 +1,39 @@
1 +/**
2 + * Non-predictive paper-scenario trend telemetry; NEVER a live trade signal.
3 + * Consumes only the explicitly entered fictional OPEN/MARK prices.
4 + */
5 +function average(items) {
6 + return items.reduce((total,x)=>total+x,0)/items.length;
7 +}
8 +export function analyzePaperTrend(position) {
9 + if (!position || position.kind!=='PAPER_POSITION'||!Array.isArray(position.events))
10 + throw new TypeError('paper position is required');
11 + const events=position.events.filter(e=>e.type==='OPEN'||e.type==='MARK');
12 + const prices=events.map(e=>Number(e.price));
13 + if (!prices.every(x=>Number.isFinite(x)&&x>0))
14 + throw new RangeError('invalid paper scenario prices');
15 + const values=prices.slice(-40);
16 + if (values.length<5) {
17 + return {kind:'PAPER_TREND',status:'INSUFFICIENT_SCENARIO_DATA',
18 + sampleCount:values.length,classification:'UNDETERMINED',
19 + fastSma:null,slowSma:null,momentumPercent:null,points:values};
20 + }
21 + const fast=average(values.slice(-3));
22 + const slow=average(values.slice(-5));
23 + const last=values.at(-1);
24 + const baseline=values.at(-5);
25 + const momentum=(last/baseline-1)*100;
26 + // Small movements around equality are neutral; no market inference.
27 + const diff=(fast/slow-1)*100;
28 + const trend=diff>0.05&&momentum>0.05?'UP':
29 + diff< -0.05&&momentum< -0.05?'DOWN':'SIDEWAYS';
30 + return {kind:'PAPER_TREND',status:'SCENARIO_ONLY',sampleCount:values.length,
31 + classification:trend,fastSma:fast,slowSma:slow,momentumPercent:momentum,
32 + points:values};
33 +}
34 +export function initialPaperRiskReward(position) {
35 + if(!position || position.kind!=='PAPER_POSITION')throw new TypeError('invalid paper position');
36 + const loss=Math.abs(position.entryPrice-position.initialStop);
37 + const gain=Math.abs(position.takeProfitPrice-position.entryPrice);
38 + return loss>0?gain/loss:null;
39 +}