search an algorithm for a new indic

Back to topics list To post a new topic, please log in or register
avatar
11
abricot91 2015.03.02 22: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)

avatar
2017
gooly 2015.03.02 22: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.


avatar
Moderator
3408
GumRai 2015.03.03 03: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 

avatar
12988
WHRoeder 2015.03.03 13:49 #
 
abricot91:
if (price == target)
Won't work.

Back to topics list  

To add comments, please log in or register