int Crossed(double LineTop, double LineBottom, double Trigger){ static int LastDir = 0; /**/ if (Trigger>=LineTop) int CurrDir=1; else if (Trigger<=LineBottom) CurrDir=2; else CurrDir=3; if (CurrDir!=LastDir){ //dir changed int prevDir = LastDir; // Save the last value to return. LastDir=CurrDir; // Now overwrite the last value. return(prevDir); // return(LastDir); } return(LastDir); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
//If I change c, why do Keep on getting a 0?
int Crossed(double LineTop,double LineBottom,double Trigger)
{
static int LastDir = 0;
static int CurrDir = 0;
if (Trigger>=LineTop)
{
CurrDir=1;
}
else
{
if (Trigger<=LineBottom)
{
CurrDir=2;
}
else
{
if (Trigger<LineTop || Trigger>LineBottom)
{
CurrDir=3;
}
}
}
if (CurrDir!=LastDir) //dir changed
{
LastDir=CurrDir;
return(LastDir);
}
/* else
{
return(0);
}*/
}
//-------------------------------------------------
int start()
{
double a = 30.0;
double b = 20.0;
double c = 35.0;
//Check trigger---------------------------------
int isCrossed = Crossed(a,b,c);
//----------------------------------------------
Print("Last direction =",isCrossed);
}