METEHAND ULTRA MASTER AE

 
#property strict

input double RiskPercent=1.0;
input int StopLossPoints=500;
input int BreakEvenPoints=300;
input int TrailingStart=300;
input int TrailingStep=200;
input int LookbackBars=50;
input int Magic=88888;

// Dashboard
bool ShowDashboard=true;
int dashX=10,dashY=50,dashWidth=250,dashHeight=180;

// İşlenecek pariteler
string Symbols[3]={"XAUUSD","EURUSD","USDJPY"};

// AI Weight Struct
struct TradeStat{ int win; int lose; double weight; datetime lastFail; };
TradeStat AIStats[3];

// Swing + 2.6
double GetHighest(string sym){ return iHigh(sym,0,iHighest(sym,0,MODE_HIGH,LookbackBars,1)); }
double GetLowest(string sym){ return iLow(sym,0,iLowest(sym,0,MODE_LOW,LookbackBars,1)); }
double LotSize(double sl){ double risk=AccountBalance()*RiskPercent/100.0; double tick=MarketInfo(Symbol(),MODE_TICKVALUE); double lot=risk/(sl*tick); return NormalizeDouble(lot,2); }

// Trend
bool BuyTrend(string sym){ return iMA(sym,PERIOD_H1,50,0,MODE_EMA,PRICE_CLOSE,0) > iMA(sym,PERIOD_H1,200,0,MODE_EMA,PRICE_CLOSE,0); }
bool SellTrend(string sym){ return iMA(sym,PERIOD_H1,50,0,MODE_EMA,PRICE_CLOSE,0) < iMA(sym,PERIOD_H1,200,0,MODE_EMA,PRICE_CLOSE,0); }

// Volatility
bool VolatilityOK(string sym){ return iATR(sym,0,14,0) > 5*Point; }
bool HasTrade(string sym){ for(int i=0;i<OrdersTotal();i++){ if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){ if(OrderMagicNumber()==Magic && OrderSymbol()==sym) return true; } } return false; }

// Toggle Dashboard (F12)
void CheckToggle(){ if(IsKeyPressed(VK_F12)) ShowDashboard=!ShowDashboard; }

// Dashboard çizimi
void DrawDashboard(){
   if(!ShowDashboard) return;

   string txt="JERVIS ULTRA DASHBOARD\n----------------------\n";
   for(int s=0;s<ArraySize(Symbols);s++){
       string sym=Symbols[s];
       double ask=MarketInfo(sym,MODE_ASK);
       double bid=MarketInfo(sym,MODE_BID);
       txt+=sym+": Bid="+DoubleToStr(bid,5)+" Ask="+DoubleToStr(ask,5)+"\n";
       txt+="AI Weight: "+DoubleToStr(AIStats[s].weight,2)+"\n";

       // Mini trade okları + SL/TP
       for(int i=0;i<OrdersTotal();i++){
           if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
               if(OrderSymbol()==sym && OrderMagicNumber()==Magic){
                   string dir=(OrderType()==OP_BUY)?"↑ BUY":"↓ SELL";
                   txt+=dir+" OpenPrice="+DoubleToStr(OrderOpenPrice(),5);
                   txt+=" SL="+DoubleToStr(OrderStopLoss(),5);
                   txt+=" TP="+DoubleToStr(OrderTakeProfit(),5)+"\n";
               }
           }
       }
       txt+="----------------------\n";
   }
   Comment(txt);
}

// AI Multi-Parite Giriş
void CheckEntry(){
   for(int s=0;s<ArraySize(Symbols);s++){
       string sym=Symbols[s];
       if(HasTrade(sym)) continue;
       if(!VolatilityOK(sym)) continue;

       double high=GetHighest(sym);
       double low=GetLowest(sym);
       double range=high-low;
       double zone=range/2.6;
       double buyLevel=low+zone;
       double sellLevel=high-zone;
       double lot=LotSize(StopLossPoints)*AIStats[s].weight;

       // BUY
       if(BuyTrend(sym) && MarketInfo(sym,MODE_ASK)<=buyLevel+10*Point && TimeCurrent()-AIStats[s].lastFail>3600){
           int ticket=OrderSend(sym,OP_BUY,lot,MarketInfo(sym,MODE_ASK),10,MarketInfo(sym,MODE_ASK)-StopLossPoints*Point,0,"AI Multi Buy",Magic,0,clrBlue);
           if(ticket<0){ AIStats[s].lose++; AIStats[s].weight*=0.9; AIStats[s].lastFail=TimeCurrent(); }
           else{ AIStats[s].win++; AIStats[s].weight*=1.05; }
       }

       // SELL
       if(SellTrend(sym) && MarketInfo(sym,MODE_BID)>=sellLevel-10*Point && TimeCurrent()-AIStats[s].lastFail>3600){
           int ticket=OrderSend(sym,OP_SELL,lot,MarketInfo(sym,MODE_BID),10,MarketInfo(sym,MODE_BID)+StopLossPoints*Point,0,"AI Multi Sell",Magic,0,clrRed);
           if(ticket<0){ AIStats[s].lose++; AIStats[s].weight*=0.9; AIStats[s].lastFail=TimeCurrent(); }
           else{ AIStats[s].win++; AIStats[s].weight*=1.05; }
       }
   }
}

// Trade Yönetimi
void ManageTrades(){
   for(int i=0;i<OrdersTotal();i++){
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
           if(OrderMagicNumber()!=Magic) continue;
           double profit;
           string sym=OrderSymbol();

           if(OrderType()==OP_BUY){
               profit=(MarketInfo(sym,MODE_BID)-OrderOpenPrice())/Point;
               if(profit>=BreakEvenPoints) OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),0,0);
               if(profit>=TrailingStart){ double newSL=MarketInfo(sym,MODE_BID)-TrailingStep*Point; if(newSL>OrderStopLoss()) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,0,0);}
               if(profit>500 && OrderLots()>0.01) OrderClose(OrderTicket(),OrderLots()/2,MarketInfo(sym,MODE_BID),10);
           }

           if(OrderType()==OP_SELL){
               profit=(OrderOpenPrice()-MarketInfo(sym,MODE_ASK))/Point;
               if(profit>=BreakEvenPoints) OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),0,0);
               if(profit>=TrailingStart){ double newSL=MarketInfo(sym,MODE_ASK)+TrailingStep*Point; if(newSL<OrderStopLoss()) OrderModify(OrderTicket(),OrderOpenPrice(),newSL,0,0);}
               if(profit>500 && OrderLots()>0.01) OrderClose(OrderTicket(),OrderLots()/2,MarketInfo(sym,MODE_ASK),10);
           }
       }
   }
}

// ANA LOOP
void OnTick(){
   CheckToggle();    // F12 ile aç/kapa
   DrawDashboard();  // Açılır dashboard
   CheckEntry();     // AI Multi-Parite giriş
   ManageTrades();   // Trade yönetimi
}