iCustom value does not match the buffer value???

 

Hi 

 I'm new to programming in mql4 so apologize in advance if I offend anyone with my questions.

 My issue is I am trying to use a custom indicator (Pinbar - https://www.mql5.com/en/code/1768) in a EA using the "iCustom" function. For some reason the values shown in Data Window for the buffers used in 'pinbar' indicator does not match the values obtained in the EA. I have attached the screenshot and the EA file I used to test the buffers (it is very basic).

 I would greatly appreciate any assistance or solutions for this issue. I have searched online but unfortunately have not found any solutions.

Thank You 

 

 P.s. I did not attach the 'pinbar' file as it is not mine but it can easily be downloaded from the link above from its rightful owner.

PinBar
PinBar
  • votes: 24
  • 2013.07.31
  • Andrey Shpilev
  • www.mql5.com
An indicator of pin bars, to be used as a built-in indicator in Expert Advisors. Shows levels specified by the pattern for the open price and stop-loss.
Files:
Display.png  76 kb
mock.mq4  2 kb
 
Jabz732: My issue is I am trying to use a custom indicator (Pinbar - https://www.mql5.com/en/code/1768) in a EA using the "iCustom" function. For some reason the values shown in Data Window for the buffers used in 'pinbar' indicator does not match the values obtained in the EA.
  1. Please use the link button (control-K.) See the difference: https://www.mql5.com/en/code/1768
  2. Don't post a link to or attach a image, insert the image Use the image button
  3. For small amounts of code just paste it
    Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

    int start(){
       double openn, stopp;
       openn = iCustom(NULL, 0, "pinbar",0, 1);
       stopp = iCustom(NULL, 0, "pinbar",1, 1);  
       Print("This is the Opeh ", openn);
       Print("This is the Stop ", stopp);
  4. Your image shows the values from iCustom is the MQ4 constant

    EMPTY_VALUE

    Empty value in an indicator buffer. Default custom indicator empty value

    2147483647 (0x7FFFFFFF)

    But your link is a MT5 indicator so it can't produce the value in your image.
  5. The data window shows you have the mouse over bar 10.25 16:00 but your iCustom/Print shows only bar zero (10.28 20:00) values, so of course they don't match. and since bar zero is not a pin bar, you expect no arrow, you expect EMPTY_VALUE.
PinBar
PinBar
  • votes: 24
  • 2013.07.31
  • Andrey Shpilev
  • www.mql5.com
An indicator of pin bars, to be used as a built-in indicator in Expert Advisors. Shows levels specified by the pattern for the open price and stop-loss.
 
whroeder1:
  1. Please use the link button (control-K.) See the difference: https://www.mql5.com/en/code/1768
  2. Don't post a link to or attach a image, insert the image
  3. For small amounts of code just paste it
    Please edit your post.
    For large amounts of code, attach it.

    int start(){
       double openn, stopp;
       openn = iCustom(NULL, 0, "pinbar",0, 1);
       stopp = iCustom(NULL, 0, "pinbar",1, 1);  
       Print("This is the Opeh ", openn);
       Print("This is the Stop ", stopp);
  4. Your image shows the values from iCustom is the MQ4 constant

    EMPTY_VALUE

    Empty value in an indicator buffer. Default custom indicator empty value

    2147483647 (0x7FFFFFFF)

    But your link is a MT5 indicator so it can't produce the value in your image.
  5. The data window shows you have the mouse over bar 10.25 16:00 but your iCustom/Print shows only bar zero (10.28 20:00) values, so of course they don't match. and since bar zero is not a pin bar, you expect no arrow, you expect EMPTY_VALUE.

Hi whroeder1

 Thank you for your reply. I will use the methods specified in steps 1 - 3.

So in response to step 4 - > Does that mean I cannot obtain the value from the data window because it is a mt5 indicaor? (Although it is a mt5 indicator it is still working?)

 Step 5 - >  Notice the data window shows the bar corresponding to 10.25 16:00 has a green x (buffer 0) and a red x (buffer 1) plotted by the indicator. The values shown in the data window are not shown in the journal where I have highlighted the values shown. It is the default value for 'EMPTY_VALUE' but at that bar the buffers are not empty clearly (data window). Is this because MT5 indicators are not compatible with MT4? If so why does it work on MT4? Also how can I obtain what I am after (can I convert the code to MT4 somehow).

 Thank You kindly for your response 

 
Jabz732:

So in response to step 4 - > Does that mean I cannot obtain the value from the data window because it is a mt5 indicaor? (Although it is a mt5 indicator it is still working?)

Step 5 - >  Notice the data window shows the bar corresponding to 10.25 16:00 has a green x (buffer 0) and a red x (buffer 1) plotted by the indicator. The values shown in the data window are not shown

  1. You are not running the MQL5 indicator, that does not use that value as empty. Your link is wrong. You are running a MQL4 indicator.
  2. What do you mean not shown?
  3. You are printing out bar zero at the beginning of the bar. Therefor no bar will be printed as a pin bar.
 
whroeder1:
  1. You are not running the MQL5 indicator, that does not use that value as empty. Your link is wrong. You are running a MQL4 indicator.
  2. What do you mean not shown?
  3. You are printing out bar zero at the beginning of the bar. Therefor no bar will be printed as a pin bar.

Hi 

Sorry I think I have not explained my problem properly.

 

Ok, let's use the values shown in the Data window    how would I for example place an order to buy on the following candle when/if the price reaches "OpenBuffer = 1.2217"?

It'll be something like this right?

int start()
  {
   double openn, stopp;
  
       openn = iCustom(NULL, 0, "pinbar",0, 1);
       stopp = iCustom(NULL, 0, "pinbar",1, 1);  
  

int total, ticket;
  // expire = TimeCurrent()+(60*60*12); //expire after 12 hours
   total = OrdersTotal();
   if(total<1)
   {
       if ((openn != EMPTY_VALUE && stopp != EMPTY_VALUE) && (openn > stopp))
          {  
            ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, stopp, Ask+(profits*Point), "EA",11111,0,Green);
              if (ticket>0)
                {
                  if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
                   Print("BUY order opened: ",OrderOpenPrice());
                }
             else
                  Print("Error opening BUY order: ",GetLastError());
             return(0);
          }  
       if ((openn != EMPTY_VALUE && stopp != EMPTY_VALUE) && (openn < stopp))
          {  
            ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, stopp, Bid-(profits*Point), "EA",11111,0,Red);
              if (ticket>0)
                {
                 if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))  
                   Print("SELL order opened: ",OrderOpenPrice());  
                }  
              else    
                   Print("Error opening SELL order: ",GetLastError());
               return(0);
           }
           return(0);
      }
        
//+----------  
   return(0);
  }

The EA dose not place any orders as 'openn and stopp = EMPTY_VALUES' only and not the values in the data window?

 

Kind Regards 
 

 

       openn = iCustom(NULL, 0, "pinbar",0, 1);
       stopp = iCustom(NULL, 0, "pinbar",1, 1);  

I haven't checked for a while, but I believe that you have to include the indicator parameters with iCustom. I know that the documentation states that the default input parameters will be used if they are not specified, but I have not found this to be the case.

Try it including the parameters.

 
Keith Watford: I haven't checked for a while, but I believe that you have to include the indicator parameters with iCustom. I know that the documentation states that the default input parameters will be used if they are not specified, but I have not found this to be the case.
  1. OPs original problem was looking at bar zero on the first tick.
  2. I'm not sure either, but I always recommend write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum
 
whroeder1:
  1. ...
  2. I'm not sure either, but I always recommend write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum

Keith Watford:

...
I know that the documentation states that the default input parameters will be used if they are not specified, but I have not found this to be the case.

It's the case. Parameters not set are using default values (hardcoded in indicator source code).
 
Keith Watford:

       openn = iCustom(NULL, 0, "pinbar",0, 1);
       stopp = iCustom(NULL, 0, "pinbar",1, 1);  

I haven't checked for a while, but I believe that you have to include the indicator parameters with iCustom. I know that the documentation states that the default input parameters will be used if they are not specified, but I have not found this to be the case.

Try it including the parameters.

Hi Keith and Whroeder1

Thank You for your advice unfortunately it didn't work. I changed the code to the following but it still cannot read the buffer values for the pinbars. Any further advice? 

int start()
  {
  #define Pinbar "pinbar"
  #define Openn 0
  #define Stopp 1
  
   int      MinBarSize=200;

   int      PriceOffset=50;

  double   BarRatio=2.2;

  double   TailRatio=1.3;

  #define  UseBodyDirection false

  #define  UseCloseThirds  true

  int      ExtremumOfBars=10;

  
  
   double OpenBuff, StopBuff;

        OpenBuff = iCustom(NULL, 0, Pinbar, MinBarSize, PriceOffset, BarRatio, TailRatio, UseBodyDirection, UseCloseThirds,ExtremumOfBars, Openn, 1);
        StopBuff = iCustom(NULL, 0, Pinbar, MinBarSize, PriceOffset, BarRatio, TailRatio, UseBodyDirection, UseCloseThirds,ExtremumOfBars, Stopp, 1);
      
        
         Print("This is the Open ", OpenBuff);
         Print("This is the Stop ", StopBuff);

//+----------   

   return(0);

   } 

 
Is bar one a pinbar?
 
whroeder1:
If bar one a pinbar?

 

I think the problem is that the indicator does not draw the buffers straight away once it forms but rather after sometime e.g below

 

Do you have any advice on how I could get it to display straight away?