Please use this to post code . . . it makes it easier to read.
hey, i am trying to check for intersection between ma 20 and ma 50,
the function i wrote seem to work, but its seems to be non consistentic.
sometimes (depends of current value) the intersection accures when the substraction of the two MA's is ~0.2 and sometimes its ~1.4.
how can i determine for sure when the intersection accured?
bar 0 is the current bar....
i'm calculating the current values of the MA's substracting between them,
i want to get a consistentic substraction value, for example, if the substraction is below 0.2 the ma's have intersected or just going to....
bool checkMAInterSection(int firstMA, int secondMA) { double currPosFirstMA = iMA(NULL , 0 , firstMA , 0 , MODE_EMA , PRICE_MEDIAN , 0); double currPosSecondMA = iMA(NULL , 0 , secondMA , 0 , MODE_EMA , PRICE_MEDIAN , 0); double subVal = MathAbs(currPosFirstMA - currPosSecondMA); bool returnVal; if ( (subVal*100 >= 0) && (subVal*100 <= INTERSECTION_MIN_VALUE )/* && (nextInterSectionIndicator == true)*/) { returnVal = true; } else { returnVal = false; } if (returnVal==false) { Alert("MA\'s didnt intersected"); } else { Alert("MA\'s Intersected!!"); } return (returnVal); }
bar 0 is the current bar....
Yes, and it's current value, Close[0] = Bid, is changing every tick . . . so your MAs are changing every tick.
Just because the difference between the MAs is < x doesn't mean that they have crossed or about to cross, they may converge and then diverge. They may cross and uncross many times during bar 0
ok, if i will change it to iMA(NULL, 0, firstMA, 0, MODE_EMA, PRICE_MEDIAN, 1);
its going to be consistentic?
bool checkMAInterSection(int firstMA, int secondMA) { double currFirstMA = iMA(NULL , 0 , firstMA , 0 , MODE_EMA , PRICE_MEDIAN , 1), prevFirstMA = iMA(NULL , 0 , firstMA , 0 , MODE_EMA , PRICE_MEDIAN , 2), currSecondMA = iMA(NULL , 0 , secondMA , 0 , MODE_EMA , PRICE_MEDIAN , 1), prevSecondMA = iMA(NULL , 0 , secondMA , 0 , MODE_EMA , PRICE_MEDIAN , 2); bool currFirstAboveSecond = currFirstMA > currSecondMA, prevFirstAboveSecond = prevFirstMA > prevSecondMA, crossed = currFirstAboveSecond != prevFirstAboveSecond; return(crossed); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hey, i am trying to check for intersection between ma 20 and ma 50,
the function i wrote seem to work, but its seems to be non consistentic.
sometimes (depends of current value) the intersection accures when the substraction of the two MA's is ~0.2 and sometimes its ~1.4.
how can i determine for sure when the intersection accured?
bool checkMAInterSection(int firstMA, int secondMA) // 20,50double currPosSecondMA = iMA(NULL, 0, secondMA, 0, MODE_EMA, PRICE_MEDIAN, 0);