Custom Indicator Bug? Wrong Values given. Help Please.

To add comments, please log in or register
franzzzz
58
franzzzz  

Hi, Im programming an EA that calls a Custom Indicator for values.


EA goes something like this:

int init() 
  {
      Alert("Initializing");
 
      itrend_1 = iCustom(currency,PERIOD_D1,indicator,0,1);
      itrend_2 = iCustom(currency,PERIOD_D1,indicator,0,2);
      
      trigger_1 = iCustom(currency,PERIOD_D1,indicator,1,1);
      trigger_2 = iCustom(currency,PERIOD_D1,indicator,1,2); 
      
      //Testing the values of the indicator
      Alert("Initialize itrend_1:",itrend_1);
      Alert("Initialize itrend_2:",itrend_2);
      Alert("Initialize trigger_2:",trigger_2);
      Alert("Initialize trigger_1:",trigger_1);   
  }

int start()
  {
      pFunction01(); //Finding ATR
      pFunction02(); //Readying Position Size   
      
      trigger_1 = iCustom(NULL,PERIOD_D1,indicator,1,1);
      trigger_2 = iCustom(NULL,PERIOD_D1,indicator,1,2); 
      
      itrend_1= iCustom(NULL,PERIOD_D1,indicator,0,1);
      itrend_2= iCustom(NULL,PERIOD_D1,indicator,0,2);
      
      //Testing the values of the indicator
      Alert("Initialize itrend_1:",itrend_1);
      Alert("Initialize itrend_2:",itrend_2);
      Alert("Initialize trigger_2:",trigger_2);
      Alert("Initialize trigger_1:",trigger_1); 
      
      int waitbars = 1;
      int barshift = iBarShift(currency,PERIOD_D1,timesent);

      if (barshift>=waitbars)
         {
            system01(); //Trading system
         } 
  }

int deinit()
  {
      Alert("Deinitializing");
      
      //Testing the values of the indicator
      var0= iCustom(currency,PERIOD_D1,indicator,0,0);
      var1= iCustom(currency,PERIOD_D1,indicator,0,1);
      var2= iCustom(currency,PERIOD_D1,indicator,0,2);
      var3= iCustom(currency,PERIOD_D1,indicator,0,3);
      var4= iCustom(currency,PERIOD_D1,indicator,0,4);
      var5= iCustom(currency,PERIOD_D1,indicator,0,5);
      var6= iCustom(currency,PERIOD_D1,indicator,0,6);
      var7= iCustom(currency,PERIOD_D1,indicator,0,7);
      var8= iCustom(currency,PERIOD_D1,indicator,0,8);
      Print("var0:", var0);
      Print("var1:", var1);
      Print("var2:", var2);
      Print("var3:", var3);
      Print("var4:", var4);
      Print("var5:", var5);
      Print("var6:", var6);
      Print("var7:", var7);
      Print("var8:", var8);
               
  }

The EA gives correct values of the Trendline Custom Indicator in the INIT and DEINIT part. What confuses me are the wrong values seen on the START. Its a little confusing and I have spent hours reading and testing/debugging this. Please can someone give some help/advice? ANything is greatly appreciated!
 


EDITED: This was on the TESTER. ONLY "trigger_2" and "trigger_1" are correct on all INIT, DEINIT, START. itrend_1 and itrend_2 are all wrong on START ONLY.

Kaleem Haider
113457
Kaleem Haider  
franzzzz:

Hi, Im programming an EA that calls a Custom Indicator for values.


EA goes something like this:

The EA gives correct values of the Trendline Custom Indicator in the INIT and DEINIT part. What confuses me are the wrong values seen on the START. Its a little confusing and I have spent hours reading and testing/debugging this. Please can someone give some help/advice? ANything is greatly appreciated!
 


I assume you have externally defined variable "currency" in the formula in init and deinit.  If so, you will have to change the formula in start to iCustom(currency,PERIOD_D1....) as well.

itrend_1 = iCustom(currency,PERIOD_D1,indicator,0,1);
franzzzz
58
franzzzz  
Kaleem Haider:

I assume you have externally defined variable "currency" in the formula in init and deinit.  If so, you will have to change the formula in start to iCustom(currency,PERIOD_D1....) as well.


Yes every variable are Defined. Im just testing if that was the culprit as the problem is really confusing. I can change all the "variables" to NULL/default, but still get wrong values.


I should mention that the wrong values got are when Im testing the TESTER.

EDIT: Variables are defined Globally.
franzzzz
58
franzzzz  

I basically just copy/paste the INIT contents to the start and had different values on the alert? ANyone experienced this?

William Roeder
20210
William Roeder  
var0= iCustom(currency,PERIOD_D1,indicator,0,0);
var1= iCustom(currency,PERIOD_D1,indicator,0,1);
  1. On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Don't mix apples and oranges.

  3. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference

franzzzz
58
franzzzz  
whroeder1:
  1. On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Don't mix apples and oranges.

  3. You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference


Hi whroeder1,

1. Will check it.

2. I dont get the apples and oranges. everything is in PERIOD_D1. The default tester is D1, default chart is D1. Different "variables" are just for my convenience but i dont think it should give wrong values.

3. I got a little dizzy looking at it. I only know basic programming and its a little complicated for me I think. I think my code above is too simple to need that kind of documentation.

4. Thats what Im doing right now. Im reading it and made a simple EA again based OnTick. Again with the simple code above to get the needed values but still gives wrong values to "itrend_1, itrend_2" on OnTick.

franzzzz
58
franzzzz  

Hi guys,


I think I finally got the values right. It seems that the problem arises from the TESTER doing and computing every tick. I added a code that only get/compute the necessary variables at the start of each bar (in my case Daily). The variables and code looks okay now. 

Im not really sure the logic behind the error. But if anyone can explain it, im sure it wont happen again. 

Let me share here the code (not mine) that only compute each bar once (At the start of each new bar).


void OnTick()
  {
   //Comparing LastActionTime with the current starting time for the candle
   if(LastActiontime!=Time[0]){
      //Code to execute once in the bar
      Print("This code is executed only once in the bar started ",Time[0]);
      
      LastActiontime=Time[0];
   }
   /Every tick code is in here
  }


EDITED: The problem returns again when I used different "Use date" on the TESTER. :( 

William Roeder
20210
William Roeder  
franzzzz: 2. I dont get the apples and oranges. everything is in PERIOD_D1. The default tester is D1, default chart is D1.
var0= iCustom(currency,PERIOD_D1,indicator,0,0);

From your previous post there is no way to know what period your chart is. Your code breaks if you put it on any other chart.

  1. Either handle the different shifts per #4 № 2

  2. Or, don't hard code the periods, and it works on any chart.
franzzzz
58
franzzzz  
whroeder1:

From your previous post there is no way to know what period your chart is. Your code breaks if you put it on any other chart.

  1. Either handle the different shifts per #4 № 2

  2. Or, don't hard code the periods, and it works on any chart.

Initially the variables: currency, timeframe, and indicator are all defined. They are NULL, 1440, "indicator name".  The difference in "naming" (the code posted in this forum as yo usee) is just the result of me trying to solve this unclear problem.

The basic problem is that the values (window chart values) are CORRECT in INIT print, DEINIT print, but are wrong in START print.

Another thing I experimented was that when use on other trend line Custom Indicators, the START print gives correct chart values. Tried using the built in iMA indicators. They are also correct in giving the correct chart values in START print. hmmm sounds like a bug? what do you think?

i was thinking that it could be like a gross "Systematic error" of the system trying to round off, etc. Tried normalizing the values but still incorrect values are given.


EDITED: I also tried changing the currency= NULL, TF = 0. 

int timeframe = 1440;
string indicator = "indicator name";
string currency = NULL;

int init() 
  {
      Alert("Initializing");
 
      itrend_1 = iCustom(currency,timeframe,indicator,0,1);
      itrend_2 = iCustom(currency, timeframe,indicator,0,2);
      trigger_1 = iCustom(currency, timeframe,indicator,1,1);
      trigger_2 = iCustom(currency, timeframe,indicator,1,2); 
      
      //Testing the values of the indicator
      Alert("Initialize itrend_1:",itrend_1);
      Alert("Initialize itrend_2:",itrend_2);
      Alert("Initialize trigger_2:",trigger_2);
      Alert("Initialize trigger_1:",trigger_1);   
  }

int start()
  {
      pFunction01(); //Finding ATR
      pFunction02(); //Readying Position Size   
      

      
      int waitbars = 1;
      int barshift = iBarShift(currency, timeframe,timesent);

      if (barshift>=waitbars)
         {
            
      trigger_1 = iCustom(currency, timeframe,indicator,1,1);
      trigger_2 = iCustom(currency, timeframe,indicator,1,2); 
      itrend_1= iCustom(currency, timeframe,indicator,0,1);
      itrend_2= iCustom(currency, timeframe,indicator,0,2);
      
      //Testing the values of the indicator
      Alert("Initialize itrend_1:",itrend_1);
      Alert("Initialize itrend_2:",itrend_2);
      Alert("Initialize trigger_2:",trigger_2);
      Alert("Initialize trigger_1:",trigger_1); 
system01(); //Trading system          }   } int deinit()   {       Alert("Deinitializing");       trigger_1 = iCustom(currency, timeframe,indicator,1,1);       trigger_2 = iCustom(currency, timeframe,indicator,1,2);       itrend_1= iCustom(currency, timeframe,indicator,0,1);       itrend_2= iCustom(currency, timeframe,indicator,0,2);              //Testing the values of the indicator       Alert("Initialize itrend_1:",itrend_1);       Alert("Initialize itrend_2:",itrend_2);       Alert("Initialize trigger_2:",trigger_2);       Alert("Initialize trigger_1:",trigger_1);                  }

jazzthedog
8
jazzthedog  

I am also experiencing similar problems, I wonder if there was any "fix" to this?

In my case, in the strategy tester "most" of the time the values come back fine from the custom indicator, but once in a while, it produces wrong values. 

The values don't match what I see in the Data window. Its quite strange and I don't have the source code of the custom indicator to try and figure out why.

Thanks.

To add comments, please log in or register