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

 

I'm building an EA for a strategy that uses information of an indicator from the close of the previous bar.

Not the close price but the information that the indicator gave at the close.

I tried looking at iBarShift but that gives the bar's info.

Bars and iBars is no help either.


In the attached picture:

As bar 0 opens, I need the ATR info from bar 1.


I've looked and looked but haven't really found anything.

Files:
Capture.JPG  56 kb
 
Underworldbros:

I'm building an EA for a strategy that uses information of an indicator from the close of the previous bar.

Not the close price but the information that the indicator gave at the close.

I tried looking at iBarShift but that gives the bar's info.

Bars and iBars is no help either.


In the attached picture:

As bar 0 opens, I need the ATR info from bar 1.


I've looked and looked but haven't really found anything.

Have you tried something like this?

   int atr = iATR(NULL,0,14);
   if (atr<=0)
      Print (GetLastError());
   else
   {
      double Values[];
      ArraySetAsSeries(Values,true);
      if (CopyBuffer(atr,0,0,2,Values)>0)
      {
         // Values[1] is the computed value for bar 1
         Print (Values[1]);
      }
      else
         Print (GetLastError());
   }
 

Is't CopyBuffer an Mql5 thing?

Did i forget to mention i was working in Mql4?

My apologies.

 
Underworldbros:

Is't CopyBuffer an Mql5 thing?

Did i forget to mention i was working in Mql4?

My apologies.

That's even more straightforward:

   double atr1 = iATR(NULL,0,14,Bar); // Bar = 0 means the the current candle, 1 means the candle before, and so on.
 
I did try that. It gave me the previous bar at time of initialization but it never advanced when a new bar opened.
 
Underworldbros:
I did try that. It gave me the previous bar at time of initialization but it never advanced when a new bar opened.

Ok. Given that the iATR call is straightforward, I suspect the problem lies in the rest of your program's code... 

 

I'm using a custom indicator based off the ATR. The code to get information of the current bar should be straight forward. Just use iCustom(n,n,n...) with the shift at the end. It should be straight forward but for some reason the information just won't advance. There is no other code currently other than printing the information. The custom indie just does some multiplication and some percentage calculations. It does a bit more than that but the information I need is the calculations. The reason I just don't transfer the code (other than stealing) is I use it on my charts in a template. It displays information amongst other things but I just need to call the calculations which shouldn't conflict. I am testing this on backtesting (since the market is closed). That should simulate live market conditions. I'm not sure where the issue lies.

 

Just for clarity, here is the code along with the indie i'm trying to call.



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

Just for clarity, here is the code along with the indie i'm trying to call.

I did a test... initially, information does seem to remain the same, until i decided to change the input parameters from 14,1.5,1,0,0,1 to the indicator's original 20.1.5,2,3,4,4.

So I think you just need to supply the right parameters when you call iCustom, and the figure changes will become more apparent.

 
Seng Joo Thio:

I did a test... initially, information does seem to remain the same, until i decided to change the input parameters from 14,1.5,1,0,0,1 to the indicator's original 20.1.5,2,3,4,4.

So I think you just need to supply the right parameters when you call iCustom, and the figure changes will become more apparent.

But why would that make a difference? Calling it in an iCustom is no different than putting in the parameters from the input. It doesn't make sense to me.

 
Underworldbros:

But why would that make a difference? Calling it in an iCustom is no different than putting in the parameters from the input. It doesn't make sense to me.

?

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

Reason: