learning mql5

hayseed

Master Trader
Jul 27, 2010
1,181
279
149
usa
checking for proper alignment of 5, 10, 20, 200 smas and returning color......

trend type filter......h

//------

Code:
//------
//------

    for(int r = 0; r < ArraySize(tfs); r++)
      {

    int ma5[15];    
    int ma10[15];    
    int ma20[15];    
    int ma200[15];    
 

 

      ma5[r]      = iMA(symbol, tfs[r],5,0,MODE_SMA,PRICE_CLOSE);
      ma10[r]     = iMA(symbol, tfs[r],10,0,MODE_SMA,PRICE_CLOSE);
      ma20[r]     = iMA(symbol, tfs[r],20,0,MODE_SMA,PRICE_CLOSE);
      ma200[r]    = iMA(symbol, tfs[r],200,0,MODE_SMA,PRICE_CLOSE);



 
        double ma5s[];

        ArraySetAsSeries(ma5s,true);  

        CopyBuffer(ma5[r],0,0,4,ma5s);

 
        double ma10s[];

        ArraySetAsSeries(ma10s,true);  

        CopyBuffer(ma10[r],0,0,4,ma10s);

 
 
        double ma20s[];

        ArraySetAsSeries(ma20s,true);  

        CopyBuffer(ma20[r],0,0,4,ma20s);

 
        double ma200s[];

        ArraySetAsSeries(ma200s,true);  

        CopyBuffer(ma200[r],0,0,4,ma200s);

     


        clrmasalign[r]  = clrYellow;
       
        if(( (ma5s[0] > ma10s[0]) && (ma5s[0] > ma20s[0])  && (ma10s[0] > ma20s[0])  && (ma20s[0] > ma200s[0]) )  &&  ( (ma5s[0] > ma5s[1]) && (ma10s[0] > ma10s[1])  && (ma20s[0] > ma20s[1])  && (ma200s[0] > ma200s[1]) )  )    
         
           {
           clrmasalign[r] = clrBlue;
           }


        if( ( (ma5s[0] < ma10s[0]) && (ma5s[0] < ma20s[0])  && (ma10s[0] < ma20s[0])  && (ma20s[0] < ma200s[0]) )   &&  ( (ma5s[0] < ma5s[1]) && (ma10s[0] < ma10s[1])  && (ma20s[0] < ma20s[1])  && (ma200s[0] < ma200s[1]) )  )    
         
           {
           clrmasalign[r] = clrRed;
           }

      }

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

//------

Screenshot 2024-11-29 032708.png
 

hayseed

Master Trader
Jul 27, 2010
1,181
279
149
usa
working on it......h

//------

history deal constants.....

datetime conversions.......

deal property string......

history deal get integer......



//--------

MQL5:
double orders[20][20];
 
string symbols[5] = {"YM", "ES", "NQ", "RT", "GC"};
 
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
 
 
void OnStart()
  {
//--- request all the existing history on the account
   if(!HistorySelect(0, TimeCurrent()))
     {
      Print("HistorySelect() failed. Error ", GetLastError());
      return;
     }
 
 
  uint     totals = HistoryDealsTotal();
 
  Print("Number of historical deals on the account: ", totals);
 
  string   symbol    = "";
  double   profit    =  0;
  ulong    ticket     = 0;
  datetime time;
 
  MqlDateTime structure;
 
//--- for all deals
   for(uint i=0;i<totals;i++)
     {
       if((ticket=HistoryDealGetTicket(i)) > 0 )
 
 
      symbol = StringSubstr(HistoryDealGetString(ticket,DEAL_SYMBOL), 0, 2);  // substring  needed due to contract months changing
 
      //Print(symbol);
 
        for(int j = 0; j< ArraySize(symbols); j++)
           {
           if(symbol == symbols[j])
            {
              orders[j][0] = orders[j][0] +1;
              orders[j][1] = orders[j][1] + HistoryDealGetDouble(ticket,DEAL_PROFIT);
              orders[j][2] = orders[j][2] + HistoryDealGetDouble(ticket, DEAL_VOLUME);  
              //orders[j][3] = orders[j][1] +
              //orders[j][4] = orders[j][1] +
              orders[j][5] = orders[j][5] + HistoryDealGetDouble(ticket, DEAL_COMMISSION);  
 
//-----                dayoftheweek  
 
              time =  HistoryDealGetInteger(ticket,DEAL_TIME);
 
              TimeToStruct(time, structure);
 
              int weekday = structure.day_of_week;  // Print(weekday);  //  Print(TimeToString(time, TIME_DATE));
 
              if(weekday == 1) {orders[j][11] = orders[j][11] + 1;  Print(symbols[j]+" monday orders "+orders[j][11]);}  
              if(weekday == 2) {orders[j][12] = orders[j][12] + 1;  Print(symbols[j]+" tuesday orders "+orders[j][12]);}
              if(weekday == 3) {orders[j][13] = orders[j][13] + 1;  Print(symbols[j]+" wednesday orders "+orders[j][13]);}
              if(weekday == 4) {orders[j][14] = orders[j][14] + 1;  Print(symbols[j]+" thursday orders "+orders[j][14]);}
              if(weekday == 5) {orders[j][15] = orders[j][15] + 1;  Print(symbols[j]+" friday orders "+orders[j][15]);}
//-----
 
           }
 
           }
 
 
      }
 
  Print("YM " +orders[0][0]+"  profit "+ orders[0][1] + "  ES " + orders[1][0]+"  profit "+ orders[1][1]  + "  NQ " +orders[2][0]+"  profit "+ orders[2][1]  + "  RTY " +orders[3][0]+"  profit "+ orders[3][1]  );  
 
  }
 
Last edited by a moderator:

hayseed

Master Trader
Jul 27, 2010
1,181
279
149
usa
Vladimir Karputov , aka barabashkakvn, from perhaps ukraine, posted on the mq5 site his Two MA Color N Bars Square - indicator for MetaTrader 5.......

this was something i had tried to do a few months ago, before finally setting it aside...... all it takes is a single concept error to end all hope.......

have written and posted hundreds or these type indicators for mq4....... they are useful to me.....

i modified , only slightly, his indicator to do what i could not before........ lines 75 and 90 in his code below......

his original is below,...... along with a hma(10) and hma(20)...... and alma and sma(200)...... you will need the alma and hma also..... will expand these.....

seems best to create a template......

the idea , for me, is small sized trades with prevailing trend....... h

//-----

he has a youtube channel...... some of his videos are translated in to english......


Screenshot 2024-12-27 062041.png
//-------
 

Attachments

  • Two MA Color N Bars Square.ex5
    19.3 KB · Views: 1
  • hma.mq5
    12.6 KB · Views: 1
  • hma.ex5
    14.4 KB · Views: 0
  • alma.mq5
    7.1 KB · Views: 1
  • alma.ex5
    9.4 KB · Views: 0
  • Two MA Color N Bars Square v alma sma200.mq5
    23.3 KB · Views: 1
  • Two MA Color N Bars Square v alma sma200.ex5
    19.9 KB · Views: 1
  • Two MA Color N Bars Square v hma10 hma20.mq5
    23.4 KB · Views: 1
  • Two MA Color N Bars Square v hma10 hma20.ex5
    19.6 KB · Views: 1
Last edited:
  • 👍
Reactions: Enivid

hayseed

Master Trader
Jul 27, 2010
1,181
279
149
usa
the coppock indicator was intended monthly charts...... few can trade monthly charts...... not me for sure......

it seems to work equally well for me on lower timeframes......

if you looked at the math, it's really just comparing 2 roc's, rate of changes, and the creating a moving average of that change......

a single ma applied to the roc indicator is a very close approximation of the coppock...... such a indicator is on the mq5 site......

roc with a signal ma.......

the idea for me with both the coppock and the roc with ma, is to alert on the zero line crossing....... a 0 line cross with confirming hull and alma ma's seems a fair signal.....

had to edit the roc with ma to work with the mym, dow 30, futures....... some indicators will not work well with symbols that are whole numbers only......

adjustable digits version below......h
//------

MYMH25M15 22.png

//-----
 

Attachments

  • ROC_with_Signal_MA digits.ex5
    12.7 KB · Views: 0
  • ROC_with_Signal_MA digits.mq5
    9.1 KB · Views: 0