How to get Moving Average Cross price

To add comments, please log in or register
Jackery
218
Jackery  

I am writing an EA that uses crossing moving averages. I tell the crossing of moving averages in the following way:


// if shift5MA > shift0MA 
   if (shift5MAArray[1] > shift0MAArray[1]) {
      
      //if shift5MA < shift0MA VALID SELL
      if (shift5MAArray[2] < shift0MAArray[2]) {
         signal = "sell";
      }
      }
   
   if (shift5MAArray[1] < shift0MAArray[1]) {
      
      //if shift5MA > shift0MA
      if (shift5MAArray[2] > shift0MAArray[2]) {
         signal = "buy";
      }
      }

How can I tell the exact price at the point that moving averages cross, preferably after a candle closes?

Jackery
218
Jackery  
Can someone please help me with this?
Faeze Bakhshayesh
3956
Faeze Bakhshayesh  
Jackery:

I am writing an EA that uses crossing moving averages. I tell the crossing of moving averages in the following way:


How can I tell the exact price at the point that moving averages cross, preferably after a candle closes?

double   MA30  =  iMA(NULL,TMF,MAPeriod1,0,MODE_LWMA,PRICE_MEDIAN,0);
double   MA15  =  iMA(NULL,TMF,MAPeriod4,0,MODE_LWMA,PRICE_MEDIAN,0);
      
if (OrdersTotal()==0)
 {
  if ( (MA15 > MA30 && OldSignal !="BUY") )
   {
    // buy here
    OldSignal = "BUY";
   }
  if ( (MA15 < MA30 && OldSignal !="SELL") )
   {
     // sell here
     OldSignal = "SELL";
   }
 }

and define "OldSignal" variable on top off your code, global variable

William Roeder
23248
William Roeder  
  1. Faeze Bakhshayesh:

    That is not checking for a cross.

  2. Jackery: How can I tell the exact price at the point that moving averages cross, preferably after a candle closes?

    Search new bar. Stop checking each tick.

  3. Exact price where they crossed? You can easily estimate that with algebra: f(t) = f[2] + (f[1]-f[2]) × t, s(t) = s[2] + (s[1]-s[2]) × t. At cross, they are equal and so is t.

  4. Or the price when they crossed? Either use 1 and 0 and note the Bid on first cross. Or much harder binary search on price.

  5. Why do you care? The market has moved away from either (№ 3 or 4) at candle close.
Faeze Bakhshayesh
3956
Faeze Bakhshayesh  
William Roeder:
  1. That is not checking for a cross.

  2. Search new bar. Stop checking each tick.

  3. Exact price where they crossed? You can easily estimate that with algebra: f(t) = f[2] + (f[1]-f[2]) × t, s(t) = s[2] + (s[1]-s[2]) × t. At cross, they are equal and so is t.

  4. Or the price when they crossed? Either use 1 and 0 and note the Bid on first cross. Or much harder binary search on price.

  5. Why do you care? The market has moved away from either (№ 3 or 4) at candle close.

You can find crossing 2 ma with hundred of ways :)

To add comments, please log in or register