Download MetaTrader 5

search an algorithm for a new indic

To add comments, please log in or register
musetti
51
musetti  

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)

Carl Schreiber
6688
Carl Schreiber  

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.

Keith Watford
Moderator
9641
Keith Watford  

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 

whroeder1
14774
whroeder1  
abricot91:
if (price == target)
Won't work.
To add comments, please log in or register