I am a newbie in programming mql5. So I try to learn it but its really hard.
My Question is, how can I draw the lines of the following indicator:
//+------------------------------------------------------------------+//| ProjectName |//| Copyright 2012, CompanyName |//| http://www.companyname.net |//+------------------------------------------------------------------+#property copyright"sanderz"#property link"https://login.mql5.com/ru/users/sanderz/seller"#property version"1.00"#property indicator_chart_window#property indicator_buffers11#property indicator_plots3#property indicator_label1 "SuperTr1"#property indicator_type1 DRAW_COLOR_LINE#property indicator_color1 clrGray#property indicator_width1 2#property indicator_label2 "SuperTr2"#property indicator_type2 DRAW_COLOR_LINE#property indicator_color2 clrPurple#property indicator_width2 2#property indicator_label3 "SuperTr3"#property indicator_type3 DRAW_COLOR_LINE#property indicator_color3 clrGreen, clrRed#property indicator_width3 2//---inputstring sect1 = ""; // SUPERTREND PARAMETERSinputint PeriodST=14; // Supertrend periodinputdouble Multiplier=3; // Supertrend multiplier 1h & 10 min Stopinputdouble Multiplier1=5; // Supertrend multiplier 10 min Entry//---inputstring sect2 = ""; // TIMEFRAME PARAMETERSinputbool swTF1=true; // Use TF 10 mininputbool swTF2=true; // Use TF 10 mininputbool swTFH1=true; // Use TF 1 hinputbool Show_Filling=false;
//---inputstring sect3 = ""; // DESIGN PARAMETERSinputint sizeFont=8; // Text sizeinputint sizeP=1; // Price mark sizeint handleSTr1=INVALID_HANDLE,handleSTr2=INVALID_HANDLE,handleSTrH1=INVALID_HANDLE;
double SuperTr1[],SuperTr2[],SuperTrH1[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---
handleSTr1=iCustom(_Symbol,PERIOD_M10,"SuperTrend",PeriodST,Multiplier);
SetIndexBuffer(0,SuperTr1,INDICATOR_DATA);
if(handleSTr1==INVALID_HANDLE)
{//--- Report the failure and return the error number PrintFormat("Failed to create the handle of the Supertrend indicator. Error=",GetLastError());
return(INIT_FAILED);
}
handleSTr2=iCustom(_Symbol,PERIOD_M10,"SuperTrend",PeriodST,Multiplier1);
SetIndexBuffer(2,SuperTr2,INDICATOR_DATA);
if(handleSTr2==INVALID_HANDLE)
{//--- Report the failure and return the error number PrintFormat("Failed to create the handle of the Supertrend indicator. Error=",GetLastError());
return(INIT_FAILED);
}
handleSTrH1=iCustom(_Symbol,PERIOD_H1,"SuperTrend",PeriodST,Multiplier);
SetIndexBuffer(4,SuperTrH1,INDICATOR_DATA);
if(handleSTrH1==INVALID_HANDLE)
{//--- Report the failure and return the error number PrintFormat("Failed to create the handle of the Supertrend indicator. Error=",GetLastError());
return(INIT_FAILED);
}
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
//--- indexing elements in arrays as in timeseries ArraySetAsSeries(high,true);ArraySetAsSeries(low,true);ArraySetAsSeries(tick_volume,true);
ArraySetAsSeries(time,true);ArraySetAsSeries(open,true);ArraySetAsSeries(spread,true);
ArraySetAsSeries(close,true);ArraySetAsSeries(volume,true);
//---if(swTF1)
{
ArrayResize(SuperTr1,2);ArrayInitialize(SuperTr1,0.0);
if(CopyBufferAsSeries(handleSTr1,2,0,2,true,SuperTr1))
{
color clr=clrBlack;
if(close[0]<SuperTr1[0])clr=clrRed;
if(close[0]>SuperTr1[0])clr=clrGreen;
if(close[0]==SuperTr1[0]&&close[1]>SuperTr1[1])clr=clrGreen;
if(close[0]==SuperTr1[0]&&close[1]<SuperTr1[1])clr=clrRed;
ArrowRightPriceDelete(0,"LPB1");
TextDelete(0,"2LPB1");
TextCreate(0,"2LPB1",0,time[0]+PeriodSeconds(_Period),SuperTr1[0],"M10","Arial",sizeFont,clr,0,ANCHOR_RIGHT_UPPER,false,false,true,0);
ArrowRightPriceCreate(0,"LPB1",0,time[0]+PeriodSeconds(_Period),SuperTr1[0],clr,DRAW_COLOR_LINE,STYLE_SOLID,sizeP,false,false,true,0);
ChartRedraw();
}
}
if(swTF2)
{
ArrayResize(SuperTr2,2);ArrayInitialize(SuperTr2,0.0);
if(CopyBufferAsSeries(handleSTr2,2,0,2,true,SuperTr2))
{
color clr=clrBlack;
if(close[0]<SuperTr2[0])clr=clrRed;
if(close[0]>SuperTr2[0])clr=clrGreen;
if(close[0]==SuperTr2[0]&&close[1]>SuperTr2[1])clr=clrGreen;
if(close[0]==SuperTr2[0]&&close[1]<SuperTr2[1])clr=clrRed;
ArrowRightPriceDelete(0,"LPB2");
TextDelete(0,"2LPB2");
TextCreate(0,"2LPB2",0, time[0]+PeriodSeconds(_Period),SuperTr2[0],"M10","Arial",sizeFont,clr,0,ANCHOR_RIGHT_UPPER,false,false,true,0);
ArrowRightPriceCreate(0,"LPB2",0,time[0]+PeriodSeconds(_Period),SuperTr2[0],clr,DRAW_COLOR_LINE, STYLE_SOLID,sizeP,false,false,true,0);
ChartRedraw();
}
}
if(swTFH1)
{
ArrayResize(SuperTrH1,2);ArrayInitialize(SuperTrH1,0.0);
if(CopyBufferAsSeries(handleSTrH1,2,0,2,true,SuperTrH1))
{
color clr=clrBlack;
if(close[0]<SuperTrH1[0])clr=clrRed;
if(close[0]>SuperTrH1[0])clr=clrGreen;
if(close[0]==SuperTrH1[0]&&close[1]>SuperTrH1[1])clr=clrGreen;
if(close[0]==SuperTrH1[0]&&close[1]<SuperTrH1[1])clr=clrRed;
ArrowRightPriceDelete(0,"LPBH1");
TextDelete(0,"2LPBH1");
TextCreate(0,"2LPBH1",0,time[0]+PeriodSeconds(_Period),SuperTrH1[0],"H1","Arial",sizeFont,clr,0,ANCHOR_RIGHT_UPPER,false,false,true,0);
ArrowRightPriceCreate(0,"LPBH1",0,time[0]+PeriodSeconds(_Period),SuperTrH1[0],clr,DRAW_COLOR_LINE,STYLE_SOLID,sizeP,false,false,true,0);
ChartRedraw();
}
}
//--- return(rates_total);
}
//+------------------------------------------------------------------+//| Creating the left price label |//+------------------------------------------------------------------+bool ArrowRightPriceCreate(constlong chart_ID=0, // chart IDconststring name="RightPrice", // the name of the price labelconstint sub_window=0, // subwindow numberdatetime time=0, // time of the anchor pointdouble price=0, // price of the anchor pointconstcolor clr=clrRed, // the color of the price labelconstENUM_LINE_STYLE style=STYLE_SOLID, // the style of the bordering lineconstint width=1, // the size of the price labelconstbool back=false, // in the backgroundconstbool selection=true, // select to moveconstbool hidden=true, // hidden in the list of objectsconstlong z_order=0) // priority for mouse click
{//ArrowLeftPriceCreate(0,"LP",0,time[0],price[0],clr,STYLE_SOLID,1,false,false,true,0);//--- set anchor point coordinates if they are not set
ChangeArrowEmptyPoint(time,price);
//--- reset the error valueResetLastError();
//--- create a price labelif(!ObjectCreate(chart_ID,name,OBJ_ARROW_RIGHT_PRICE,sub_window,time,price))
{
Print(__FUNCTION__,
": Failed to create the left price label! Error code = ",GetLastError());
return(false);
}
//--- set the label colorObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set the edging line styleObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set the label sizeObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse//--- when creating a graphical object using ObjectCreate function, the object cannot be//--- highlighted and moved by default. Inside this method, selection parameter//--- is true by default making it possible to highlight and move the objectObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object listObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chartObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful executionreturn(true);
}
//+------------------------------------------------------------------+//| Delete the left price label from the chart |//+------------------------------------------------------------------+bool ArrowRightPriceDelete(constlong chart_ID=0,// chart IDconststring name="RightPrice") // the name of the label
{
//--- reset the error valueResetLastError();
//--- delete the labelif(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
": Failed to delete the left price label! Error code = ",GetLastError());
return(false);
}
//--- successful executionreturn(true);
}
// Copies the indicator values into an array, taking into account the indexing order bool CopyBufferAsSeries(int _handle, // indicator handleint bufer, // the number of the indicator bufferint start, // where to startint number, // how many items to copybool asSeries, // array indexing orderdouble &M[]) // the array, into which data will be copied
{
//--- filling in the M array by the current indicator valuesif(CopyBuffer(_handle,bufer,start,number,M)<=0) return(false);
//--- creating the indexing order of the M array//--- if asSeries=true, then the order of indexing of the M array is that of a timeseries//--- if asSeries=false, then the default order of indexing of the M array is appliedArraySetAsSeries(M,asSeries);
//---return(true);
}
//+------------------------------------------------------------------+//| Checking anchor point values and setting default values |//| for empty ones |//+------------------------------------------------------------------+void ChangeArrowEmptyPoint(datetime &time,double &price)
{
//--- if the point's time is not set, it will be on the current barif(!time)
time=TimeCurrent();
//--- if the point's price is not set, it will have Bid valueif(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
}
//+------------------------------------------------------------------+//| Creating the "Text" object |//+------------------------------------------------------------------+bool TextCreate(constlong chart_ID=0, // chart IDconststring name="Text", // the name of the objectconstint sub_window=0, // subwindow numberdatetime time=0, // time of the anchor pointdouble price=0, // price of the anchor pointconststring text="Text", // the textconststring font="Arial", // fontconstint font_size=10, // font sizeconstcolor clr=clrRed, // colorconstdouble angle=0.0, // slopeconstENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor typeconstbool back=false, // in the backgroundconstbool selection=false, // select to moveconstbool hidden=true, // hidden in the list of objectsconstlong z_order=0) // priority for mouse click
{//TextCreate(0,"2LB",0,time[0],price[0],"text","Arial",12,clr,angle,ANCHOR_RIGHT_UPPER,false,false,true,0);//--- set anchor point coordinates if they are not set
ChangeTextEmptyPoint(time,price);
//--- reset the error valueResetLastError();
//--- create Text objectif(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
{
Print(__FUNCTION__,
": failed to create the \"Text\" object! Error code = ",GetLastError());
return(false);
}
//--- set the textObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set the text fontObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font sizeObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the textObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor typeObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set colorObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- display in the foreground (false) or background (true)ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the object by mouseObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object listObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chartObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful executionreturn(true);
}
//+------------------------------------------------------------------+//| Deleting the "Text" object |//+------------------------------------------------------------------+bool TextDelete(constlong chart_ID=0, // chart IDconststring name="Text") // object name
{
//--- reset the error valueResetLastError();
//--- delete the objectif(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
": failed to delete the \"Text\" object! Error code = ",GetLastError());
return(false);
}
//--- successful executionreturn(true);
}
//+------------------------------------------------------------------+//| Checking anchor point values and setting default values |//| for empty ones |//+------------------------------------------------------------------+void ChangeTextEmptyPoint(datetime &time,double &price)
{
//--- if the point's time is not set, it will be on the current barif(!time)
time=TimeCurrent();
//--- if the point's price is not set, it will have Bid valueif(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
}
//+------------------------------------------------------------------+//| Custom indicator deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
ArrowRightPriceDelete(0,"LPB1");
ArrowRightPriceDelete(0,"LPB2");
ArrowRightPriceDelete(0,"LPBH1");
TextDelete(0,"2LPB1");
TextDelete(0,"2LPB2");
TextDelete(0,"2LPBH1");
ChartRedraw();
}
//+------------------------------------------------------------------+
I tried and tried but nothing worked. Please give me a little help.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello everyone,
I am a newbie in programming mql5. So I try to learn it but its really hard.
My Question is, how can I draw the lines of the following indicator:
I tried and tried but nothing worked. Please give me a little help.
Thx in advance.
Best regards
Sandro