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
- Faeze Bakhshayesh:
That is not checking for a cross.
- 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.
-
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.
-
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.
- Why do you care? The market has moved away from either (№ 3 or 4) at candle close.
-
That is not checking for a cross.
-
Search new bar. Stop checking each tick.
-
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.
-
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.
- 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 :)
-
That is not checking for a cross.
-
Search new bar. Stop checking each tick.
-
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.
-
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.
- Why do you care? The market has moved away from either (№ 3 or 4) at candle close.
Sorry, I've not been here for a while.
I am trying to figure out how to use the equation you've provided in my code. I don't really get the understand what s(t) and f(t) represent with respect to the code I provided.
From my observation and backtesting, based on some other additional conditions, price might return to fill in orders at this cross price before continuing in it's respective direction.
You can find crossing 2 ma with hundred of ways :)
I would really appreciate you showing me one of those hundred ways :)
I would really appreciate some help with getting this solved
and define "OldSignal" variable on top off your code, global variable
double MA301 = iMA(NULL,TMF,MAPeriod1,0,MODE_LWMA,PRICE_MEDIAN,0); double MA302 = iMA(NULL,TMF,MAPeriod1,0,MODE_LWMA,PRICE_MEDIAN,1); double MA151 = iMA(NULL,TMF,MAPeriod4,0,MODE_LWMA,PRICE_MEDIAN,0); double MA152 = iMA(NULL,TMF,MAPeriod4,0,MODE_LWMA,PRICE_MEDIAN,1); if (OrdersTotal()==0) { if ( (MA151 > MA301 && MA152 < MA302 && OldSignal !="BUY") ) { // buy here OldSignal = "BUY"; } if ( (MA151 < MA301 && MA152 > MA302 && OldSignal !="SELL") ) { // sell here OldSignal = "SELL"; } }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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?