search an algorithm for a new indic

 

Hi,

I would like to code an indicateur wich mark +1 each time that a price is crossed.

example : if price hit 3 times 9600, indicator will mark "9600  +3".

My first idea was :

double ask    = Marketinfo(Symbol(),MODE_ASK);

double bid    = Marketinfo(Symbol(),MODE_BID);

double price  = (ask+bid)/2;

double target = 9600;

if (price == target)

  {

      short result = 0;

              result = result + 1;

      Print ("target has been hit :",result,"times");

  }


But If I want to make that for each price what is better way (algorithm)

 

This:

      short result = 0;
      result = result + 1;

will set result always to 1.

You would need (as far as I can see this from this little code snippet):

static short result;
if (price == target)

  {
     result = result + 1;
     ..
  }

Little hint: read in the editor's reference about static variables or global variables.

 

it will be rare that

if (price == target)

will be true. It may never be true.

If you want to find out how many times it crossed get price and check whether it is above or below target, store the result

Next tick check to see if it is on the opposite side of target 

 
abricot91:
if (price == target)
Won't work.
Reason: