I am just starting developing in MQL5, I am usually developing Pine Script EAs.
As a learning purpose, I am trying to replicate an Ichimoku EA I have developed in pine script.
In this EA I am merging the Kijun-Sen & Tenkan-Sen, the following way :
Pine Script 5// Smoothing the merged line
smoothingPeriod = input.int(9, title="Smoothing Period")
// Merge theLead Lines A & B
mergedLines = (lead_line_a + lead_line_b) / 2// Smoothing the merged line
smoothedMergedLines = ta.rma(mergedLines, smoothingPeriod )
plot(BoolShowIMLeadlinesMerged ? smoothedMergedLines : na, color=color.yellow, linewidth=1, title="Merged Kijun-Sen & Tenkan-Sen")
It is quite straightforward in pine script and I am struggling to implement this into an MQL5 indicator existing script I have found here : https://www.mql5.com/en/code/34225. The idea is after having modified the indicator to get the relevant data from this indicator into my EA.
Hereafter my code, you can find the code I have added or modified marked with a //*.
I would appreciate some expertise in order to move forward.
Many thanks in advance. Cheers.
//+------------------------------------------------------------------+//| IchimokuAlert.mq5 |//| Copyright 2021, MSK Corp. |//| m.saket@gmail.com |//+------------------------------------------------------------------+#property copyright"2021, MSK Corp."#property link"m.saket@gmail.com"#property description"Ichimoku Tenkan_sen Kinjun-sen Cross Alert"//--- indicator settings#property indicator_chart_window#property indicator_buffers6//*#property indicator_plots3//*#property indicator_type1DRAW_LINE#property indicator_type2DRAW_LINE#property indicator_type3DRAW_LINE//*#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Orange //*#property indicator_label1"Tenkan-sen"#property indicator_label2"Kijun-sen"#property indicator_label3"Merged Tenkan-sen and Kijun-sen"//*//--- input parametersinputint InpTenkan=9; // Tenkan-seninputint InpKijun=26; // Kijun-seninputint InpMergedLine=0; // Merged Tenkan-sen and Kijun-sen //*//--- indicator buffersdouble ExtTenkanBuffer[];
double ExtKijunBuffer[];
double ExtMergedLinesBuffer[]; //*int LastBars;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+voidOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(0,ExtTenkanBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtKijunBuffer,INDICATOR_DATA);
SetIndexBuffer(3,ExtMergedLinesBuffer,INDICATOR_DATA); //*//---IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawnPlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpTenkan);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKijun);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpMergedLine); //*//--- lines shifts when drawingPlotIndexSetInteger(3,PLOT_SHIFT,InpKijun);
PlotIndexSetInteger(4,PLOT_SHIFT,-InpKijun);
PlotIndexSetInteger(5,PLOT_SHIFT,0); //*//--- change labels for DataWindowPlotIndexSetString(0,PLOT_LABEL,"Tenkan-sen("+string(InpTenkan)+")");
PlotIndexSetString(1,PLOT_LABEL,"Kijun-sen("+string(InpKijun)+")");
PlotIndexSetString(2,PLOT_LABEL,"Merged Tenkan-sen and Kijun-sen("+string(InpMergedLine)+")"); //*
}
//+------------------------------------------------------------------+//| Ichimoku Kinko Hyo |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
int start;
//---if(prev_calculated==0)
start=1;
else
start=prev_calculated-1;
//--- main loopfor(int i=start; i<rates_total && !IsStopped(); i++)
{
//--- tenkan sendouble price_max=Highest(high,InpTenkan,i);
double price_min=Lowest(low,InpTenkan,i);
ExtTenkanBuffer[i]=(price_max+price_min)/2.0;
//--- kijun sen
price_max=Highest(high,InpKijun,i);
price_min=Lowest(low,InpKijun,i);
ExtKijunBuffer[i]=(price_max+price_min)/2.0;
double ee=ExtTenkanBuffer[i];
double es=ExtKijunBuffer[i];
double ew=ExtTenkanBuffer[i-1];
double wq=ExtKijunBuffer[i-1];
// Calculate the merged line (average of Tenkan-sen and Kijun-sen)double ml = (ExtTenkanBuffer[i] + ExtKijunBuffer[i]) / 2.0; //*int nBars=Bars(_Symbol,PERIOD_CURRENT);
if(LastBars!=nBars)
{
LastBars=nBars;
if(ExtTenkanBuffer[i]>ExtKijunBuffer[i] && ExtTenkanBuffer[i-1]<=ExtKijunBuffer[i-1])
SendNotification("Cross Up");
if(ExtTenkanBuffer[i]<ExtKijunBuffer[i] && ExtTenkanBuffer[i-1]>=ExtKijunBuffer[i-1])
SendNotification("Cross Up");
}
}
return(rates_total);
}
//+------------------------------------------------------------------+//| get price_max value for range |//+------------------------------------------------------------------+double Highest(constdouble& array[],constint range,int from_index)
{
double res=0;
//---
res=array[from_index];
for(int i=from_index; i>from_index-range && i>=0; i--)
if(res<array[i])
res=array[i];
//---return(res);
}
//+------------------------------------------------------------------+//| get price_min value for range |//+------------------------------------------------------------------+double Lowest(constdouble& array[],constint range,int from_index)
{
double res=0;
//---
res=array[from_index];
for(int i=from_index; i>from_index-range && i>=0; i--)
if(res>array[i])
res=array[i];
//---return(res);
}
//+------------------------------------------------------------------+
Ichimoku is one of the excellent indicator which can work lonely or with other indicators. With Alerting indicator which send notification to your cell phone whenever Tenkan-sen Cross Kijun-sen you can have an opportunity to enter or exit market at right time .
Hi,
I am just starting developing in MQL5, I am usually developing Pine Script EAs.
As a learning purpose, I am trying to replicate an Ichimoku EA I have developed in pine script.
In this EA I am merging the Kijun-Sen & Tenkan-Sen, the following way :
It is quite straightforward in pine script and I am struggling to implement this into an MQL5 indicator existing script I have found here : https://www.mql5.com/en/code/34225. The idea is after having modified the indicator to get the relevant data from this indicator into my EA.
Hereafter my code, you can find the code I have added or modified marked with a //*.
I would appreciate some expertise in order to move forward.
Many thanks in advance. Cheers.