3DMa - indicator for MetaTrader 4




3DMa - indicator for MetaTrader 4


3DMA


Changing two parameters with the mouse pointer 

  • X - maximum MA period changes
  • Y - step of changing of MA period
#include <CanvasiCanvas.mqh> //https://www.mql5.com/en/code/23840
#property indicator_chart_window

double  close[];
long Total;
int Ma=0;
int stepMa=0;

int OnInit()
  {
   ChartSetInteger(0,CHART_SCALE,0,0);
   ChartSetInteger(0,CHART_FOREGROUND,true);
   CopyClose(_Symbol,_Period,(int)W.Right_bar,W.BarsInWind+Ma-1,close);
   Total=SeriesInfoInteger(_Symbol,_Period,SERIES_BARS_COUNT);
   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
  {
   return(rates_total);
  }

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   static int MaOld=-1,stepMaOld=-1;
   Ma=W.MouseX+100;
   stepMa=W.MouseY;
   if(stepMa<=0) stepMa=1;
   stepMa=1+stepMa/10;
   if(stepMa>Ma) stepMa=Ma-1;
   if(id==CHARTEVENT_CHART_CHANGE || MaOld!=Ma || stepMaOld!=stepMa)
     {
      ChartSetInteger(0,CHART_SCALE,0,0);
      CopyClose(_Symbol,_Period,(int)W.Right_bar,W.BarsInWind+Ma-1,close);
      nMA();
      MaOld=Ma; stepMaOld=stepMa;
     }
  }
//+------------------------------------------------------------------+

void nMA()
  {
   int preY=0;
   Canvas.Erase();
   double S=0;
   for(int i=0;i<Ma; i++) S+=close[i];

   for(int Per=Ma;Per>0;)
     {
      double s=S;
      uint Clr=Grad((double)Per/Ma);
      for(int x=0; x<W.BarsInWind;x++)
        {
         int Y=(int)(Canvas.Y(s/Per)-0.5);
         if(x>0) if(fabs(Y-preY)>1) Canvas.Line(x-1,preY,x,Y,Clr);
         else Canvas.PixelSet(x,Y,Clr);
         if((Ma+x)<ArraySize(close)) s=s-close[x+Ma-Per]+close[Ma+x]; else break;
         preY=Y;
        }
      for(int j=0; j<stepMa; j++) if(Per>0) {S=S-close[Ma-Per]; Per--;} else break;
     }
   Canvas.Update();
  }
//+------------------------------------------------------------------+
uint Grad(double p)
  {
   static uint Col[6]={0xFF0000FF,0xFFFF00FF,0xFFFF0000,0xFFFFFF00,0xFF00FF00,0xFF00FFFF};
   if(p>0.9999) return Col[5];
   if(p<0.0001) return Col[0];
   p=p*5;
   int n=(int)p;
   double k=p-n;
   argb c1,c2;
   c1.clr=Col[n];
   c2.clr=Col[n+1];
   return ARGB(255,c1.c[2]+uchar(k*(c2.c[2]-c1.c[2])+0.5),
                   c1.c[1]+uchar(k*(c2.c[1]-c1.c[1])+0.5),
                   c1.c[0]+uchar(k*(c2.c[0]-c1.c[0])+0.5));
  }
MT5 Version works much faster and therefore much more comfortable


Download 3DMa - indicator for MetaTrader 4




Related News




Latest News
Stocks: Home Depot, Kohls, Energy Shares Weigh on Market
19.11.2019 22:24
Investing.com – Stocks struggled to keep the big rally moving Tuesday, but weakness in retail stocks pulled the Dow lower and kept the S&P 500 in check. The S&P 500 hit a new intraday high but just missed a new record close and sixth straight gain. The NASDAQ Composite and Nasdaq 100 indexes did close at record levels and hit new
Read more
Day Ahead: Top 3 Things to Watch
19.11.2019 22:21
Investing.com - Here's a preview of the top 3 things that could rock markets tomorrow. 1. Fed's Minutes in Focus The Federal Reserve on Wednesday at 2 pm ET (19:00 GMT) will release the minutes of its October 29-30 Federal Open Market Committee (FOMC) meeting. At its October meeting, the FOMC cut interest rates, but expectations for
Read more
OxyContin maker Purdue Pharma to pay states' lawyers, urged to help victims
19.11.2019 22:18
By Tom Hals (Reuters) - OxyContin maker Purdue Pharma LP got court approval on Tuesday to reimburse millions of dollars in legal fees for states that back its proposed $10 billion settlement of opioid lawsuits, but with a condition meant to help victims of the addiction crisis. Purdue had told Bankruptcy Judge Robert Drain at Tuesday's
Read more
Australia to fast-track $2.6 billion worth of infrastructure spending in bid to revive economy
19.11.2019 22:15
By Colin Packham SYDNEY (Reuters) - Australia's conservative government will fast-track A$3.8 billion ($2.59 billion) in infrastructure spending, Prime Minister Scott Morrison said on Wednesday - a fillip to a stalling economy. Australia's economic growth has slumped to its lowest in a decade, led by weakness in consumer spending and
Read more
Conoco Plans Share Buyback That’s Almost 50% of Market Value
19.11.2019 22:12
(Bloomberg) -- ConocoPhillips (NYSE:COP) announced a 10-year plan to buy back $30 billion of shares, equivalent to about half of its current market capitalization, as the oil producer attempts to distance itself from the troubled U.S. shale industry. The company also said it will pay dividends of about $20 billion over the period and limit average
Read more