MTF_MA_001
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
MTF_MA_001

#property indicator_chart_window
//#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 White
//**************************************************************************/
extern int TimeFrame=15;
extern int MAPeriod=8;
extern int ma_method=MODE_LWMA;
extern bool ShowRawData = true;
extern bool ColorTrend = true;
extern int applied_price=PRICE_CLOSE;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

double RawBuffer[];
double SmoothBuffer[];
double trend[],Dir;
int i, limit;
  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  { 
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);   
   return(0);
   }
//+------------------------------------------------------------------+
//| MTF Moving Average                                               |
//+------------------------------------------------------------------+
int start()
   {
   
    //GlobalVariableSet("NLMA", 0);  
   //InitAllBuffers(); 
   Draw();
   //GlobalVariableSet("NLMA", trend[0]);
   //if(Dir == 1) GlobalVariableSet("NLMA", 1);//DrawVline(Yellow, Time[0]);  
   
        i= 500;
      while(i >= 0)
         {
            //Print("Trend: ",trend[i]);
            //if( ExtMapBuffer1[i] >  ExtMapBuffer1[i+1]) DrawVline(Yellow, Time[i]);  
   
          i--;
         }
     
      
   return(0);
   }
//+------------------------------------------------------------------+

//--------------- Draw -----------------------------------------------
void Draw()
{
      limit=Bars;

//WWWWWWWWWWWWWWWWWWW
      ArrayResize(RawBuffer, limit + 100);
      ArrayResize(SmoothBuffer, limit + 100);
      ArrayResize(trend, limit + 100);       
      ArrayResize(ExtMapBuffer1, limit + 100);      
      ArrayResize(ExtMapBuffer2, limit + 100);
      ArrayResize(ExtMapBuffer3, limit + 100);            
      //
      ArrayInitialize(ExtMapBuffer1,0);
      ArrayInitialize(ExtMapBuffer2,0);
      ArrayInitialize(ExtMapBuffer3,0);
      ArrayInitialize(RawBuffer,0);
      ArrayInitialize(SmoothBuffer,0);
      ArrayInitialize(trend,0);
      //
      ArraySetAsSeries(RawBuffer,true);
      //
      ArraySetAsSeries(SmoothBuffer,true);
      ArraySetAsSeries(trend,true);
      ArraySetAsSeries(ExtMapBuffer1,true);
      ArraySetAsSeries(ExtMapBuffer2,true);
      ArraySetAsSeries(ExtMapBuffer3,true);
//WWWWWWWWWWWWWWWWWWW 
      i= limit;
      while(i >= 0)
         {
         int Bar_Shift=iBarShift(NULL,TimeFrame,Time[i],false);
         RawBuffer[i]=iMA(NULL,TimeFrame,MAPeriod,0,ma_method,applied_price,Bar_Shift);
         if(ShowRawData) ExtMapBuffer3[i]= RawBuffer[i];
   
         i--;
         }
     
      i= limit;
      while(i >= 0)
         {
          SmoothBuffer[i] = iMAOnArray(RawBuffer,0,(TimeFrame/Period() ),0,0,i);
         ExtMapBuffer1[i] = SmoothBuffer[i];//Uptrend 
          
          
         trend[i] = trend[i+1];
         if (SmoothBuffer[i]> SmoothBuffer[i+1])
            {
            trend[i] =1;
            Dir = 1;
            }
         if (SmoothBuffer[i]< SmoothBuffer[i+1])
            {
            trend[i] =-1;
            Dir = -1;
            }
   //if(trend[i] == 1) GlobalVariableSet("NLMA", trend[0]);//DrawVline(Yellow, Time[i]);       
         
          
         
          if( ColorTrend)//Two-color trend
            {
            
           

            if (trend[i]>0)
               {
               //DrawVline(Yellow, Time[i]);
               //GlobalVariableSet("NLMA", trend[i]);
               ExtMapBuffer1[i] = SmoothBuffer[i];//Uptrend 
               if (trend[i+1]<0) ExtMapBuffer1[i+1]=SmoothBuffer[i+1];
               ExtMapBuffer2[i] = EMPTY_VALUE;
               }
            else
            if (trend[i]<0)
               { 
               ExtMapBuffer2[i] = SmoothBuffer[i];//Downtrend 
               if (trend[i+1]>0) ExtMapBuffer2[i+1]=SmoothBuffer[i+1];
               ExtMapBuffer1[i] = EMPTY_VALUE;
               }
            }else//Single-color trend
            ExtMapBuffer1[i]=trend[i];//SmoothBuffer[i];
              
            
         i--;
         }
       
//--------
   return(0);
   }
//-----------------------------------------------------------------------------



//-----------------------------------------------------------
void InitAllBuffers ()
   {
//
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

double RawBuffer[];
double SmoothBuffer[];
double trend[],Dir;
//   
      limit=Bars;
      ArrayResize(RawBuffer, limit + 100);
      ArrayResize(SmoothBuffer, limit + 100);
      ArrayResize(trend, limit + 100);       
      ArrayResize(ExtMapBuffer1, limit + 100);      
      ArrayResize(ExtMapBuffer2, limit + 100);
      ArrayResize(ExtMapBuffer3, limit + 100);            
      //
      ArrayInitialize(ExtMapBuffer1,0);
      ArrayInitialize(ExtMapBuffer2,0);
      ArrayInitialize(ExtMapBuffer3,0);
      ArrayInitialize(RawBuffer,0);
      ArrayInitialize(SmoothBuffer,0);
      ArrayInitialize(trend,0);
      //
      ArraySetAsSeries(RawBuffer,true);
      
   return(0);
   }     
//-----------------------------------------------------------  




//-----------------------------------------------------------
void DrawVline (color Color, datetime time)
   {
   static int ObjCnt;
   static double PrevVlineTime;
   if (time == PrevVlineTime) return(0);//Still on same bar
      ObjectCreate( "UpLine"+ObjCnt, OBJ_VLINE, 0, time, 0);
      ObjectSet("UpLine"+ObjCnt, OBJPROP_COLOR, Color);
      ObjectSet("UpLine"+ObjCnt, OBJPROP_BACK,true);
      ObjCnt++;
      PrevVlineTime = time;//Store bar time of last drawn line
   return(0);
   }     
//-----------------------------------------------------------  

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---