How to count

Posted By: Tuguldur717

How to count - 02/17/18 10:15

how to count how many price candles cross over line of moving average of price in a given time interval?
Posted By: Tuguldur717

Re: How to count - 02/17/18 13:55

Is there anybody to help me?
Posted By: Brax

Re: How to count - 02/17/18 19:15

In a very simplified way:

Code:
static var crossed = 0;

function run()
{
  BarPeriod = 24*60;
  asset("EURUSD");
  vars price = series(priceClose());
  vars ema = series(EMA(price,10));

  if(crossOver(price, ema) || crossUnder(price,ema))
    crossed = 0;
  else
    crossed++;
}



Hope it helps.
Posted By: Tuguldur717

Re: How to count - 02/19/18 02:45

Thank you bro. I will test it.
Posted By: Brax

Re: How to count - 02/20/18 11:44

Hello.

Reviewing your question i've noticed you probably really wanted to do this:

Code:
function run()
{
    StartDate = 20150601;
    EndDate = 20151201;
    BarPeriod = 24*60;
    asset("EUR/USD");
    
    vars price = series(priceClose());
    vars ema = series(EMA(price,10));
    vars crosses = series(0);
    
    int i;
    var period = 5;
    var crossed = 0;

	for(i=0; i<period; i++)
		if(crossOver(price+i, ema+i) || crossUnder(price+i,ema+i))
                     crosses[0] = ++crossed

    PlotWidth = 1024;
    PlotHeight1 = 400;
    plot("EMA",ema,MAIN,PURPLE);
    plot("Crossed",crossed,NEW,RED);
    plot("Crosses",crosses,NEW,BLUE);
}



This is a rolling counting of crosses with a moving average. The "crosses" series is not necessary, but in case you want to further evaluate the results, this way you'll have a mechanism to do it, instead of just incrementing a variable.

Take a look to the series instruction, you'll learn a lot:
http://www.zorro-trader.com/manual/en/series.htm

If this is not what you wanted, then i hope it helps you with further developments.

Bye.
Posted By: Tuguldur717

Re: How to count - 02/20/18 12:08

Thank very much you are the one who response in 220 people. You made truthful response. I am proud of you bro. Just now i am testing your code...
© 2024 lite-C Forums