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); }
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);
}