forked from tfuser/TF-altProjekte
63 lines
2.8 KiB
MQL5
63 lines
2.8 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| test1.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 strict
|
|
#include <Trade\Trade.mqh>
|
|
#include <Trade\PositionInfo.mqh>
|
|
|
|
int iMA_handle;
|
|
double iMA_buf[];
|
|
double Close_buf[];
|
|
string iMA_name;
|
|
|
|
string my_symbol;
|
|
ENUM_TIMEFRAMES my_timeframe;
|
|
|
|
CTrade m_Trade;
|
|
CPositionInfo m_PositionsInfo;
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
//---
|
|
my_symbol=Symbol();
|
|
my_timeframe=PERIOD_CURRENT;
|
|
iMA_handle=iMA(my_symbol,my_timeframe,40,0,MODE_SMA,PRICE_CLOSE);
|
|
if(iMA_handle==INVALID_HANDLE)
|
|
{
|
|
Print("Failed to get the indicator handle"); //if the handle is not obtained, print the relevant error message into the log file
|
|
return(-1); //complete handling the error
|
|
}
|
|
ChartIndicatorAdd(ChartID(),0,iMA_handle); //add the indicator to the price chart
|
|
ArraySetAsSeries(iMA_buf,true); //set iMA_buf array indexing as time series
|
|
ArraySetAsSeries(Close_buf,true); //set Close_buf array indexing as time series
|
|
iMA_name=ChartIndicatorName(ChartID(),0,ChartIndicatorsTotal(0,0)-1);
|
|
Print("Name Indicator :"+iMA_name);
|
|
//---
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//---
|
|
IndicatorRelease(iMA_handle); //deletes the indicator handle and deallocates the memory space it occupies
|
|
ArrayFree(iMA_buf); //free the dynamic array iMA_buf of data
|
|
ArrayFree(Close_buf); //free the dynamic array Close_buf of data
|
|
ChartIndicatorDelete(ChartID(),0,iMA_name);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
//---
|
|
}
|
|
//+------------------------------------------------------------------+
|