learning mql5

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

saw both those functions but tried neither.....

was trying the same arraycopy method which has worked without fail before....

the basic code is very simple, we both could write every line of it in our heads..... until volume for me.....

the only difference i can see is ivolume requires a shift where the others do not.....

the indicator sets all the global values for it's symbol and 7 common timeframes......

the dashboard indicator then cycles thru all the global values and displays them....

i will read up on the functions you mentioned.......

my goal is to see the coppock indicator and all others, in a single at a glance screen.....h

//------- using iVolume(_Symbol,tf[j],0) > iVolume(_Symbol,tf[j],1) works

MQL5:
//-------  individual []  arrays declared above
 
 
 for(int i = 0; i < 7; i++)    // 7 timeframes
      {
 
      alma[i]     = iCustom(_Symbol,tf[i],"alma");
      coppock[i]  = iCustom(_Symbol,tf[i],"Coppock");
      hma[i]      = iCustom(_Symbol,tf[i],"hma",20,2.0);
      //schaff[i]   = iCustom(_Symbol,tf[i],"schaff");
      psar[i]     = iSAR(_Symbol,tf[i],0.01,0.2);
      ma10[i]     = iMA(_Symbol,tf[i],10,0,MODE_SMA,PRICE_CLOSE);
      ma20[i]     = iMA(_Symbol,tf[i],20,0,MODE_SMA,PRICE_CLOSE);
      ma50[i]     = iMA(_Symbol,tf[i],50,0,MODE_SMA,PRICE_CLOSE);
      stoch[i]    = iStochastic(_Symbol,tf[i], 10, 3, 6, MODE_SMA, STO_CLOSECLOSE);
      atr[i]      = iATR(_Symbol,tf[i],20);
      ao[i]       = iAO(_Symbol,tf[i]);
      tema[i]     = iTEMA(_Symbol,tf[i],20,0,PRICE_CLOSE);
      dema[i]     = iDEMA(_Symbol,tf[i],20,0,PRICE_CLOSE);
      vol[i]      = iRealVolume(_Symbol,tf[i],0);              // insists on a shift where others do not have tried several versions
      bars        = iBars(_Symbol,tf[i]);
 
      }
 
 
    for(int j = 0; j < 7; j++)  // 7 timeframes
      {
 
        double vols[];
 
        ArraySetAsSeries(vols,true);
 
        CopyBuffer(vol[j],0,0,4,vols);
 
 
        double almas[];
 
        ArraySetAsSeries(almas,true);
 
        CopyBuffer(alma[j],0,0,20,almas);
 
 
        double coppocks[];
 
        ArraySetAsSeries(coppocks,true);
 
        CopyBuffer(coppock[j],0,0,20,coppocks);
 
//----------        repetitive array copy
 
//-----------  global variables set in this manner
 
            if(coppocks[1] > coppocks[2])  { GlobalVariableSet(_Symbol+tfs[j]+"coppock", 10); } 
 
            if(coppocks[1] < coppocks[2])  { GlobalVariableSet(_Symbol+tfs[j]+"coppock",-10); }
 
            if(coppocks[1] > 0)            { GlobalVariableSet(_Symbol+tfs[j]+"coppock0", 10); } 
 
            if(coppocks[1] < 0)            { GlobalVariableSet(_Symbol+tfs[j]+"coppock0",-10); }
 
 
            GlobalVariableSet(_Symbol+tfs[j]+"ahm", 0);
 
            if((hmas[0] > almas[0]) && (almas[0] > ma10s[0]) && (ma10s[0] > ma20s[0]))  {GlobalVariableSet(_Symbol+tfs[j]+"ahm", 10); }
 
            if((hmas[0] < almas[0]) && (almas[0] < ma10s[0]) && (ma10s[0] < ma20s[0]))  {GlobalVariableSet(_Symbol+tfs[j]+"ahm",-10); }
 
 
            //if( !((almas[1] > almas[2]) && (hmas[1] > hmas[2]) && (coppocks[1] > coppocks[2])) && !((almas[1] < almas[2]) && (hmas[1] < hmas[2]) && (coppocks[1] < coppocks[2])))   {clr[j] = clrYellow;  GlobalVariableSet(_Symbol+tfs[j],0);}
 
 
            if(aos[0] >  aos[1])  {GlobalVariableSet(_Symbol+tfs[j]+"ao",  10); }
 
            if(aos[0] <= aos[1])  {GlobalVariableSet(_Symbol+tfs[j]+"ao", -10); }
 
 
            if(temas[0] >  temas[1])  {GlobalVariableSet(_Symbol+tfs[j]+"tema",  10); }
 
            if(temas[0] <= temas[1])  {GlobalVariableSet(_Symbol+tfs[j]+"tema", -10); }
 
 
            if(demas[0] >  demas[1])  {GlobalVariableSet(_Symbol+tfs[j]+"dema",  10); }
 
            if(demas[0] <= demas[1])  {GlobalVariableSet(_Symbol+tfs[j]+"dema", -10); }
 
            //
            if(iVolume(_Symbol,tf[j],0) >  iVolume(_Symbol,tf[j],1))  {GlobalVariableSet(_Symbol+tfs[j]+"volume",  10); } // can't get arraycopy to work..... this does.....
 
            if(iVolume(_Symbol,tf[j],0) <  iVolume(_Symbol,tf[j],1))  {GlobalVariableSet(_Symbol+tfs[j]+"volume", -10); }
 
//------

//------

View attachment 31854
You think that iRealVolume() and iVolume() are indicator functions (like iMA()), but they aren't. They are access functions, like iHigh() and iLow(). That's why you cannot copy any buffers from them.
 
.....h

//----- positionstotal.....

MQL5:
   } // if(NewBar())
 
 
 
//-----    https://www.mql5.com/en/docs/trading/positionstotal
//-----
 
       if(PositionsTotal() == 0) {highestaccountprofit  = 0.00;}
 
 
       if((_Symbol == "YM_M") && accounttrailstop)
         {
 
          if((AccountInfoDouble(ACCOUNT_PROFIT) > dailytarget) && (AccountInfoDouble(ACCOUNT_PROFIT) > highestaccountprofit))  {highestaccountprofit = AccountInfoDouble(ACCOUNT_PROFIT);}
 
          if((highestaccountprofit >= dailytarget) &&  AccountInfoDouble(ACCOUNT_PROFIT) < (highestaccountprofit - accountprofittrail))
          {
          closingall();
          closingall();
          closingall();
 
          Print(DoubleToString(highestaccountprofit,0));
 
          Alert("account trailing stop hit... closed all... reassess trades.... " + DoubleToString(highestaccountprofit,0));
          Alert("account trailing stop hit... closed all... reassess trades.... " + DoubleToString(highestaccountprofit,0));
 
          SendNotification("account trailing stop hit... closed all... reassess trades.... " + DoubleToString(highestaccountprofit,0));
          }
         }
 
 
 //----
 //----
 
       if((AccountInfoDouble(ACCOUNT_PROFIT) > dailytarget) &&  (_Symbol == "YM_M") && !accounttrailstop)
         {
         Alert("daily target hit closing all");
 
         closingall();
         closingall();
         closingall();
 
         Alert("daily target hit... closed all... reassess trades....");
         Alert("daily target hit... closed all... reassess trades....");
 
 
         SendNotification("daily target hit... closed all... reassess trades....");
        }
 
 
  Comment( "                                              "+DoubleToString(AccountInfoDouble(ACCOUNT_PROFIT),0)+"     "+ DoubleToString(symprofit(),0));
 
   if(trailingstophighlow || trailingstoppsar || trailingstopma || trailpsarsellstop || trailmasellstop || trailpsarbuystop || trailmabuystop)         {trail = clrAqua;}
 
      Display("trail",1470, 30);          
      ObjectSetText("trail","trailing",10,"Verdana", trail);
 
   if(!trailingstophighlow && !trailingstoppsar && !trailingstopma && !trailpsarsellstop && !trailmasellstop && !trailpsarbuystop && !trailmabuystop)  {trail = clrBlack;}
 
      Display("trail",1470, 30);          
      ObjectSetText("trail","trailing",10,"Verdana", trail);
 
  } // void OnTick()
//+---
 
......h


//------ tested only on YM_M

MQL5:
//-------   returning alligator lips value for use in a typical trailing stop......
//-------   just for practice.....
 
double lips()  //----- returns lips value, usually green lip , for the current 0 bar
  {
 
     double lipsArray[];
     MqlRates pArray[];
 
     ArraySetAsSeries(lipsArray,true);
     int Data=CopyRates(_Symbol,_Period,0,1,pArray);
 
     int alligator = iAlligator(_Symbol,_Period,13,8,8,5,5,3,MODE_SMMA,PRICE_MEDIAN);
 
     CopyBuffer(alligator,2,0,13,lipsArray);
 
     double lipsValue = NormalizeDouble(lipsArray[0],_Digits);
 
     return(lipsValue);
     }
 
 
//-------
//-------

//-------

Screenshot 2025-04-10 005208.png
 
a very crude example of creating rectangles based on risk to reward..... have several yet to be understood issues......

goal is to create rectangles with colors based on trades grade ranking , such as "a", "b", "c" and so on ...... where "a" would be your favorite conditions.....

rectangle size is based on the amount of total account value being risked, with respect to the risk/reward ratio..... like people often say, risking 2%.....

by that i mean, if 2000$ is total risk, the r/r ratio of 1/1 would create a rectangle the equivalent distance of 2000$ both up and down......

secondary goal is to better visualize exits and method of...... such as when should a trailing stop start and how much should it lag..... or would just a plain target fare better.....

need to understand why they redraw when other indicators are added.....

many more ideas to implement easily come to mind.....

the code can be elusive......h

//-------


// the width being determine by an expected time window for trade completion, so it spans the completion time would be a benefit.......


Screenshot 2025-04-12 182612.png

//------- text describing the reason and metrics of the trade would help looking back......

Screenshot 2025-04-12 181105.png


//---



MQL5:
   double dollaratrisk = AccountInfoDouble(ACCOUNT_BALANCE)*(riskpercent/100);    //  0.002
 
 
   double pointsinplay = dollaratrisk / ((1/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)) * SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)); 
 
   double pointvalue   = ((1/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)) * SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
 
 
 
//---
   double ask             = SymbolInfoDouble(Symbol(),SYMBOL_ASK);             
   double bid             = SymbolInfoDouble(Symbol(),SYMBOL_BID);
 
   if(buy)  {up = bid+(pointsinplay*reward); dn = bid-(pointsinplay*risk);}
   if(sell) {up = bid+(pointsinplay*risk);   dn = bid-(pointsinplay*reward);}
 
 
 
   ObjectCreate(0, "riskreward"+id, OBJ_RECTANGLE, 0, iTime(NULL, 0, 0), up, iTime(NULL, 0, 20), dn);
   ObjectSetInteger(0, "riskreward"+id, OBJPROP_FILL, true);   
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_SELECTABLE,true);
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_COLOR,fillcolor);
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_BACK,true);
 
 
 
    Comment(" account balance is  " + DoubleToString(AccountInfoDouble(ACCOUNT_BALANCE),0)+ "\n" + " dollar at risk is   " + DoubleToString(dollaratrisk,0) + "\n" + " points in play " + DoubleToString(pointsinplay,2) + "\n" + " tick size " + SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE) + "\n" + " tickvalue " + SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE) + "\n" + " point value " + DoubleToString(pointvalue,2)  + "\n" + " high price " +   DoubleToString(ObjectGetDouble(0,"riskreward"+id,OBJPROP_PRICE,0),0)  + "\n" + " low price " +   DoubleToString(ObjectGetDouble(0,"riskreward"+id,OBJPROP_PRICE,1),0));
 
conditional rectangle...... simple alma color change in this case...... need to add multiple confirming conditions..... safety in numbers......

birds of a feather, ya know....h

//--------

MQL5:
       ArraySetAsSeries(almas,true);   
       CopyBuffer(alma[j],0,0,4,almas);
 
       }
 
 
   double dollaratrisk = AccountInfoDouble(ACCOUNT_BALANCE)*(riskpercent/100);    //  0.002
 
 
   double pointsinplay = dollaratrisk / ((1/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)) * SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)); 
 
   double pointvalue   = ((1/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)) * SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
 
   color tradeclr = clrGray;
 
//---
   double ask             = SymbolInfoDouble(Symbol(),SYMBOL_ASK);             
   double bid             = SymbolInfoDouble(Symbol(),SYMBOL_BID);
 
   bool buysignal  = ((almas[1] > almas[2]) && (almas[2] <= almas[3]));     // conditional signal
   bool sellsignal = ((almas[1] < almas[2]) && (almas[2] >= almas[3]));     // conditional signal
 
 
   if(buy  || buysignal)  {up = bid+(pointsinplay*reward); dn = bid-(pointsinplay*risk);    tradeclr = clrLime;}
   if(sell || sellsignal) {up = bid+(pointsinplay*risk);   dn = bid-(pointsinplay*reward);  tradeclr = clrRed;}
 
 
   if(buy  || buysignal || sell || sellsignal)
   {
   ObjectCreate(0, "riskreward"+id, OBJ_RECTANGLE, 0, datetime (iTime(NULL, 0, 0))+60*60, up, iTime(NULL, 0, 0), dn);   // rectangles future  zone  datetime (iTime(NULL, 0, 0))+60*60
   ObjectSetInteger(0, "riskreward"+id, OBJPROP_FILL, true);   
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_SELECTABLE,true);
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_COLOR,tradeclr);
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_BACK,true);
   }

//------ also need pre-thought out trade metrics..... displayed in text on chart......

//------

Screenshot 2025-04-13 002707.png
 
might be best to have objectcreate outside the oncalculate.....

need to include ability to create rectangles in the past for study......h


//-------

MQL5:
   bool buysignal  = ((almas[1] > almas[2]) && (almas[2] <= almas[3]));     // conditional signal
   bool sellsignal = ((almas[1] < almas[2]) && (almas[2] >= almas[3]));     // conditional signal
 
 
   if(buy  || buysignal)  {up = bid+(pointsinplay*reward); dn = bid-(pointsinplay*risk);    tradeclr = clrLime;}
   if(sell || sellsignal) {up = bid+(pointsinplay*risk);   dn = bid-(pointsinplay*reward);  tradeclr = clrRed;}
 
   string rect = "rectangle"+id;
 
   if((buy  || buysignal || sell || sellsignal) && (ObjectFind(0,rect) != 0) )
       {
        drawrectangle(rect, tradeclr, up, dn);
       }
 
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
void drawrectangle (string rect, color tradeclr, double up, double dn) 
   {
   ObjectCreate(0, "riskreward"+id, OBJ_RECTANGLE, 0, datetime (iTime(NULL, 0, 0))+60*60, up, iTime(NULL, 0, 0), dn);   // rectangles future  zone  datetime (iTime(NULL, 0, 0))+60*60
   ObjectSetInteger(0, "riskreward"+id, OBJPROP_FILL, true);   
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_SELECTABLE,true);
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_COLOR,tradeclr);
   ObjectSetInteger(0,"riskreward"+id,OBJPROP_BACK,true);
   }