Code Running Success fully in Under Customer Indicator But Not In Expert Advisor

To add comments, please log in or register
SELVAN26
16
SELVAN26  

Dear Sir,

 

I Had Written An Code And I Had Save As Mq4 ( Custom Indicator  ( Mq4 File ) )Under Meta Editor  And I Had Run The Code Without Any Error , The Output Of The Code  Is Running In Chart Window As Expected But When I Use Same Code Under Expert Advisor And I Compile The Same Code Under Expert Advisor It Run Without Error But When I Try To Run The Code ( Ex4 File ) The Output Is Not Showing, I Am Copy And Pasting The Same Code For Your Consideration Please Help Me To Fix The Problem

 

Thank You Sir


//+------------------------------------------------------------------+
//|                                                       BUTTON.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


string Buy_ButtonID  ="Buy_Button";

string Sell_ButtonID ="Sell_Button";

string Short_Sell_ButtonID ="Short_Sell_Button";

string Short_Cover_ButtonID ="Short_Cover_Button";




//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
  
  
  
  
  
//--- Create a button to send custom events

//================== Buy Button

   ObjectCreate(0,Buy_ButtonID,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_BGCOLOR,clrDarkGreen);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_XDISTANCE,10);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_YDISTANCE,20);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_XSIZE,150);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_YSIZE,40);
   ObjectSetString(0,Buy_ButtonID,OBJPROP_FONT,"TimesNewRoman");
   ObjectSetString(0,Buy_ButtonID,OBJPROP_TEXT,"Buy");
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_SELECTABLE,0);
   ObjectSetInteger(0,Buy_ButtonID,OBJPROP_BORDER_COLOR,clrWhite);

 
 //=============== sell Button
 
 
 
   ObjectCreate(0,Sell_ButtonID,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_BGCOLOR,clrRed);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_XDISTANCE,170);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_YDISTANCE,20);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_XSIZE,150);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_YSIZE,40);
   ObjectSetString(0,Sell_ButtonID,OBJPROP_FONT,"TimesNewRoman");
   ObjectSetString(0,Sell_ButtonID,OBJPROP_TEXT,"Sell");
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_SELECTABLE,0);
   ObjectSetInteger(0,Sell_ButtonID,OBJPROP_BORDER_COLOR,clrWhite);
 
 
 
 
 //=============== Short Sell Button
 
 
   ObjectCreate(0,Short_Sell_ButtonID,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_BGCOLOR,clrRed);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_XDISTANCE,170);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_YDISTANCE,70);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_XSIZE,150);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_YSIZE,40);
   ObjectSetString(0,Short_Sell_ButtonID,OBJPROP_FONT,"TimesNewRoman");
   ObjectSetString(0,Short_Sell_ButtonID,OBJPROP_TEXT,"Short Sell");
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_SELECTABLE,0);
   ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_BORDER_COLOR,clrWhite);
 
 
 //=============== Short Cover Button
 
 
 
 
   ObjectCreate(0,Short_Cover_ButtonID,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_BGCOLOR,clrGreen);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_XDISTANCE,10);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_YDISTANCE,70);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_XSIZE,150);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_YSIZE,40);
   ObjectSetString(0,Short_Cover_ButtonID,OBJPROP_FONT,"TimesNewRoman");
   ObjectSetString(0,Short_Cover_ButtonID,OBJPROP_TEXT,"Short Cover");
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_SELECTABLE,0);
   ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_BORDER_COLOR,clrWhite);
 
 
 //OBJPROP_BORDER_COLOR
 
 
  ChartRedraw(0);
 
 
  

   return(INIT_SUCCEEDED);
}
 
 
 
 
 void OnDeinit(const int reason)
  {

  ObjectDelete(0,Buy_ButtonID);
 
  }
 
 
 
  
 
 
 
 
//+------------------------------------------------------------------+
//| Custom indicator iteration 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 &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---









  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
  
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {




//---
 
 
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      string clickedChartObject=sparam;
      //--- If you click on the object with the name Buy_ButtonID
      if(clickedChartObject==Buy_ButtonID)
        {
         //--- State of the button - pressed or not
         bool selected=ObjectGetInteger(0,Buy_ButtonID,OBJPROP_STATE);
 
 
  if(selected=="true")
           {
           
            // run code example Alert ( your Buy Code Executed )

             Alert ( "Buy Order Send " );
           
            // reseting the Pressed Button
           
          
            //Sleep(10000);
           
            bool selected = ObjectSetInteger(0,Buy_ButtonID,OBJPROP_STATE,false);

           
           }
       
 
  }// buy clieck ends

}

//=====================================================================



if(id==CHARTEVENT_OBJECT_CLICK)
     {


    
      string clickedChartObject=sparam;
      //--- If you click on the object with the name Buy_ButtonID
      if(clickedChartObject==Sell_ButtonID)
        {


Alert ( "Sell Order Send ");


bool selected = ObjectSetInteger(0,Sell_ButtonID,OBJPROP_STATE,false);

        }

     }
 
 
//=====================================================================


if(id==CHARTEVENT_OBJECT_CLICK)
     {


    
      string clickedChartObject=sparam;
      //--- If you click on the object with the name Buy_ButtonID
      if(clickedChartObject==Short_Sell_ButtonID)
        {


Alert ( " Short Sell Order Send ");


bool selected = ObjectSetInteger(0,Short_Sell_ButtonID,OBJPROP_STATE,false);

        }

     }

//=====================================================================


if(id==CHARTEVENT_OBJECT_CLICK)
     {


    
      string clickedChartObject=sparam;
      //--- If you click on the object with the name Buy_ButtonID
      if(clickedChartObject==Short_Cover_ButtonID)
        {


Alert ( " Short Cover Order Send ");


bool selected = ObjectSetInteger(0,Short_Cover_ButtonID,OBJPROP_STATE,false);

        }

     }



  }
 
 
 
 
 
  
 
//+------------------------------------------------------------------+
To add comments, please log in or register