Hi, Here I have the code that I want to check when ma8 cuts ma21 from bellow I want to place the buy order and when ma8 cuts ma21 from the top I want to place the sell order, How can do these two in if statements that I leave them empty in the code?
- How do I set "TakeProfit" at death cross?? HELP!!!
- [ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3.
- How to know if a cross is fresh or not?
محمد دهقانی: t I want to check when ma8 cuts ma21 from bellow
double ma8 = ma(ma8_handle, 0); double ma21 = ma(ma21_handle, 0);
Look for a cross.
double aPrev = …(i+1), aCurr = …(i), bPrev = …(i+1), bCurr = …(i); bool wasUp = aPrev > bPrev, isUp = aCurr > bCurr, isCross = isUp != wasUp;
Compare the previous prices
Just do it
bool crossover(int index) { return ma(ma8_handle, index)>ma(ma21_handle, index) && ma(ma8_handle, index+1)<ma(ma21_handle, index+1); } bool crossunder(int index) { return ma(ma8_handle, index)<ma(ma21_handle, index) && ma(ma8_handle, index+1)>ma(ma21_handle, index+1); }

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