I think, It would be better like this (to check):
int CheckForCross(){
// check if moving averages have crossed
static int siLastDirection = 0;
static int siCurrentDirection = 0;
double Mahundred;
// get the current prices for each moving average and standard deviation
Mahundred = iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,0);
// check if lines have crossed and standard deviation > 69
if (Close+Mahundred> Mahundred)
//upAlert("Signal alert");
{
siCurrentDirection = 1;
Alert("Signal alert");
}
if (Close+Mahundred*Point < Mahundred)
//down
{
siCurrentDirection = 2;
Alert("Signal alert");
}
if(siCurrentDirection != siLastDirection){
// they have so return the new signal
siLastDirection = siCurrentDirection;
return (siLastDirection);
}
// no cross
return(0);
}
wapzzoo it still didnt work. Its not even running now, im getting 4 errors. The real problem is that u r trying to fix my code but as i said i dont really know any thing about programming. I just did some reading and came up with that but i dont think its any good. So i dont think u should try to fix it at all. it may need to be rewritten completely, what i have seems unnecessarily complicated for what im trying to achieve.
koolguyme i take ur advice but getting the sound isnt really the problem, i got a sound. the problem is that i get the sound whenever the candle closes and not when there is any cross of the MA line by the price which is what i really want.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Im am trying to write an alert to make a noise when price crosses SMA 100 from below and closes above it and similarly when price crosses SMA 100 from above and closes below it. I am not a programmer but i did some reading and came up with this (see below) but is doesnt work. can any one help me with this i would really appreciate it.
int start()
{
//----
int iCrossed;
// see if we have a new cross
iCrossed = CheckForCross();
//----
return(0);
}
//+------------------------------------------------------------------+
int CheckForCross(){
// check if moving averages have crossed
static int siLastDirection = 0;
static int siCurrentDirection = 0;
double Mahundred;
// get the current prices for each moving average and standard deviation
Mahundred = iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,0);
// check if lines have crossed and standard deviation > 69
if (Close+Mahundred*Point > Mahundred) siCurrentDirection = 1; //upAlert("Signal alert");
{
Alert("Signal alert");
}
if (Close+Mahundred*Point < Mahundred) siCurrentDirection = 2; //down
{
Alert("Signal alert");
}
if(siCurrentDirection != siLastDirection){
// they have so return the new signal
siLastDirection = siCurrentDirection;
return (siLastDirection);
}
// no cross
return(0);
}