Download MetaTrader 5
To add comments, please log in or register
Improve your rating. Execute orders in Freelance service!
musetti
51
musetti 2015.03.02 21:32 

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
5953
Carl Schreiber 2015.03.02 21:41  

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
7947
Keith Watford 2015.03.03 02:39  

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
13627
whroeder1 2015.03.03 12:49  
abricot91:
if (price == target)
Won't work.
/
To add comments, please log in or register