cm MA 2 bar Signal

Author: Copyright 2021, cmillion@narod.ru
Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
cm MA 2 bar Signal
ÿþ//+------------------------------------------------------------------+

//|                                                    MA Signal.mq4 |

//|                                Copyright 2021, cmillion@narod.ru |

//|                                               http://cmillion.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright 2021, cmillion@narod.ru"

#property link      "http://cmillion.ru"

#property version   "1.00"

#property strict

#property indicator_chart_window

#property indicator_buffers 3

#property  indicator_color1  clrBlue

#property  indicator_color2  clrBlue

#property  indicator_color3  clrRed

#property description "=48:0B>@ 2K405B A83=0;, :>340 425 ?>A;54=85 A25G8 70:@K;8AL (2KH5/=865) MA =0 7040==>< B09<D@59<5.@8 MB>< ?>O2;O5BAO 0;5@B A C:070=85< ?0@K =0 :>B>@>9 ?@>87>H;> 40==>5 459AB285"

//+------------------------------------------------------------------+

extern int                 MAperiod        = 5;           //?5@8>4 

extern int                 shift           = 0;           //!4283  >B=>A8B5;L=> F5=>2>3> 3@0D8:0.

input ENUM_MA_METHOD       method          = MODE_SMMA;   //5B>4K A:>;L7OI8E 

input ENUM_APPLIED_PRICE   applied_price   = PRICE_OPEN;  //A?>;L7C5<0O F5=0 .

input ENUM_TIMEFRAMES      timeframe   = 0;           //5@8>4. 



double     MA[];

double     SignalBufferRed[];

double     SignalBufferBlue[];

datetime TimeBar=0;

//+------------------------------------------------------------------+

int OnInit()

  {

   IndicatorBuffers(3);

   SetIndexStyle(0,DRAW_LINE);

   SetIndexStyle(1,DRAW_ARROW,0,2);

   SetIndexArrow(1,233);

   SetIndexStyle(2,DRAW_ARROW,0,2);

   SetIndexArrow(2,234);



   SetIndexBuffer(0,MA);

   SetIndexBuffer(1,SignalBufferBlue);

   SetIndexBuffer(2,SignalBufferRed);



   IndicatorShortName(StringConcatenate("MA (",MAperiod,")"));

   SetIndexLabel(0,"MA");

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

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[])

  {

   int i,limit;



   limit=rates_total-prev_calculated-2;

   if(limit<2) limit=2;

   for(i=1; i<limit; i++)

   {

      MA[i]=iMA(NULL,timeframe,MAperiod,shift,method,applied_price,i);

   }

   for(i=1; i<limit; i++)

   {

      if (MA[i+2]>iClose(NULL,timeframe,i+2) && MA[i+1]<iClose(NULL,timeframe,i+1) && MA[i]<iClose(NULL,timeframe,i)) 

      {SignalBufferBlue[i]=open[i];if (i==1 && TimeBar!=Time[0]) {Alert(Symbol()," BUY");TimeBar=Time[0];}}

      if (MA[i+2]<iClose(NULL,timeframe,i+2) && MA[i+1]>iClose(NULL,timeframe,i+1) && MA[i]>iClose(NULL,timeframe,i)) 

      {SignalBufferRed[i]=open[i];if (i==1 && TimeBar!=Time[0]) {Alert(Symbol()," SELL");TimeBar=Time[0];}}

   }



   return(rates_total);

  }

//+------------------------------------------------------------------+

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