I am developing an EA with a buy signal when the MACD histogram goes from negative to positive. Very often the histogram goes positive then negative in a matter of seconds when the buy signal has been triggered. Any ideas how to not trigger my exit signal so quickly?
- Sample Code of MACD Line Crosses MACD Signal Line
- Calculating the spread on a position, SP500
- Need a little help with EA
//BUY SIGNAL if(macd_histogram_value2 < 0 && macd_histogram_value1 > 0 && macd_blue_line_value1 > macd_red_line_value1) //EXIT BUY SIGNAL if(macd_histogram_value1 < 0) else if(macd_blue_line_value1 < macd_red_line_value1) //REFERENCE macd_histogram1 = current macd histogram macd_histogram2 = previous macd histogram macd_blue_line_value1 = current macd blue line macd_red_line_value1 = current macd red lineHere's a sample of my code. My current problem is the buy signal gets triggered then a few seconds after that, the exit buy signal gets triggered. Is there any way to delay the exit signal for at least 1 bar? Right now, my temporary fix is to disable the exit sell signal by default and enable it manually after 1 bar with an external variable. Kind of dumb cos it isn't automated.
//BUY SIGNAL if(macd_histogram_value2 < 0 && macd_histogram_value1 > 0 && macd_blue_line_value1 > macd_red_line_value1) { //..... your stuff_here... GlobalVariableSet("buy_signal_"+Symbol(), TimeCurrent()); } /EXIT BUY SIGNAL if( TimeCurrent()-GlobalVariableGet("buy_signal_"+Symbol())>15*60 ) // test histogram only 15 minutes after last signal { if(macd_histogram_value1 < 0) { // your stuff .... //... } else ... } // if using on eurusd, the flag created at tools->global variable is "buy_signal_eurusd" with the time value of the signal. // If you didn't include Symbol() in the name of the flag, you would be limited to a single currency.
Thanks. It works! I also added this GlobalVariableDel to delete the global variable once my exit signal is hit.
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