Help with For Cycle Operator

Hi BabyPips,

I have a completely noob question for you.

I’m trying to write a cycle operator that takes the sum of the following formula:

  ( Close[t] - Close[t+1] ) + Open[t]

… for a given number of cycles (say 40 times) that I specify.

What I have come up with so far is woefully incomplete. Here’s my partial attempt:

double Price_Long (int t);
{for (t=0;t<=40;t++)
( Close[t] - Close[t+1] ) * Open[t];
???; // WHAT DO I DO HERE TO MAKE IT ADD TO ITSELF!!! SO FRUSTRATING!!!
}

Help me, BabyPips. You’re my only hope.

<3,

DK

I think I may the thing that should work for you. The function I think you are trying to write should look like this:

double Price_Long(int t)
{
double tmp = 0.0;
for(int i = 0;
i <= t;
t++)
tmp += (Close[t] - Close[t+1])*Open[t];
return(tmp);
}

This seems like what you described. Plus I made that parameter work as your cycle parameter. I think that is what you will want long term. So you can use any number of cycles you want, but you may want to go back to a hard coded cycle (t<=40). That is an easy fix if you choose. I took this code and compiled it into one of my libraries, and it compiles just fine. So, I think this could help.

PS: If you get a chance please take a look at my EA. You can download it from fzfreemt4ea.com (sorry they won’t let me put links in my postings yet). Let me know what you think of it. There is a forum link for your convenience. You can ask me any questions about the EA. If you feel like passing this info on to any others that would really help me out.

Thank you,

fZ

I made a mistake this is what is should look like:

double Price_Long(int t)
{
double tmp = 0.0;
for(int i = 0;
i <= t;
i++)
tmp += (Close[i] - Close[i+1])*Open[i];
return(tmp);
}

I ran this function through one of my test EAs and the debug output wasn’t right. This should be right. That other function will compile and run, but this one will give the right output.

I was finally able to get this to work (I lost my internet connection for a few months). Thank you so much!

Your own EA looks quite impressive.