AlgoX_MA_Channel

Author: © AlgoX-Trading
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites
AlgoX_MA_Channel
ÿþ//------------------------------------------------------------------

#property copyright    "© AlgoX-Trading"

#property version      "1.00"

#property description  "AlgoX MA-Channel"

//------------------------------------------------------------------

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2







#property indicator_type1   DRAW_LINE

#property indicator_label1  "MA Up"

#property indicator_color1  clrDarkViolet

#property indicator_style1 STYLE_SOLID

#property indicator_width1 2



#property indicator_type2  DRAW_LINE

#property indicator_label2  "MA Down"

#property indicator_color2  clrDarkViolet

#property indicator_style2 STYLE_SOLID

#property indicator_width2 2





//

//---

//--- Input Parameter ---//

input int             MAPeriod        = 20; // MA-Channel Period

input ENUM_MA_METHOD  MAMethode = MODE_SMA; // MA-Channel Methode





//

//--- Global Parameters --//

//

double MAUpBuffer[], MADownBuffer[];

int MA1Einst, MA2Einst;

int MaxPeriod;



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

//| Start                                                            |

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

int OnInit()

  {





   SetIndexBuffer(0,MAUpBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,MADownBuffer,INDICATOR_DATA);







   MaxPeriod=MAPeriod;





   PlotIndexGetInteger(0,PLOT_DRAW_BEGIN,MaxPeriod);

   PlotIndexGetInteger(1,PLOT_DRAW_BEGIN,MaxPeriod);



   MA1Einst = iMA(Symbol(),PERIOD_CURRENT,MAPeriod,0,MAMethode,PRICE_HIGH);

   MA2Einst = iMA(Symbol(),PERIOD_CURRENT,MAPeriod,0,MAMethode,PRICE_LOW);





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

//|                                                                  |

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

   return(0);

  }





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

//| Ending                                                           |

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

void OnDeinit(const int reason)

  {

   if(MA1Einst!=INVALID_HANDLE)

      IndicatorRelease(MA1Einst);

   if(MA2Einst!=INVALID_HANDLE)

      IndicatorRelease(MA2Einst);



  }





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

//|                                                                  |

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

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

  {



   if(IsStopped())

      return(0);



   if(rates_total<MaxPeriod)

      return (0);





   if(BarsCalculated(MA1Einst)>rates_total)

      return(0);

   if(BarsCalculated(MA2Einst)>rates_total)

      return(0);





   int copyBars =0;

   if(prev_calculated>rates_total || prev_calculated<=0)

     {

      copyBars = rates_total;

     }

   else

     {

      copyBars =  rates_total - prev_calculated;

      copyBars++;

     }



   if(IsStopped())

      return(0);

   if(CopyBuffer(MA1Einst,0,0,copyBars,MAUpBuffer)<=0)

      return(0);

   if(CopyBuffer(MA2Einst,0,0,copyBars,MADownBuffer)<=0)

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