learning mql5

hayseed

Master Trader
Jul 27, 2010
1,166
275
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,166
275
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: