';});container.innerHTML=html;}
async function gexRefresh(){delete gexCache[gexActiveSym];await gexLoad(gexActiveSym);}
function optSubTab(btn,which){['optBtnOf','optBtnOi'].forEach(function(id){var b=document.getElementById(id);b.style.background='transparent';b.style.color='var(--text-secondary)';b.style.borderColor='var(--border-subtle)';});btn.style.background='rgba(212,175,55,.15)';btn.style.color='#D4AF37';btn.style.borderColor='#D4AF37';document.getElementById('optSubOf').style.display=which==='of'?'block':'none';document.getElementById('optSubOi').style.display=which==='oi'?'block':'none';if(which==='oi'&&typeof loadOIFlow==='function')loadOIFlow(window.state&&window.state.currentSymbol||'SPY');}
// ═══════════════ Pre-Trade Checklist ═══════════════
(function(){
'use strict';
var DEFAULT_ITEMS=[
{id:'m1',section:'🌍 حالة السوق',text:'السوق في اتجاه صاعد (فوق MA200)',why:'Murphy: التداول في اتجاه السوق الكبير',weight:2,required:true},
{id:'m2',section:'🌍 حالة السوق',text:'VIX أقل من 25 (سوق هادئ)',why:'VIX>25 يعني تقلبات عالية — مخاطرة أعلى',weight:1,required:false},
{id:'m3',section:'🌍 حالة السوق',text:'لا أحداث اقتصادية كبيرة خلال ساعة',why:'NFP/CPI/FOMC تسبب تحركات مفاجئة',weight:2,required:true},
{id:'s1',section:'📊 جودة الإشارة',text:'الإشارة من 3+ مدارس متوافقة',why:'Wyckoff + ICT + Murphy = ثقة أعلى',weight:3,required:true},
{id:'s2',section:'📊 جودة الإشارة',text:'السعر قرب دعم/مقاومة واضح',why:'الدخول قرب مستوى يحسن نسبة R:R',weight:2,required:true},
{id:'s3',section:'📊 جودة الإشارة',text:'الـ GEX يدعم اتجاه الإشارة',why:'Gamma Exposure يوجه حركة صانع السوق',weight:2,required:false},
{id:'s4',section:'📊 جودة الإشارة',text:'Options Flow يؤكد الاتجاه (P/C < 0.7 للشراء)',why:'الحيتان يضعون أموالهم مع الاتجاه',weight:2,required:false},
{id:'r1',section:'🛡️ إدارة المخاطرة',text:'وقف الخسارة محدد مسبقاً',why:'لا تدخل صفقة بدون وقف واضح',weight:3,required:true},
{id:'r2',section:'🛡️ إدارة المخاطرة',text:'نسبة R:R أكبر من 1.5',why:'الربح المتوقع ≥ 1.5× الخسارة المحتملة',weight:2,required:true},
{id:'r3',section:'🛡️ إدارة المخاطرة',text:'حجم المركز لا يتجاوز 2% من المحفظة',why:'حماية رأس المال الأساسية',weight:2,required:true},
{id:'p1',section:'🧠 الحالة النفسية',text:'لست في حالة انتقام بعد خسارة',why:'التداول الانتقامي يؤدي لخسائر مضاعفة',weight:2,required:true},
{id:'p2',section:'🧠 الحالة النفسية',text:'الصفقة تتبع خطتي المعتادة',why:'لا تكسر قواعدك بسبب فرصة مغرية',weight:1,required:false}
];
var ptcState={items:[],answers:{},customItems:[],activeTab:'Check'};
function ptcLoad(){try{var saved=localStorage.getItem('tih_ptc_custom');if(saved)ptcState.customItems=JSON.parse(saved);}catch(e){}ptcState.items=DEFAULT_ITEMS.concat(ptcState.customItems.map(function(c,i){return{id:'c'+i,section:'⚙️ مخصص',text:c,why:'',weight:1,required:false};}));}
window.ptcOpen=function(){ptcLoad();ptcState.answers={};document.getElementById('ptcModal').classList.add('open');ptcRenderItems();ptcUpdateScore();ptcRenderCustomList();ptcRenderLog();if(window.state&&window.state.currentSymbol)document.getElementById('ptcSymInput').value=window.state.currentSymbol;};
window.ptcClose=function(){document.getElementById('ptcModal').classList.remove('open');};
window.ptcBgClose=function(e){if(e.target===document.getElementById('ptcModal'))window.ptcClose();};
window.ptcTab=function(btn,tab){ptcState.activeTab=tab;document.querySelectorAll('.ptc-tab').forEach(function(b){b.classList.remove('active');});btn.classList.add('active');['Check','Custom','Log'].forEach(function(t){var el=document.getElementById('ptcTab'+t);if(el)el.style.display=t===tab?'block':'none';});if(tab==='Log')ptcRenderLog();};
window.ptcAutoFill=function(){if(window.state&&window.state.currentSymbol){document.getElementById('ptcSymInput').value=window.state.currentSymbol;if(typeof showToast==='function')showToast('✅ تم جلب الرمز: '+window.state.currentSymbol,'success');}else{if(typeof showToast==='function')showToast('ابحث عن رمز في الموقع أولاً','');}};
function ptcGroupItems(){var groups={};ptcState.items.forEach(function(item){if(!groups[item.section])groups[item.section]=[];groups[item.section].push(item);});return groups;}
function ptcRenderItems(){var container=document.getElementById('ptcItemsContainer');var groups=ptcGroupItems();var html='';Object.keys(groups).forEach(function(sec){html+='
';}).join('');}
window.ptcClearLog=function(){localStorage.removeItem('tih_ptc_log');ptcRenderLog();};
window.ptcAddCustom=function(){var inp=document.getElementById('ptcCustomInput');var val=inp.value.trim();if(!val)return;ptcState.customItems.push(val);inp.value='';ptcRenderCustomList();};
document.getElementById('ptcCustomInput').addEventListener('keydown',function(e){if(e.key==='Enter')window.ptcAddCustom();});
function ptcRenderCustomList(){var container=document.getElementById('ptcCustomList');if(!ptcState.customItems.length){container.innerHTML='
لا بنود مخصصة
';return;}container.innerHTML=ptcState.customItems.map(function(item,i){return'';}).join('');}
window.ptcEditCustom=function(i,val){ptcState.customItems[i]=val;};
window.ptcDelCustom=function(i){ptcState.customItems.splice(i,1);ptcRenderCustomList();};
window.ptcSaveCustom=function(){localStorage.setItem('tih_ptc_custom',JSON.stringify(ptcState.customItems));ptcLoad();ptcReset();if(typeof showToast==='function')showToast('✅ تم حفظ التخصيص','success');};
})();