From a21fd7519e4198658e65c9188b3b281baafec78e Mon Sep 17 00:00:00 2001 From: Pietro Giacobazzi Date: Wed, 17 Jun 2026 07:07:11 +0000 Subject: [PATCH] PaPP v2 indicatore: box auto-fit con larghezza reale del testo (TextGetSize); titolo TF compatto Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- PaPP v2/PaPP_Median.mq5 | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/PaPP v2/PaPP_Median.mq5 b/PaPP v2/PaPP_Median.mq5 index 0bd519f..1b6f576 100644 --- a/PaPP v2/PaPP_Median.mq5 +++ b/PaPP v2/PaPP_Median.mq5 @@ -440,6 +440,14 @@ int OnCalculate(const int rates_total, } //+------------------------------------------------------------------+ +// larghezza in pixel di un testo nel font del pannello +int TxtW(string s,int fs,bool bold) + { + TextSetFont(bold?"Consolas Bold":"Consolas",-fs*10); + uint w=0,h=0; TextGetSize(s,w,h); + return (int)w; + } +//+------------------------------------------------------------------+ void DrawInfo() { double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID); @@ -456,7 +464,7 @@ void DrawInfo() double cluCur,cluPct,velCur,velPct,accCur,accPct,volCur,volPct; AllMetrics(CLWIN,cluCur,cluPct,velCur,velPct,accCur,accPct,volCur,volPct); - string sT = "PaPP Median ["+EnumToString((ENUM_TIMEFRAMES)_Period)+"]"; + string sT = "PaPP Median ["+StringSubstr(EnumToString((ENUM_TIMEFRAMES)_Period),7)+"]"; string sM = "Median: "+DoubleToString(median,_Digits); string sD = StringFormat("Dist: %+.2f%% - %s (P%.0f)",distPct,DistWord(distPct,distAbsPct),distAbsPct*100); string sV = StringFormat("Cluster %.3f%% - %s (P%.0f)",cluCur,MagWord(cluPct,"molto stretto","stretto","normale","largo","molto largo"),cluPct*100); @@ -467,15 +475,20 @@ void DrawInfo() for(int m=0;m<7;m++) sMA[m]=StringFormat("MA %3dg: %s",gDays[m],DoubleToString(GetMA(m,1),_Digits)); string sH = "Sopra=SELL | Sotto=BUY"; - //--- 2) larghezza/altezza del box dal contenuto - int maxc=StringLen(sT); - int lens[7]; lens[0]=StringLen(sM); lens[1]=StringLen(sD); lens[2]=StringLen(sV); - lens[3]=StringLen(sVE); lens[4]=StringLen(sAC); lens[5]=StringLen(sVO); lens[6]=StringLen(sH); - for(int k=0;k<7;k++) if(lens[k]>maxc) maxc=lens[k]; - for(int m=0;m<7;m++) if(StringLen(sMA[m])>maxc) maxc=StringLen(sMA[m]); + //--- 2) larghezza/altezza del box: misuro la larghezza REALE in pixel (TextGetSize) + int maxw=0; + maxw=MathMax(maxw,TxtW(sT,FontSize+2,true)); + maxw=MathMax(maxw,TxtW(sM,FontSize,false)); + maxw=MathMax(maxw,TxtW(sD,FontSize,true)); + maxw=MathMax(maxw,TxtW(sV,FontSize,false)); + maxw=MathMax(maxw,TxtW(sVE,FontSize,false)); + maxw=MathMax(maxw,TxtW(sAC,FontSize,false)); + maxw=MathMax(maxw,TxtW(sVO,FontSize,false)); + maxw=MathMax(maxw,TxtW(sH,FontSize-1,false)); + for(int m=0;m<7;m++) maxw=MathMax(maxw,TxtW(sMA[m],FontSize-1,false)); int boxX=x-6, boxY=y0-6; - int w=(int)(maxc*FontSize*0.62)+18; - int bodyH=15*lh+6; // 7 righe in alto + 7 MA + riga finale + padding + int w=maxw+(x-boxX)+10; // padding sinistro (x-boxX) + destro 10 + int bodyH=15*lh+6; // 7 righe in alto + 7 MA + riga finale + padding PanelBox(boxX,boxY,w,bodyH); //--- 3) scritte (aggiornate in-place: niente ObjectsDeleteAll -> niente lampeggio)