learning mql5

attempt at gaussian filter ea......h
//------

according to barabashkakvn, Handle MUST be created ONLY ONCE. The most convenient place to create a handle is OnInit ()........ post 4 in how to start with mq5
 

Attachments

alerts only...... appears to work as intended.....

need trade.Buy and trade.Sell next........h

//------

MQL5:
int handlefast         = INVALID_HANDLE;
int handleslow         = INVALID_HANDLE;
int handlesuperslow    = INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
 
   trade.SetExpertMagicNumber(MagicNumber);
 
   // create indicator handles
   handlefast       = iCustom(_Symbol,_Period,"gfea",10);
   handleslow       = iCustom(_Symbol,_Period,"gfea",20);
   handlesuperslow  = iCustom(_Symbol,_Period,"gfea",30);
 
   if (handlefast == INVALID_HANDLE || handleslow == INVALID_HANDLE || handlesuperslow == INVALID_HANDLE)
   {
      Print("Indicator handle creation failed. fast = ",handlefast," slow = ",handleslow," super slow = ",handlesuperslow);
      return(INIT_FAILED);
   }
 
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 
//if(!allowtrades()) return;
 
//------
 
   //--- Read indicator values from buffers
   double fasts[], slows[], superslows[];
 
      ArraySetAsSeries(fasts,true);
      ArraySetAsSeries(slows,true);           
      ArraySetAsSeries(superslows,true);   
 
   if(CopyBuffer(handlefast,      0, 0, 4, fasts)       != 4) return;   
   if(CopyBuffer(handleslow,      0, 0, 4, slows)       != 4) return;
   if(CopyBuffer(handlesuperslow, 0, 0, 4, superslows)  != 4) return;
 
  if(NewBar())
  {
 
  if(((fasts[1] > slows[1]) && (slows[1] > superslows[1])) && ((fasts[2] < slows[2]) || (slows[2] < superslows[2]))) {Alert("gaussian buy on " +_Symbol + " "+ _Period);}
 
  if(((fasts[1] < slows[1]) && (slows[1] < superslows[1])) && ((fasts[2] > slows[2]) || (slows[2] > superslows[2]))) {Alert("gaussian sell on " +_Symbol + " "+ _Period);}
 }
 
 bool buy  = (((fasts[1] > slows[1]) && (slows[1] > superslows[1])) && ((fasts[2] < slows[2]) || (slows[2] < superslows[2])));
 
 bool sell = (((fasts[1] < slows[1]) && (slows[1] < superslows[1])) && ((fasts[2] > slows[2]) || (slows[2] > superslows[2])));
 
 Comment(buy+" "+sell);
 
 
//-----   
  }
//+------------------------------------------------------------------+



Screenshot 2025-10-03 055557.png
 
the weighted moving average is a perfect example of something that continues to elude me to this day...... how to best weight signals.....

not only the same indicator signal of different timeframes but differing indicators themselves on differing timeframes......

in the wma, the most recent prices are given more weight....... simple enough......

when trying to weight the wma signals by timeframe, there seems more to consider......

should the 60 minute wma carry twice the weight as the 30 minute...... should the four hour wma carry 240 times as much as the 1 minute.....

it's like a dog chasing his tail.......h

//-----
 

Attachments

this weeks to do list......

standard libraries.......h

//----

1. MQL5 Standard Library is written in MQL5 and is designed to facilitate writing programs (indicators, scripts, experts)... via mql5.....

2 COrderInfo is a class for easy access to the pending order properties. COrderInfo class provides access to the pending order properties..... via mql5.......

3 CPositionInfo is a class for easy access to the open position properties....... CPositionInfo class provides easy access to the open position properties...... via mql5.....
 
Last edited:
[in] Price. If the price is not specified, the current market Ask price will be used......

so we don't need ask or bid when sending market buy or sell orders......

simplifies multi asset ea's..... esp when another function is handling profit targets, stoplosses, trailing stops and such.......h

//------

MQL5:
 void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
 {
 
 if(id==CHARTEVENT_OBJECT_CLICK)
    {
 
 
    if(sparam == "Close All Profitable")
    {  
    closingallprofitable(); 
    closingallprofitable();
    closingallprofitable();    
    }           
 
 
 
    if(sparam == "Buy YM")
    {    
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"YM_Z",0,0,0,NULL);    
    }
 
 
    if(sparam == "Sell YM")
    {    
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"YM_Z",0,0,0,NULL);    
    }   
 
//---------------------------------------------------------------   
 
    if(sparam == "Buy ES")
    {    
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"ES_Z",0,0,0,NULL);    
    }
 
 
 
    if(sparam == "Sell ES")
    {    
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"ES_Z",0,0,0,NULL);    
    }   
 
 
//---------------------------------------------------
 
    if(sparam == "Buy NQ")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"NQ_Z",0,0,0,NULL);    
    }
 
 
 
    if(sparam == "Sell NQ")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"NQ_Z",0,0,0,NULL);    
    }   
 
//------------------------------------------------ 
 
 
    if(sparam == "Buy RTY")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"RTY_Z",0,0,0,NULL);    
    }
 
 
 
    if(sparam == "Sell RTY")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"RTY_Z",0,0,0,NULL);    
    }   
 
//------------------------------------------------
 
 
    if(sparam == "Buy 6E")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"6E_Z",0,0,0,NULL);    
    }
 
 
 
    if(sparam == "Sell 6E")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"6E_Z",0,0,0,NULL);    
    }   
 
//--------------------------------------------------
 
 
    if(sparam == "Buy 6B")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"6B_Z",0,0,0,NULL);    
    }
 
 
 
    if(sparam == "Sell 6B")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"6B_Z",0,0,0,NULL);    
    }   
 
//--------------------------------------------------
 
 
 
    if(sparam == "Buy 6A")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"6A_Z",0,0,0,NULL);    
    }
 
 
 
    if(sparam == "Sell 6A")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"6A_Z",0,0,0,NULL);    
    }   
 
//--------------------------------------------------
 
 
 
    if(sparam == "Buy 6N")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Buy(contracts,"6N_Z",0,0,0,NULL);    
    }
 
 
 
    if(sparam == "Sell 6N")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"6N_Z",0,0,0,NULL);    
    }   
 
//--------------------------------------------------
 
 
 
 
 
 
 
 
 
 
    }  // if(id==CHARTEVENT_OBJECT_CLICK)     
 }
 
//------
 
.....h
//------

MQL5:
//--------------------------------------------------
 
 
 
    if(sparam == "Buy All Index")
    {
 
    Alert(sparam+ " was pressed ");
 
 
    trade.Buy(contracts,"YM_Z",0,0,0,NULL);
 
    trade.Buy(contracts,"ES_Z",0,0,0,NULL);
 
    trade.Buy(contracts,"NQ_Z",0,0,0,NULL);
 
    trade.Buy(contracts,"RTY_Z",0,0,0,NULL);
 
    }
 
 
 
    if(sparam == "Sell All Index")
    {
 
    Alert(sparam+ " was pressed ");
 
 
    trade.Sell(contracts,"YM_Z",0,0,0,NULL);
 
    trade.Sell(contracts,"ES_Z",0,0,0,NULL);
 
    trade.Sell(contracts,"NQ_Z",0,0,0,NULL);
 
    trade.Sell(contracts,"RTY_Z",0,0,0,NULL);
 
    }   
//--------------------------------------------------
 
 
 
    if(sparam == "Buy All Currency")
    {
 
    Alert(sparam+ " was pressed ");
 
 
    trade.Buy(contracts,"6E_Z",0,0,0,NULL);
 
    trade.Buy(contracts,"6B_Z",0,0,0,NULL);
 
    trade.Buy(contracts,"6A_Z",0,0,0,NULL);
 
    trade.Buy(contracts,"6N_Z",0,0,0,NULL);
 
    }
 
 
 
    if(sparam == "Sell All Currency")
    {
 
    Alert(sparam+ " was pressed ");
 
    trade.Sell(contracts,"6E_Z",0,0,0,NULL);
 
    trade.Sell(contracts,"6B_Z",0,0,0,NULL);
 
    trade.Sell(contracts,"6A_Z",0,0,0,NULL);
 
    trade.Sell(contracts,"6N_Z",0,0,0,NULL);
 
    }   
 
 
 
 
//--------------------------------------------------
 
reasoning and potential use explained here........h
//-----

MQL5:
input bool   safetymode          = false;     // safety close true or false...
 
input double safeminimum         = 1000;      // single trade safe mode target...
 
input int    contracts           = 1;
 
int OnInit()
  {
    buttons();
 
   return(INIT_SUCCEEDED);
  }
//--------
 
//-----
//-----
 
 
 
void safeclose()                                   //----- safety close  .....
   {
    for(int i=PositionsTotal()-1; i>=0; i--)
       {
       ulong  ticket = PositionGetTicket(i);                                 //  https://www.mql5.com/en/docs/trading/positiongetticket
 
       string symbol = PositionGetSymbol(i);                                 //  https://www.mql5.com/en/docs/trading/positiongetsymbol
 
       double profit = PositionGetDouble(POSITION_PROFIT);                   //  https://www.mql5.com/en/docs/trading/positiongetdouble
 
       double minimum = safeminimum;
 
       if(StringSubstr(symbol, 0, 1) == "6")  {minimum = safeminimum*0.1;}   //  https://www.mql5.com/en/docs/strings/stringsubstr 
 
       if(PositionGetDouble(POSITION_PROFIT) < minimum ) continue;
 
       if(PositionGetDouble(POSITION_PROFIT) > minimum )
       {
       trade.PositionClose(ticket);
 
        Alert("peyton safety close   "            +symbol+  " profit  "+ DoubleToString(profit,0));
        SendNotification("peyton safety close   " +symbol+  " profit  "+ DoubleToString(profit,0));
 
 
       }
       }
//----
 
 
   }  // void safeclose()
 
Last edited:
added tooltip hover over object for total symbol profit/loss at a glance.....

hovering over 6n_z currently shows -55$...... it happens......

yeah, could have hovered over rty_z........

but why bring up a bad subject.......h
//------

Screenshot 2025-10-15 130800.png


//-----

MQL5:
    for(int i = 0; i < total; i++)
      { 
 
       string symbol = SymbolName(i,true);     
 
       Display(symbol+"gfs", 1260, 1000+(i*50));                 
       ObjectSetText(symbol+"gfs", symbol, 10, "Verdana", clrAqua);
       ObjectSetString(0, symbol+"gfs", OBJPROP_TOOLTIP, symbol+"  profit  "+DoubleToString(symbolprofit(symbol),0));                               
//------
 
 
 
 
 
 
double symbolprofit(string symbol)                                               
      {
       double profit = 0.0;                                 
 
       for(int i=PositionsTotal()-1; i>=0; i--)                       //----- https://www.mql5.com/en/docs/trading/positionstotal
       {
 
       if(PositionGetSymbol(i) !=symbol) continue;                    //----- https://www.mql5.com/en/docs/trading/positiongetsymbol
 
       profit += PositionGetDouble(POSITION_PROFIT);                  //---- https://www.mql5.com/en/docs/trading/positiongetdouble
       }
 
       return(profit);
 
      }
 
......h
//------

MQL5:
    for(int k = 0; k < 7; k++)
      { 
 
        double fastgfs[];
 
        ArraySetAsSeries(fastgfs,true);   
 
        CopyBuffer(fastgf[k],0,0,4,fastgfs);
 
 
 
        double slowgfs[];
 
        ArraySetAsSeries(slowgfs,true);   
 
        CopyBuffer(slowgf[k],0,0,4,slowgfs);
 
 
        double sslowgfs[];
 
        ArraySetAsSeries(sslowgfs,true);   
 
        CopyBuffer(sslowgf[k],0,0,4,sslowgfs);
 
 
        double laguerres[];   
 
        ArraySetAsSeries(laguerres,true);   
 
        CopyBuffer(laguerre[k],0,0,4,laguerres);
 
 
 
 
 
//------
            color clr  = clrYellow;
 
            int   size = 10;
 
 
            if((fastgfs[0] > slowgfs[0]) &&  (slowgfs[0] > sslowgfs[0]) && (laguerres[0] > 0.99))                                                               { clr = clrAqua;   }   
 
            if((fastgfs[0] < slowgfs[0]) &&  (slowgfs[0] < sslowgfs[0]) && (laguerres[0] < 0.01))                                                               { clr = clrMagenta;}     
 
            if((fastgfs[0] > slowgfs[0]) &&  (slowgfs[0] > sslowgfs[0]) && ((fastgfs[1] < slowgfs[1]) ||  (slowgfs[1] < sslowgfs[1])) && (laguerres[0] > 0.99)) { clr = clrBlue; size = 12;}   
 
            if((fastgfs[0] < slowgfs[0]) &&  (slowgfs[0] < sslowgfs[0]) && ((fastgfs[1] > slowgfs[1]) ||  (slowgfs[1] > sslowgfs[1])) && (laguerres[0] < 0.01)) { clr = clrRed;  size = 12;}     
 
 
 
 
 
               Display(symbol+tfs[k]+"gfvsgfvsgfl",  (k*50), 1200);                     
               ObjectSetText(symbol+tfs[k]+"gfvsgfvsgfl", "ÛÛ",size,"Terminal", clr);
               ObjectSetString(0, symbol+tfs[k]+"gfvsgfvsgfl", OBJPROP_TOOLTIP, symbol+" gf(10) vs gf(20) vs gf(30) && lagurre == 0 / 100");                               
 
 
             if(alerts)
             {
 
             }
 
        }  //-----  for(int k = 0; k < 7; k++)
//----


//------

Screenshot 2025-10-19 071548.png
 
......h
//-------

Screenshot 2025-10-19 072634.png

//------

MQL5:
    for(int k = 0; k < 7; k++)
      { 
 
 
        double almas[];
 
        ArraySetAsSeries(almas,true);   
 
        CopyBuffer(alma[k],0,0,20,almas);
 
 
        double coppocks[];
 
        ArraySetAsSeries(coppocks,true);   
 
        CopyBuffer(coppock[k],0,0,20,coppocks);
 
 
        double hmas[];
 
        ArraySetAsSeries(hmas,true);   
 
        CopyBuffer(hma[k],0,0,20,hmas);
 
 
 
        double stochs[];
 
        ArraySetAsSeries(stochs,true);   
 
        CopyBuffer(stoch[k],0,0,4,stochs);
 
 
 
        double fastgfs[];
 
        ArraySetAsSeries(fastgfs,true);   
 
        CopyBuffer(fastgf[k],0,0,4,fastgfs);
 
 
 
        double slowgfs[];
 
        ArraySetAsSeries(slowgfs,true);   
 
        CopyBuffer(slowgf[k],0,0,4,slowgfs);
 
 
        double sslowgfs[];
 
        ArraySetAsSeries(sslowgfs,true);   
 
        CopyBuffer(sslowgf[k],0,0,4,sslowgfs);
 
 
 
        double jfatls[];   
 
        ArraySetAsSeries(jfatls,true);   
 
        CopyBuffer(jfatl[k],0,0,4,jfatls);
 
 
        double jjmas[];   
 
        ArraySetAsSeries(jjmas,true);   
 
        CopyBuffer(jjma[k],0,0,4,jjmas);
 
 
        double itls[];   
 
        ArraySetAsSeries(itls,true);   
 
        CopyBuffer(itl[k],0,0,4,itls); //trend line buffer 0   https://www.mql5.com/en/docs/series/copybuffer  Instantaneous Trendline.mq5
 
 
        double itlts[];
 
        ArraySetAsSeries(itlts,true);   
 
        CopyBuffer(itl[k],1,0,4,itlts); // trigger line buffer 1   https://www.mql5.com/en/docs/series/copybuffer  Instantaneous Trendline.mq5
 
 
 
        double threepbws[];
 
        ArraySetAsSeries(threepbws,true);   
 
        CopyBuffer(threepbw[k],0,0,20,threepbws);
 
 
 
        double threepsss[];
 
        ArraySetAsSeries(threepsss,true);   
 
        CopyBuffer(threepss[k],0,0,20,threepsss);
 
 
 
        double jmas[];
 
        ArraySetAsSeries(jmas,true);   
 
        CopyBuffer(jma[k],0,0,20,jmas);
 
 
 
//------
            color clr = clrYellow;
 
 
            if(((almas[0] > almas[1]) + (hmas[0] > hmas[1]) + (fastgfs[0] > slowgfs[0]) + (slowgfs[0] > sslowgfs[0]) + (jfatls[0] > jfatls[1]) + (jjmas[0] > jjmas[1]) + (itlts[0] > itls[0]) + (threepsss[0] > threepbws[1]) + (jmas[0] > jmas[1])) ==  8)  { clr = clrAqua;   }  //   
 
            if(((almas[0] < almas[1]) + (hmas[0] < hmas[1]) + (fastgfs[0] < slowgfs[0]) + (slowgfs[0] < sslowgfs[0]) + (jfatls[0] < jfatls[1]) + (jjmas[0] < jjmas[1]) + (itlts[0] < itls[0]) + (threepsss[0] < threepbws[1]) + (jmas[0] < jmas[1])) ==  8)  { clr = clrMagenta;}  //   
 
            if(((almas[0] > almas[1]) + (hmas[0] > hmas[1]) + (fastgfs[0] > slowgfs[0]) + (slowgfs[0] > sslowgfs[0]) + (jfatls[0] > jfatls[1]) + (jjmas[0] > jjmas[1]) + (itlts[0] > itls[0]) + (threepsss[0] > threepbws[1]) + (jmas[0] > jmas[1])) ==  9)  { clr = clrBlue;   }  //   
 
            if(((almas[0] < almas[1]) + (hmas[0] < hmas[1]) + (fastgfs[0] < slowgfs[0]) + (slowgfs[0] < sslowgfs[0]) + (jfatls[0] < jfatls[1]) + (jjmas[0] < jjmas[1]) + (itlts[0] < itls[0]) + (threepsss[0] < threepbws[1]) + (jmas[0] < jmas[1])) ==  9)  { clr = clrRed;}  //   
 
 
//            if((almas[0] > almas[1]) && (hmas[0] > hmas[1]) && ((fastgfs[0] > slowgfs[0]) && (slowgfs[0] > sslowgfs[0])) && (jfatls[0] > jfatls[1]) && (jjmas[0] > jjmas[1]) && (itlts[0] > itls[0]) && (threepsss[0] > threepbws[1]) && (jmas[0] > jmas[1]))  { clr = clrAqua;   }  //   
 
//            if((almas[0] < almas[1]) && (hmas[0] < hmas[1]) && ((fastgfs[0] < slowgfs[0]) && (slowgfs[0] < sslowgfs[0])) && (jfatls[0] < jfatls[1]) && (jjmas[0] < jjmas[1]) && (itlts[0] < itls[0]) && (threepsss[0] < threepbws[1]) && (jmas[0] < jmas[1]))  { clr = clrMagenta;}  //   
 
 
               Display(symbol+tfs[k],   (k*50), 250);                           
               ObjectSetText(symbol+tfs[k], "ÛÛ",10,"Terminal", clr);
               ObjectSetString(0, symbol+tfs[k], OBJPROP_TOOLTIP, symbol+"  "+IntegerToString(tfs[k])+" supertrend 8 or 9 ma's");                               
 
 
 
        }  //-----  for(int k = 0; k < 7; k++)
//----
 
 
 
 
 
 
       }  //------        if(NewBar() || weekend)
 
here's another gee-wizz fun fact that will only effect 1 in 8.2 billion people........

just noticed something.......

if you have lets say 10 accounts, you can of course log in to them all from a single platform.....

if those accounts have some unique feature, such as a name, it can be hard to associate the account number with that feature.......

in my case, the unique feature is each account is named, like hayseed, paws, peyton, priscilla , mckenzie, makayla and so on.......

simply naming them does not make it easier for me to know whose account i'm in....... so i create a button which recognizes the account number and names the button accordingly...... the idea is when i log in to peytons account the button will say peyton.....

so say i apply the ea and start at first in the list of accounts....... when i move to the next lower account in the list, the name changes correctly...... as long as i continue down the list...... if i back up and go higher the name does not change......

same happens if i start at the last in the list and go higher...... names change correctly as long as i go higher up the list..... if i go lower it does not......

where you start does not really matter, if you start in the middle and go down, the same thing happens......

to reverse direction and have the name change correctly, you must remove and reapply the ea......

this is off market hours so not sure if it's the same in open markets......

imagine the ea takes a screenshot and does a lot of calculations which it exports to excel or prints...... the calculations will be correct but the screenshots button might not be.......

yeah i know ........ gee-wizz...... 1 in 8.2 billion........h

//--------
Screenshot 2025-10-25 085110.png

//------

MQL5:
//-------  https://www.mql5.com/en/docs/constants/environment_state/accountinformation
 
 
 string account = "";
 
      if(AccountInfoInteger(ACCOUNT_LOGIN) == ) {account = "hayseed";}
      if(AccountInfoInteger(ACCOUNT_LOGIN) == ) {account = "paws";}
      if(AccountInfoInteger(ACCOUNT_LOGIN) == ) {account = "peyton";}
      if(AccountInfoInteger(ACCOUNT_LOGIN) == ) {account = "makayla";}
      if(AccountInfoInteger(ACCOUNT_LOGIN) == ) {account = "jason";}
      if(AccountInfoInteger(ACCOUNT_LOGIN) == ) {account = "kenzie";}
      if(AccountInfoInteger(ACCOUNT_LOGIN) == ) {account = "priscilla";}
 
 
 
      ObjectCreate(0,account,OBJ_BUTTON,0,0,0);
 
      ObjectSetInteger(0,account,OBJPROP_XDISTANCE,10);
 
      ObjectSetInteger(0,account,OBJPROP_YDISTANCE,700);
 
      ObjectSetInteger(0,account,OBJPROP_XSIZE,200);
 
      ObjectSetInteger(0,account,OBJPROP_YSIZE,40);
 
      ObjectSetInteger(0,account,OBJPROP_CORNER,0);
 
      ObjectSetString(0,account,OBJPROP_TEXT,account);
 
      ObjectSetInteger(0,account,OBJPROP_BGCOLOR,clrLime);
 
      ObjectSetInteger(0,account,OBJPROP_BACK,false);
 
this is off market hours so not sure if it's the same in open markets......

imagine the ea takes a screenshot and does a lot of calculations which it exports to excel or prints...... the calculations will be correct but the screenshots button might not be.......

yeah i know ........ gee-wizz...... 1 in 8.2 billion........h

//--------
//----

ok..... just verified it's the same in live markets....... once you start a direction you must continue in that direction for the name to change correctly......

need to change my code some......

maybe i could add a button they said, " don't hold trades over the weekend you dumb hayseed ".......

that button should never change.......h
 
//----

ok..... just verified it's the same in live markets....... once you start a direction you must continue in that direction for the name to change correctly......

need to change my code some......

maybe i could add a button they said, " don't hold trades over the weekend you dumb hayseed ".......

that button should never change.......h
That's weird. Where do you put your account detecting code? OnInit? OnTimer? OnTick?
I'd name the accounts and use AccountInfoString(ACCOUNT_NAME)) in OnTimer to set it to the button/label. It also has to be followed by ChartRedraw() to get updated regardless of ticks.
 
That's weird. Where do you put your account detecting code? OnInit? OnTimer? OnTick?
I'd name the accounts and use AccountInfoString(ACCOUNT_NAME)) in OnTimer to set it to the button/label. It also has to be followed by ChartRedraw() to get updated regardless of ticks.
//-----

hey enivid...... thanks for the reply......

the buttons() function creates all those buttons and is called in the OnInit() ....... it's a expert advisor, using OnTick().....

i changed it to AccountInfoString(ACCOUNT_NAME) but the results are the same..... the button changes correctly if i continue in the direction started......

i'll look into OnTimer and chartredraw..........

how does AccountInfoString(ACCOUNT_NAME) know what i named the accounts.....

hope all is well.......h
 
//-----

hey enivid...... thanks for the reply......

the buttons() function creates all those buttons and is called in the OnInit() ....... it's a expert advisor, using OnTick().....

i changed it to AccountInfoString(ACCOUNT_NAME) but the results are the same..... the button changes correctly if i continue in the direction started......

i'll look into OnTimer and chartredraw..........

how does AccountInfoString(ACCOUNT_NAME) know what i named the accounts.....

hope all is well.......h
The ACCOUNT_NAME is taken from the registered account name. When you open a demo account your provide some name. In most cases, it's just your first and last name.
 
The ACCOUNT_NAME is taken from the registered account name. When you open a demo account your provide some name. In most cases, it's just your first and last name.
//-----

as best as i can remember, with all prop firms and my personal accounts that's been the case....... here, darwin is opening the mt5 and it is assigning the traders username...... that's kinda nice of them......

verified tonite to be sure....... opened new darwin account, chose a new darwin username, and the AccountInfoString(ACCOUNT_NAME) returns that name.......

still studying up on ontimer......h
 
for years i've wondered what change% was relative to...... as in, 100$ profit is 0.03% change of what...... balance..... equity..... time...... margin...... what......

no matter my math nothing made sense........ sometimes the % was large compared to the profit...... sometimes the % was small compared to the profit.......

often two trades in a row might have the same profit but very different %'s....... what gives......... just wondered...... never cared enough to dig deep......

stumbled on the answer tonite while working on something else........

it's the symbols price change from entry to exit..........

hiding in plain sight......h

//--------

from oanda......

There are specific characteristics in the displayed information for order rows and trade rows.

  1. Time: Displays the trade time.
  2. Symbol: Displays the trading instrument.
  3. Ticket: Displays the order number in the ‘Order’ row and the trade number in the ‘Trade’ row.
  4. ID: Displays the trade ID.
  5. Type: In the ‘Order’ row, it shows Buy, Sell, Buy Limit, Buy Stop, Sell Limit, or Sell Stop. In the ‘Trade’ row, it shows ‘in’ for entry trades and ‘out’ for closing trades.
  6. Volume: In the ‘Order’ row, it shows order numbers/trade volume, and in the ‘Trade’ row, it shows trade volume.
  7. Price: In the ‘Order’ row, it displays ‘Market’ for market orders. For Limit or Stop orders, it shows the specified price. The execution price is displayed in the ‘Trade’ row.
  8. Commission, Feed and Swap: For OANDA these fields are empty.
  9. Profit: In the ‘Order’ row, for take-profit (TP) or stop-loss (SL), it displays ‘TP price’ or ‘SL price.’ In the case of a stop-out, it shows the percentage. When an order is canceled, it displays Cancelled. Additionally, in the ‘Trade’ row, it shows the Profit/Loss on closing.
  10. Change: Displays the percentage change. For Buy trades, it shows ‘(closing price - entry price) / entry price’; and for Sell trades, it shows ‘(entry price - closing price) / entry price’.
//-----------

Screenshot 2025-10-31 092203.png
 
.......h

//-------

MQL5:
void OnTick()
  {
 
   setfiles();
 
 
   Comment(IntegerToString(dailytargets)+"  "+ DoubleToString(AccountInfoDouble(ACCOUNT_PROFIT),0));
 
 
 
//---    closingallprofitable()
 
   if((AccountInfoDouble(ACCOUNT_PROFIT) > dailytargets))
     {
      Alert("daily target hit closing all profitable only  "+DoubleToString(AccountInfoDouble(ACCOUNT_PROFIT),0));
 
      closingallprofitable();                                                                             //----- closes all profitable trades on all symbols......   all type orders..... leaves unprofitable
      closingallprofitable();                                                                             //----- closes all profitable trades on all symbols......   all type orders..... leaves unprofitable
 
      Alert("daily target hit... closed all profitable ... reassess trades....");
 
      SendNotification("daily target hit... closed all profitable... reassess trades....");
     }
 
 
 
 
 void setfiles()
        {
 
        MqlDateTime dt_struct;
        datetime    dtSer      = TimeCurrent(dt_struct);
        int         minute     = dt_struct.min ;
        int         hour       = dt_struct.hour ;    
 
 
        if(hour <  10) {dailytargets =  900.0;}      //  1am
        if(hour == 10) {dailytargets = 1000.0;}      //  2am    
        if(hour == 11) {dailytargets = 1100.0;}      //  3am
        if(hour == 12) {dailytargets = 1200.0;}      //  4am
        if(hour == 13) {dailytargets = 1300.0;}      //  5am
        if(hour == 14) {dailytargets = 1400.0;}      //  6am
        if(hour == 15) {dailytargets = 1500.0;}      //  7am
        if(hour == 16) {dailytargets = 2000.0;}      //  8am
        if(hour == 17) {dailytargets = 3000.0;}      //  9am
        if(hour == 18) {dailytargets = 4000.0;}      // 10am
        if(hour == 19) {dailytargets = 3000.0;}      // 11am
        if(hour == 20) {dailytargets = 2000.0;}      // 12am
        if(hour >  20) {dailytargets = 1000.0;}      // > 12am
 
 
        }
 
Last edited:
added hover tooltip on buttons to display the symbols profit...... could have hovered over buy rty or buy ym...... but they are negative......

and no one wants to let on they have losses.......h

//-------

Screenshot 2025-11-04 145709.png


//------
MQL5:
double profit(string symbol)                                      //-----  selected  symbol profit only
   {
       double symbolprofit = 0.0;                                 //-----  use AccountInfoDouble(ACCOUNT_PROFIT) for total account profit
 
    for(int i=PositionsTotal()-1; i>=0; i--)
       {
 
       if(PositionGetSymbol(i) != symbol) continue;
 
       symbolprofit += PositionGetDouble(POSITION_PROFIT);
       }
 
     return(symbolprofit);
 
   }
 
 
//----- 
 
      ObjectCreate(0,"Buy ES",OBJ_BUTTON,0,0,0);
 
      ObjectSetInteger(0,"Buy ES",OBJPROP_XDISTANCE,500);
 
      ObjectSetInteger(0,"Buy ES",OBJPROP_YDISTANCE,400);
 
      ObjectSetInteger(0,"Buy ES",OBJPROP_XSIZE,200);
 
      ObjectSetInteger(0,"Buy ES",OBJPROP_YSIZE,40);
 
      ObjectSetInteger(0,"Buy ES",OBJPROP_CORNER,0);
 
      ObjectSetString(0,"Buy ES",OBJPROP_TEXT,"Buy ES");
 
      ObjectSetInteger(0,"Buy ES",OBJPROP_BGCOLOR,clrLime);
 
      ObjectSetInteger(0,"Buy ES",OBJPROP_BACK,false);     
 
      ObjectSetString(0, "Buy ES", OBJPROP_TOOLTIP, profit("ES_Z"));