TF-altProjekte/Indukatoren/I-MA/I-MA-v1.mq5

119 lines
9.8 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:31:33 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| I-MA-v1.mq5 |
//| Thorsten Fischer Copyright 2019-2020 |
//| https://mql5.tfsystem.de |
//+------------------------------------------------------------------+
#property copyright "Thorsten Fischer Copyright 2019-2020"
#property link "https://mql5.tfsystem.de"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
//--- plot Label1
//#property indicator_label1 "MA1"
//#property indicator_type1 DRAW_LINE
//#property indicator_color1 clrRed
//#property indicator_style1 STYLE_SOLID
//#property indicator_width1 1
//--- input parameters
input string i_Short_Name="Ma Test"; // MA Short Name
input int i_MA_Periode=5; // MA Periode
input int i_MA_Draw_Begin=5; // MA Zeichnen Beginn
input int i_MA_Shift=0; // MA Verschiebung
input color i_MA_Color=clrTan; // MA Linien Farbe
input int i_MA_Width=3; // MA Linien Breite
input ENUM_LINE_STYLE i_MA_Style=0; // MA Linien Style
input ENUM_MA_METHOD i_MA_Method=MODE_SMMA; // MA Art der Gl<EFBFBD>ttung
input ENUM_APPLIED_PRICE i_MA_Applied_Price_High=PRICE_HIGH; // MA Preistyp oben
input ENUM_APPLIED_PRICE i_MA_Applied_Price_Low=PRICE_LOW; // MA Preistyp unten
input ENUM_TIMEFRAMES i_Period=PERIOD_CURRENT; // Zeitrahmen
string i_Symbol; // Indicator Symbol
bool einmal=true;
//---
int i_MA_Handle_High;
int i_MA_Handle_Low;
//--- indicator buffers
//double Label1Buffer[];
double i_MA_Buffer_High[];
double i_MA_Buffer_Low[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
//SetIndexBuffer(0,i_MA_Buffer,INDICATOR_DATA);
//---
i_Symbol=Symbol();
//---
i_MA_Handle_High=iMA(i_Symbol,i_Period,i_MA_Periode,i_MA_Shift,i_MA_Method,i_MA_Applied_Price_High);
i_MA_Handle_Low=iMA(i_Symbol,i_Period,i_MA_Periode,i_MA_Shift,i_MA_Method,i_MA_Applied_Price_Low);
if(i_MA_Handle_High==INVALID_HANDLE || i_MA_Handle_Low==INVALID_HANDLE)
{
Print("Indicator handle error");
return(INIT_FAILED);
}
//---
//PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,i_MA_Draw_Begin);
//PlotIndexSetInteger(0,PLOT_LINE_COLOR,i_MA_Color);
//PlotIndexSetInteger(0,PLOT_LINE_WIDTH,i_MA_Width);
//PlotIndexSetInteger(0,PLOT_LINE_STYLE,i_MA_Style);
//PlotIndexSetInteger(0,PLOT_SHIFT,i_MA_Shift);
PlotIndexSetString(0,PLOT_LABEL,"ma0");
//---
//ChartIndicatorAdd(ChartID(),0,i_MA_Handle_High);
//ChartIndicatorAdd(ChartID(),0,i_MA_Handle_Low);
IndicatorSetString(INDICATOR_SHORTNAME,i_Short_Name);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if (i_MA_Handle_High!=INVALID_HANDLE)
{
IndicatorRelease(i_MA_Handle_High);
}
if (i_MA_Handle_Low!=INVALID_HANDLE)
{
IndicatorRelease(i_MA_Handle_Low);
}
Comment("");
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
//int OnCalculate(const int rates_total,
// const int prev_calculated,
// const int begin,
// const double &price[])
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 calculated=BarsCalculated(i_MA_Handle_High);
if(einmal)
{
//Print(__FUNCTION__+" calculated : "+(string)calculated);
//Print(__FUNCTION__+" rates_total : "+(string)rates_total);
//Print(__FUNCTION__+" prev_calculated : "+(string)prev_calculated);
einmal=false;
}
//---
CopyBuffer(i_MA_Handle_High,0,prev_calculated,calculated,i_MA_Buffer_High);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+