Can some kind person tell me where I am wrong?

 
I am trying to solve a problem.


**** I have corrected errors based on feedback from Raptor and deVries ***

Values from the indicator

Long Buffer 0 +ve (iCustom(NULL, NULL, "Signal_Indi",12,0,1)
Short Buffer 1 -ve (iCustom(NULL, NULL, "Signal_Indi",12,1,1)

For Long I test for "Bulls" Buffer 0 > "Bears" Buffer 1. The values are always positive numbers with 4 decimal places.

On the LONG side of the branch the code is:

if (MathAbs(iCustom(NULL, 0, "Signal_Indi",12,0,1) - iCustom(NULL, 0, "Signal_Indi",12,1,1)) > Multiplier * iCustom(NULL, 0, "Signal_Indi",12,1,1))
 

*** Corrected here too ***

I want to test for Bulls > Bears by a ratio instead of a minimum difference value. This is because when I am dealing with any pair with JPY the values are quite different e.g EURUSD 0.0010 but EURJPY 0.1000.


Example if Bulls 0.0025 (or 0.2500 if JPY) and Bears is 0.0012 (or 0.1200 if JPY) the ratio is > 2:1. So a Multiplier test for (say) 0.0025 > 2 * 0.0012 = TRUE

I defined the Multiplier as a double to permit me trying values such as 1.5 so I'm not stuck with whole numbers only.

MetaEditor compiles this without errors or warnings. Trades are opened but not as I would expect to see when I observe in slow-motion on strategy tester.

I confess I guessed the MathAbs was the right way to do the calculation I was trying to achieve. And now I am unsure.

Is my logic and way of solving this correct or in error?
 

First issue . . . maybe, in reference to iCustom what is the value of NULL for the timeframe ? did you mean 0 as in the current chart timeframe ?

In your example the difference between your bull and bear values is 0.0012 . . . so where do you get 0.0036 from ?

Add plenty of Print statements so you can see what your variables are at key places in your code . . .

 

If it is the same indicator the values come from

then why do you use two different names ?? for this indicator ?

 
Many thanks for this feedback. I have corrected my original post to remove the inconsistencies in my question. I did not know I ought to use 0 in TimeFrame - the raw EA code is produced by EA Generator application. I have learned a new thing here and will always replace the NULL with 0.

Should I also change the NULL for the instrument?

I will now go looking in the MQL codebase to see if I can find how to make a print statement - that would be very usefull.

Does the revised code appear correct?

 
Look in the Documentation . . . Print . . . iCustom
 
Thanks very much for this info. I have learned a new thing. May I ask about the effect of using NULL instead of 0? The docs.mql4 says to use 0 or PERIOD_xx and I have always accepted the code generated by EA Builder as correct. So using NULL instead of 0 might have been a big problem? For sure, I will always replace the NULL with a 0 henceforth.
 
NewtonLeo:
Thanks very much for this info. I have learned a new thing. May I ask about the effect of using NULL instead of 0? The docs.mql4 says to use 0 or PERIOD_xx and I have always accepted the code generated by EA Builder as correct. So using NULL instead of 0 might have been a big problem? For sure, I will always replace the NULL with a 0 henceforth.


double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)
Calculates the specified custom indicator and returns its value. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\experts\indicators directory.

Parameters:

symbol - Symbol the data of which should be used to calculate indicator. NULL means current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
name - Custom indicator compiled program name.
... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.
mode - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

Sample:
  double val=iCustom(NULL, 0, "SampleInd",13,1,0);

iCustom(NULL, 0, "Signal_Indi",12,0,1)

What type is here NULL double ??? int ???? string ???? datetime ?????? color ????

and what type is first '0' in this formule

 
deVries:


double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)
Calculates the specified custom indicator and returns its value. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\experts\indicators directory.

Parameters:

symbol - Symbol the data of which should be used to calculate indicator. NULL means current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
name - Custom indicator compiled program name.
... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.
mode - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
Sample:

iCustom(NULL, 0, "Signal_Indi",12,0,1)

What type is here NULL double ??? int ???? string ???? datetime ?????? color ????

and what type is first '0' in this formule

it's iCustom(NULL, 0, "IndiName",12,0,1) NULL is the current symbol, 0 for current timeframe, 12 period, Buffer 0, Closed candle.

I managed to print the values to the screen so the indicator settings are working. A typical result is 0.0012 so it's a double if I understand correctly. I am trying to get around having to use new values when a JPY pair is involved; hence I'm trying to use ratios.

The only thing I can't verify is if my formula is working because I'm not proficient at where and how to place the print to log. The EA works in strategy testing but I have never read about how to use the magnitude check for one value x being > * times the other

ie.
if (MathAbs(iCustom(..Buffer 0,1) - iCustom( Buffer 1,1)) > Multiplier * iCustom(..Buffer 1,1))
Does this help clarify? I appreciate any input here as I have "L" plates on
 
 

I did not explain myself clearly in my initial post and apologise for my ambiguous and unclear question. I hope this is clear and unambiguous. I am asking only for confirmation it "seems" valid code.

This is the indicator window. Green is Buffer 0 and Red is Buffer 1

I am trying to overcome the issue about xxxJPY values being numerically different to all other pairs by using the indicator output values relative difference so I don't have to keep editing default (say) 0.0001 for (say) EURUSD to 0.01 for (say) EURJPY. I could use a set file but it seems more practical to use ratios. However, when I searched to see if I could do this, I found no reference so came up with the code below.

To illustrate, you can see in the above screenshot the Green bars are increasing while the Red bars are reducing. My trigger to open an order is when the value of Green bars is numerically greater than 2 times the Red bar (if Multiplier = 2.00). I defined Multiplier variable as a double (double Multiplier = 2.00;) thinking I can use (say) 1.75 as a multiplier rather than being stuck with int whole numbers 1,2,3 etc.

The equation I am using is below. It compiles without errors and "seems" to be working as I hoped. I am a novice coder and have in the past made some stupid blunders (like defining an int with a value of 0.0025). I am still learning and only yesterday learned I should use 0 or specified PERIOD_XX and not "NULL" as I was doing prior to yesterday. I am asking only if the code on face value will work as I envisaged withiot me learning days or weeks later that something about it is another blunder.

if (MathAbs(iCustom(NULL, 0, "SampleIndi",0,1) - iCustom(NULL,0, "SampleIndi",1,1)) > Multiplier * iCustom(NULL, 0, "SampleIndi",1,1))
Reason: