Author: Copyright 2020, MetaQuotes Software Corp.
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
TriMACross
//+------------------------------------------------------------------+
//|                                                   TriMACross.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   5
//--- plot FastLine
#property indicator_label1  "FastLine"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot SlowLine
#property indicator_label2  "SlowLine"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot Long
#property indicator_label3  "Long"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  clrRed
#property indicator_style4  STYLE_SOLID
#property indicator_width3  1
//--- plot Short
#property indicator_label4  "Short"
#property indicator_type4   DRAW_HISTOGRAM
#property indicator_color4  clrGreen
#property indicator_style5  STYLE_SOLID
#property indicator_width4  1
//--- plot MidLine
#property indicator_label5  "MidLine"
#property indicator_type5   DRAW_LINE
#property indicator_color5  clrYellow
#property indicator_style5  STYLE_SOLID
#property indicator_width5  1

//--- input Fast iMA parameters
input string             CommandFM            = "=====Fast_MA Paramater=====";
input ENUM_TIMEFRAMES    FastMA_timeframe     = 0;
input int                FastMA_period        = 9;
input int                FastMA_shift         = 0;
input ENUM_MA_METHOD     FastMA_method        = 0;
input ENUM_APPLIED_PRICE FastMA_applied_price = 0;

//--- input Mid iMA parameters
input string             CommandMM            = "=====Mid_MA Paramater=====";
input ENUM_TIMEFRAMES    MidMA_timeframe     = 0;
input int                MidMA_period        = 18;
input int                MidMA_shift         = 0;
input ENUM_MA_METHOD     MidMA_method        = 0;
input ENUM_APPLIED_PRICE MidMA_applied_price = 0;

//--- input Slow iMA parameters
input string             CommandSM            = "=====Slow_MA Paramater=====";
input ENUM_TIMEFRAMES    SlowMA_timeframe     = 0;
input int                SlowMA_period        = 36;
input int                SlowMA_shift         = 0;
input ENUM_MA_METHOD     SlowMA_method        = 0;
input ENUM_APPLIED_PRICE SlowMA_applied_price = 0;

//--- indicator buffers
double         FastLineBuffer[];
double         SlowLineBuffer[];
double         LongBuffer[];
double         ShortBuffer[];
double         MidLineBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
   SetIndexBuffer(0,FastLineBuffer);
   SetIndexBuffer(1,SlowLineBuffer);
   SetIndexBuffer(2,LongBuffer);
   SetIndexBuffer(3,ShortBuffer);
   SetIndexBuffer(4,MidLineBuffer);
   
   EventSetMillisecondTimer(300);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
   OnTimer();
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }

void OnTimer()
  {
  
    for(int i=WindowFirstVisibleBar(); i>=0; i--)
       {
        
       FastLineBuffer[i]=iMA(NULL,FastMA_timeframe,FastMA_period,FastMA_shift,FastMA_method,FastMA_applied_price,i);
       MidLineBuffer[i]=iMA(NULL,MidMA_timeframe,MidMA_period,MidMA_shift,MidMA_method,MidMA_applied_price,i);
       SlowLineBuffer[i]=iMA(NULL,SlowMA_timeframe,SlowMA_period,SlowMA_shift,SlowMA_method,SlowMA_applied_price,i);
       
       if(SlowLineBuffer[i]>MidLineBuffer[i] && MidLineBuffer[i]>FastLineBuffer[i])
         {
          LongBuffer[i]=FastLineBuffer[i];
          ShortBuffer[i]=SlowLineBuffer[i];
         }
       
       if(FastLineBuffer[i]>MidLineBuffer[i] && MidLineBuffer[i]>SlowLineBuffer[i])
         {
          ShortBuffer[i]=SlowLineBuffer[i];
          LongBuffer[i]=FastLineBuffer[i];
         }
         
       }

  
  }

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 ---