how to load the indicator on chart when EA is running?

 

Hi,

I'm new to MQ4 coding. I hit some problem when using customer indicator in my EA.

I coded an EA that use an existing indicator. When I run my EA, the indicator is loaded in the chart and I'm able to use the buffer of the indicator. See attached 1. I can see from the log that after EA is loaded successfully, the indicator is also loaded successfully.

I then created my own indicator and change my EA code to call the new indicator but I have problem getting the indicator loaded onto the chart when I run the EA. See attached 2. I can see from the log that the EA is loaded successfully but there isn't any indication that the indicator is loaded successfully. But I can see the Print from the indicator from the log. And I can also use all the buffer in the indicator in the EA. Just that the indicator is not display on the chart and I have to deploy it separately. 

Can I know how to make the indicator loaded when I run the EA?

 
cpliew:

Hi,

I'm new to MQ4 coding. I hit some problem when using customer indicator in my EA.

I coded an EA that use an existing indicator. When I run my EA, the indicator is loaded in the chart and I'm able to use the buffer of the indicator. See attached 1. I can see from the log that after EA is loaded successfully, the indicator is also loaded successfully.

Nothing is attached.

I then created my own indicator and change my EA code to call the new indicator but I have problem getting the indicator loaded onto the chart when I run the EA. See attached 2. I can see from the log that the EA is loaded successfully but there isn't any indication that the indicator is loaded successfully. But I can see the Print from the indicator from the log. And I can also use all the buffer in the indicator in the EA. Just that the indicator is not display on the chart and I have to deploy it separately. 

Can I know how to make the indicator loaded when I run the EA?

Nothing is attached.

Please show your code if you need coding help.

 
cpliew:

sorry for that.

You will not receive any help providing a screenshot of the code. Provide the code directly !

 

Here is the code the EA calling the indicator. Let me know if I need to attach the code of the indicator. The log is as above on the 2 attachment. Hope this is sufficient information to request for assistant.

//+------------------------------------------------------------------+
int CheckEntry(int dir){
 
   double entry_pr,InpSl_pr;
   
   //checking for major signal
   if(dir==0){
      double indValue = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,0,1);
      if(indValue>0 && indValue!=EMPTY_VALUE){
            dir=1;
            entry_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,6,1);
            InpSl_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,8,1);
            InpSl = (((entry_pr - InpSl_pr)*dir)/POINT)-spread;
            InpTp = InpSl * InpTP2factor;
            Print("minSL : ",InpIndMinSL," Max SL : ",InpIndMaxSL," TP : ",InpTp," SL : ",InpSl);
      }else{
         indValue = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,1,1);
         if(indValue>0 && indValue!=EMPTY_VALUE){
               dir=-1;
               entry_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,7,1);
               InpSl_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,9,1);
               InpSl = (((entry_pr - InpSl_pr)*dir)/POINT)-spread;
               InpTp = InpSl * InpTP2factor;
               Print("minSL : ",InpIndMinSL," Max SL : ",InpIndMaxSL," TP : ",InpTp," SL : ",InpSl);
         }
      }
   }
   
   // checking for minor signal
   if(dir==0 && InpTradeMinor == true){
      double indValue = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,4,1);
      if(indValue>0 && indValue!=EMPTY_VALUE){
            dir=1;
            
            entry_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,18,1);
            InpSl_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,19,1);
            InpSl = (((entry_pr - InpSl_pr)*dir)/POINT)-spread;
            InpTp = InpSl * InpTP2factor;
            Print("minSL : ",InpIndMinSL," Max SL : ",InpIndMaxSL," TP : ",InpTp," SL : ",InpSl);
      }else{
         indValue = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,5,1);
         if(indValue>0 && indValue!=EMPTY_VALUE){
               dir=-1;
               
               entry_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,20,1);
               InpSl_pr    = iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,21,1);
               InpSl = (((entry_pr - InpSl_pr)*dir)/POINT)-spread;
               InpTp = InpSl * InpTP2factor;
               Print("minSL : ",InpIndMinSL," Max SL : ",InpIndMaxSL," TP : ",InpTp," SL : ",InpSl);
         }
      }
   }
   
   return dir;
}
 
cpliew: I have problem getting the indicator loaded onto the chart when I run the EA.
  1. EAs have no eyes; they don't need the indicator displayed on the chart. If you want to see the indicator's lines displayed, you put it on the chart.
  2. You should encapsulate your iCustom calls to make your code self-documenting.
 
whroeder1:
  1. EAs have no eyes; they don't need the indicator displayed on the chart. If you want to see the indicator's lines displayed, you put it on the chart.
  2. You should encapsulate your iCustom calls to make your code self-documenting.

#2 - Nailed it. 

double Ind(const int val)
{
   return iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,val,1);
}
 
nicholishen :

#2 - Nailed it. 


You lacked the index (bar)


double Ind(const int buffer, const int index)
{
   return iCustom(_Symbol,0,ind_name,InpIndMinSL,InpIndMaxSL,InpTP1factor,InpTP2factor,InpIndPeriod,InpmedMA,InpfastMA,buffer,index);
}