Trying to shift the given information of an indicator by the previous bar for an EA - page 2

 
Seng Joo Thio:

?

All I'm saying is you need to supply the right parameters to your indicator.

ok ok ok. So I took your comment into consideration and I changed the indicator default values in code to match the ones I need. I even went as far as to make them 1's so they would match exactly. The count is correct, the numbers match. 4 buffers with 6 inputs. With the iCustom parameters, that's 3 prerequisites, 6 indie params, 1 buffer param and 1 chart param. Bringing a total count to 11 params for iCustom, which I have. Everything should be correct. Still get the same result of it not advancing. Other than that? I'm not quite sure what you mean by right parameters.

extern int periods=14;
extern double percentSL=1.5;
extern double percentTP1 = 1;
extern double percentTP2 = 1;
extern double percentTP3 = 1;
extern int corner=1;

double ATR_SL=iCustom(NULL,0,"ATR in SL-TP_2",14,1.5,1,1,1,1,0,1);
double ATR_TP=iCustom(NULL,0,"ATR in SL-TP_2",14,1.5,1,1,1,1,1,1);
 
Underworldbros:

ok ok ok. So I took your comment into consideration and I changed the indicator default values in code to match the ones I need. I even went as far as to make them 1's so they would match exactly. The count is correct, the numbers match. 4 buffers with 6 inputs. With the iCustom parameters, that's 3 prerequisites, 6 indie params, 1 buffer param and 1 chart param. Bringing a total count to 11 params for iCustom, which I have. Everything should be correct. Still get the same result of it not advancing. Other than that? I'm not quite sure what you mean by right parameters.


No, I was referring to the default parameter values WITHIN the indicator - the file you attached. They are:

//---- Input parameters
extern int periods = 20;
extern double percentSL = 1.5;
extern double percentTP1 = 2;
extern double percentTP2 = 3;
extern double percentTP3 = 4;
extern int corner = 4;

So you should have similar set in your Expert:

int periods = 20;
double percentSL = 1.5;
double percentTP1 = 2;
double percentTP2 = 3;
double percentTP3 = 4;
int corner = 4;

double ATR_SL=iCustom(NULL,0,"ATR in SL-TP_2",periods,percentSL,percentTP1,percentTP2,percentTP3,corner,0,1);
double ATR_TP=iCustom(NULL,0,"ATR in SL-TP_2",periods,percentSL,percentTP1,percentTP2,percentTP3,corner,1,1);
 
Seng Joo Thio:

No, I was referring to the default parameter values WITHIN the indicator - the file you attached. They are:

So you should have similar set in your Expert:

Agreed, which I changed in the initial indicator. (making a duplicate of course) and I still have the same issue.



EDIT: I see my fault. Retesting now.



EDIT2: The fault I saw was not a fault. The code posted is correct.

Files:
 
Underworldbros:

Agreed, which I changed in the initial indicator. (making a duplicate of course) and I still have the same issue.

I don't know how you test. But when I started running at 0958, and waited until the next bar, I see different return values from the indicator:


My test code:

void OnTick()
  {
//---
static datetime LTF = 0;
if (LTF==0 || LTF<iTime(NULL,0,0))
{
   double ATR[4];
   string PrintStr = "";
   
   int bar = 1;
   for (int i=0; i<4; i++)
   {
      ResetLastError();
      ATR[i]=iCustom(NULL,0,"ATR_in_SL-TP",20,1.5,2,3,4,4,i,bar);
      int Err = GetLastError();
      if (Err>0)
         Print("Err at i = ", i, ", Code = ", Err);
      PrintStr = PrintStr + "ATR["+IntegerToString(i)+"] = " + DoubleToStr(ATR[i],2) +"  ";
   }
   Print("bar = ", IntegerToString(bar), " ", PrintStr);   
   PrintStr = "";

   LTF = iTime(NULL,0,0);
}
  }

So the values DO get updated. As to how big the change should be, it really depends on how you tweak your parameters.

 
Seng Joo Thio:

I don't know how you test. But when I started running at 0958, and waited until the next bar, I see different return values from the indicator:


My test code:

So the values DO get updated. As to how big the change should be, it really depends on how you tweak your parameters.

I just have print. Can you explain your code so I can learn what you did and why? You may have posted the answer I need but I don't understand how it works.

   Print("SL=",ATR_SL);
   Print("TP=",ATR_TP);
 
Underworldbros:

I just have print. Can you explain your code so I can learn what you did and why? You may have posted the answer I need but I don't understand how it works.

ok. So the green lines are added to make sure i retrieve the values from the indicator at the start of a new bar, rather than triggering it every tick (and wasting cpu time), when I'm only interested in bar 1. Blue and red lines are there for debugging purposes - blue to print the values retrieved from the indicator for checking, and red just in case the icustom call fails and i'll know why it fails. And lastly, yellow line to iterate through all 4 buffers that the indicator uses, just to satisfy my curiosity and prove that the indicator's return values do change.

void OnTick()
  {
//---
static datetime LTF = 0;
if (LTF==0 || LTF<iTime(NULL,0,0))
{
   double ATR[4];
   string PrintStr = "";
   
   int bar = 1;
   for (int i=0; i<4; i++)
   {
      ResetLastError();
      ATR[i]=iCustom(NULL,0,"ATR_in_SL-TP",20,1.5,2,3,4,4,i,bar);
      int Err = GetLastError();
      if (Err>0)
         Print("Err at i = ", i, ", Code = ", Err);
      PrintStr = PrintStr + "ATR["+IntegerToString(i)+"] = " + DoubleToStr(ATR[i],2) +"  ";
   }
   Print("bar = ", IntegerToString(bar), " ", PrintStr);   
   PrintStr = "";

   LTF = iTime(NULL,0,0);
}
  }

Hope my explanations are useful.

 
Seng Joo Thio:

ok. So the green lines are added to make sure i retrieve the values from the indicator at the start of a new bar, rather than triggering it every tick (and wasting cpu time), when I'm only interested in bar 1. Blue and red lines are there for debugging purposes - blue to print the values retrieved from the indicator for checking, and red just in case the icustom call fails and i'll know why it fails. And lastly, yellow line to iterate through all 4 buffers that the indicator uses, just to satisfy my curiosity and prove that the indicator's return values do change.

Hope my explanations are useful.

They do indeed. The green is actually all I needed to make it work but it all help in the sake of learning.


Now that is settled, could you help me on the other problem I have on my other post? 

After some deep searching, it seems to be a common problem with no real solution given.

 
Underworldbros:

Now that is settled, could you help me on the other problem I have on my other post? 

After some deep searching, it seems to be a common problem with no real solution given.

Do you mean https://www.mql5.com/en/forum/312141?

I did not follow up there because I didn't understand your requirements/comments... LOL

It's ok, I'll clarify over there...

Unexplained incorrect data and non-advancing numbers
Unexplained incorrect data and non-advancing numbers
  • 2019.04.28
  • www.mql5.com
I've racked my brain around this stuff. Looked at the book, watched videos and dove into forums with no luck. the code is in mql4...
Reason: