@@ -393,6 +393,36 @@ const checkDate = ((param1, param2) => {
393393 return check
394394})
395395
396+ // Compute P/L Ratio for a daily itemTrade (avg win per share / avg loss per share)
397+ const getPLRatio = (itemTrade ) => {
398+ try {
399+ if (! itemTrade || ! itemTrade .pAndL ) return ' -'
400+ const p = itemTrade .pAndL
401+ const pref = amountCase && amountCase .value ? amountCase .value : amountCase
402+
403+ const winSum = p[pref + ' SharePLWins' ] || p[pref + ' SharePLWins' ] === 0 ? p[pref + ' SharePLWins' ] : null
404+ const winCount = p[pref + ' WinsCount' ] || p[pref + ' WinsCount' ] === 0 ? p[pref + ' WinsCount' ] : null
405+ const lossSum = p[pref + ' SharePLLoss' ] || p[pref + ' SharePLLoss' ] === 0 ? p[pref + ' SharePLLoss' ] : null
406+ const lossCount = p[pref + ' LossCount' ] || p[pref + ' LossCount' ] === 0 ? p[pref + ' LossCount' ] : null
407+
408+ if (! winSum || ! winCount || ! lossSum || ! lossCount) {
409+ // Fallback: try keys without 'SharePL' prefix (older structures)
410+ const altWinSum = p[pref + ' Wins' ] || p[pref + ' Wins' ] === 0 ? p[pref + ' Wins' ] : null
411+ const altLossSum = p[pref + ' Loss' ] || p[pref + ' Loss' ] === 0 ? p[pref + ' Loss' ] : null
412+ if (altWinSum == null || altLossSum == null || winCount == 0 || lossCount == 0 ) return ' -'
413+ }
414+
415+ const avgWinPerShare = (winSum / winCount)
416+ const avgLossPerShare = (- (lossSum) / lossCount)
417+
418+ if (! isFinite (avgWinPerShare) || ! isFinite (avgLossPerShare) || avgLossPerShare === 0 ) return ' -'
419+
420+ return (avgWinPerShare / avgLossPerShare).toFixed (2 )
421+ } catch (e) {
422+ return ' -'
423+ }
424+ }
425+
396426/** ************
397427 * SATISFACTION
398428 ***************/
@@ -801,11 +831,10 @@ function getOHLC(date, symbol, type) {
801831 :data-index =" index" class =" ms-2 uil uil-tag-alt pointerClass" ></i >
802832
803833 </div >
804- <div class =" col-12 col-lg-auto ms-auto" >P&L({{ selectedGrossNet.charAt(0)
805- }}):
834+ <div class =" col-12 col-lg-auto ms-auto" >P/L Ratio:
806835 <span
807- v-bind:class =" [itemTrade.pAndL[amountCase + 'Proceeds'] > 0 ? 'greenTrade ' : 'redTrade ']" >{{
808- useTwoDecCurrencyFormat (itemTrade.pAndL[amountCase + 'Proceeds'] )
836+ v-bind:class =" [itemTrade.pAndL.grossWinsCount/(itemTrade.pAndL.grossWinsCount+itemTrade.pAndL.grossLossCount) < 0.5 && getPLRatio(itemTrade) < 1. 0 ? 'redTrade ' : 'greenTrade ']" >{{
837+ getPLRatio (itemTrade)
809838 }}</span >
810839 </div >
811840
@@ -882,8 +911,8 @@ function getOHLC(date, symbol, type) {
882911 </div >
883912 <div >
884913 <label >P&L(g)</label >
885- <p >{{ useTwoDecCurrencyFormat( itemTrade.pAndL.grossProceeds)
886- }}
914+ <p v-bind:class = " [ itemTrade.pAndL[amountCase + 'Proceeds'] > 0 ? 'greenTrade' : 'redTrade'] " >
915+ {{ useTwoDecCurrencyFormat(itemTrade.pAndL.grossProceeds) }}
887916 </p >
888917 </div >
889918 </div >
0 commit comments