Thanks for Murrey Math on/off Button !
May we have some sound, popup, push alerts to be added up when it crosses one level to another level - up/down (i.e. from 3/8 to 4/8 up or 3/8 to 2/8 down)
Thanking you in advance
MT5 Time Frame Access Buttons 4 replies
MT4 GUI - Draw Buttons, Change Timeframes and Symbols 1 reply
Is it possible? Buttons for buy and sell and close open orders 3 replies
Help to make buttons in EA 0 replies
Dislikedhi BanzaiFx Please add on off button to this indcator "True_TrandLine_Indicator" {image} {file}Ignored
Disliked{quote} I posted it above post-396 https://www.forexfactory.com/thread/...6#post13776436Ignored
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 3
//----
// 5 LWMA Shift
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDarkBlue
#property indicator_width1 2
#property indicator_style1 STYLE_DASH
#property indicator_label1 "5 LWMA"
// 13 SMMA
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrBlack
#property indicator_width2 3
#property indicator_style2 STYLE_SOLID
#property indicator_label2 "13 SMMA"
// 5 SMMA
#property indicator_type3 DRAW_LINE
#property indicator_width3 2
#property indicator_style3 STYLE_SOLID
#property indicator_color3 clrFireBrick
#property indicator_label3 "5 SMMA"
//---- input parameters
// 5 LWMA Shift
input string str2zs = "====================5 LWMA============================"; //---
input int InpMA1Period=5; // MA1 period
input int InpMA1Shift=0; // MA1 shift
input ENUM_MA_METHOD InpMA1Method=MODE_LWMA; // MA1 method
input ENUM_APPLIED_PRICE InpMA1Price=PRICE_TYPICAL; //MA1 Applied price
// 13 SMMA Band based on MA2
input string str6as = "======================13 SMMA=========================="; //---
input int InpMA2Period=13; // MA2 period
input int InpMA2Shift=0; // MA2 shift
input ENUM_MA_METHOD InpMA2Method=MODE_SMMA; // MA2 method
input ENUM_APPLIED_PRICE InpMA2Price=PRICE_TYPICAL; // MA2 Applied price
// 5 SMMA
input string str7kp = "==================5 SMMA=============================="; //---
input int InpMA3Period=5; // MA3 period
input int InpMA3Shift=0; // MA3 shift
input ENUM_MA_METHOD InpMA3Method=MODE_SMMA; // MA3 method
input ENUM_APPLIED_PRICE InpMA3Price=PRICE_TYPICAL; // MA3 Applied price
//+------------------------------------------------------------------+
//---- ON OFF Button
//+-------------------------------------+
input string button_note1 = "------------------------------";
input ENUM_BASE_CORNER btn_corner = CORNER_RIGHT_UPPER; //chart btn_corner for anchoring
input string btn_text = "EMA34";
input string btn_Font = "Arial";
input int btn_FontSize = 10; //btn__font size
input color btn_text_ON_color = clrGreen;
input color btn_text_OFF_color = clrRed;
input color btn_background_color = clrLemonChiffon;
input color btn_border_color = clrBlack;
input int button_x =100; //btn__x
input int button_y = 13; //btn__y
input int btn_Width = 60; //btn__width
input int btn_Height = 20; //btn__height
input string button_note2 = "------------------------------";
bool show_data = true;
string IndicatorName, IndicatorObjPrefix, buttonId;
int rates_total_global = 0; // Globally Scoped copy of "rates_total" (if required)
int prev_calculated_global = 0; // Globally Scoped copy of "prev_calculated"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GenerateIndicatorName(const string target) //don't change anything here
{
string name = target;
int try
= 2;
while(ChartWindowFind(ChartID(),name) != -1)
{
name = target + " #" + IntegerToString(try
++);
}
return name;
}
//+------------------------------------------------------------------+
//---- indicator buffers
double ExtMA1[];
double ExtMA2[];
double ExtMA3[];
//---- handles for moving averages
int ExtMA1Handle; //5LWMA
int ExtMA2Handle; // 13 SMMA
int ExtMA3Handle; // 5 SMMA
//--- bars minimum for calculation
int ExtBarsMinimum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//------ ON OFF Button
//--------------------------
IndicatorName = GenerateIndicatorName(btn_text);
IndicatorObjPrefix = "__" + IndicatorName + "__";
IndicatorSetString(INDICATOR_SHORTNAME,IndicatorName);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
double val;
if(GlobalVariableGet(IndicatorName + "_visibility", val))
show_data = val != 0;
//--------
ChartSetInteger(ChartID(), CHART_EVENT_MOUSE_MOVE, 1);
buttonId = IndicatorObjPrefix + "Moving Average Price Action"; //---------->>> //don't forget to change name here
//--- create ON OFF button
createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, clrGreen);
ObjectSetInteger(ChartID(), buttonId, OBJPROP_YDISTANCE, button_y);
ObjectSetInteger(ChartID(), buttonId, OBJPROP_XDISTANCE, button_x);
//--------------------------
// put init() here
init2();
//start2();
//--- initialization done
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
handleButtonClicks();
recalc = false;
if(show_data)
{
init2();
start2();
}
else
{
}
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init2()
{
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMA1,INDICATOR_DATA);
SetIndexBuffer(1,ExtMA2,INDICATOR_DATA);
SetIndexBuffer(2,ExtMA3,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMA1Period-1);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpMA2Period-1);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpMA3Period-1);
//---- line shifts when drawing
PlotIndexSetInteger(0,PLOT_SHIFT,InpMA1Shift);
PlotIndexSetInteger(1,PLOT_SHIFT,InpMA2Shift);
PlotIndexSetInteger(2,PLOT_SHIFT,InpMA3Shift);
//---- name for DataWindow
PlotIndexSetString(0,PLOT_LABEL,"MA1("+string(InpMA1Period)+")");
PlotIndexSetString(1,PLOT_LABEL,"MA2("+string(InpMA2Period)+")");
PlotIndexSetString(2,PLOT_LABEL,"MA3("+string(InpMA3Period)+")");
//--- get MA's handles
ExtMA1Handle=iMA(NULL,0,InpMA1Period,0,InpMA1Method,InpMA1Price);
ExtMA2Handle=iMA(NULL,0,InpMA2Period,0,InpMA2Method,InpMA2Price);
ExtMA3Handle=iMA(NULL,0,InpMA3Period,0,InpMA3Method,InpMA3Price);
//--- bars minimum for calculation
ExtBarsMinimum=InpMA1Period+InpMA1Shift;
if(ExtBarsMinimum<(InpMA2Period+InpMA2Shift))
ExtBarsMinimum=InpMA2Period+InpMA2Shift;
if(ExtBarsMinimum<(InpMA3Period+InpMA3Period))
ExtBarsMinimum=InpMA3Period+InpMA3Period;
return(INIT_SUCCEEDED);
//--- initialization done
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start2()
{
return(INIT_SUCCEEDED);
//--- initialization done
}
//+------------------------------------------------------------------+
//| OnCalculate function |
//+------------------------------------------------------------------+
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 &TickVolume[],
const long &Volume[],
const int &Spread[])
{
//--- check for rates total
rates_total_global = rates_total; // Update Global copy (if required)
prev_calculated_global = prev_calculated; // Update Global copy
if(rates_total_global<ExtBarsMinimum)
return(0); // not enough bars for calculation
//------------------------------------------------------------------
// Main
//--- not all data may be calculated
//+------------------------------------------------------------------+
int calculated=BarsCalculated(ExtMA1Handle);
if(calculated<rates_total_global)
{
Print("Not all data of ExtMA1Handle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//+------------------------------------------------------------------+
calculated=BarsCalculated(ExtMA2Handle);
if(calculated<rates_total_global)
{
Print("Not all data of ExtMA2Handle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//+------------------------------------------------------------------+
calculated=BarsCalculated(ExtMA3Handle);
if(calculated<rates_total_global)
{
Print("Not all data of ExtMA3Handle is calculated (",calculated,"bars ). Error",GetLastError());
return(0);
}
//--- we can copy not all data
int to_copy;
if(prev_calculated_global>rates_total_global || prev_calculated_global<0)
to_copy=rates_total_global;
else
{
to_copy=rates_total_global-prev_calculated_global;
if(prev_calculated_global>0)
to_copy++;
}
//---- get ma buffers
if(IsStopped())
return(0); //Checking for stop flag
if(CopyBuffer(ExtMA1Handle,0,0,to_copy,ExtMA1)<=0)
{
Print("getting ExtMA1Handle is failed! Error",GetLastError());
return(0);
}
//+------------------------------------------------------------------+
if(IsStopped())
return(0); //Checking for stop flag
if(CopyBuffer(ExtMA2Handle,0,0,to_copy,ExtMA2)<=0)
{
Print("getting ExtMA2Handle is failed! Error",GetLastError());
return(0);
}
//+------------------------------------------------------------------+
if(IsStopped())
return(0); //Checking for stop flag
if(CopyBuffer(ExtMA3Handle,0,0,to_copy,ExtMA3)<=0)
{
Print("getting ExtMA3Handle is failed! Error",GetLastError());
return(0);
}
//+------------------------------------------------------------------+
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void createButton(string buttonID,string buttonText,int width,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor)
{
ObjectDelete(ChartID(),buttonID);
ObjectCreate(ChartID(),buttonID,OBJ_BUTTON,0,0,0);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_COLOR,txtColor);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_BGCOLOR,bgColor);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_BORDER_COLOR,borderColor);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_XSIZE,width);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_YSIZE,height);
ObjectSetString(ChartID(),buttonID,OBJPROP_FONT,font);
ObjectSetString(ChartID(),buttonID,OBJPROP_TEXT,buttonText);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_FONTSIZE,fontSize);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_SELECTABLE,0);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_CORNER,btn_corner);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_HIDDEN,1);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_XDISTANCE,9999);
ObjectSetInteger(ChartID(),buttonID,OBJPROP_YDISTANCE,9999);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------------------------------------------------------+
int deinit()
{
ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
//put deinit() here
return(0);
}
//+------------------------------------------------------------------------------------------------------------------+
//don't change anything in this function
bool recalc = true;
void handleButtonClicks()
{
if(ObjectGetInteger(ChartID(), buttonId, OBJPROP_STATE))
{
ObjectSetInteger(ChartID(), buttonId, OBJPROP_STATE, false);
show_data = !show_data;
GlobalVariableSet(IndicatorName + "_visibility", show_data ? 1.0 : 0.0);
recalc = true;
start();
}
}
//+------------------------------------------------------------------------------------------------------------------+
void OnChartEvent(const int id, //don't change anything in this function
const long &lparam,
const double &dparam,
const string &sparam)
{
handleButtonClicks();
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------------------------------------------------------+
//+------------------------------------------------------------------+