| / | Forum |
|
mql4newbie
2008.12.02 19:14
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?
|
|
Secrets of MetaTrader 4 Client Terminal 21 way to ease the life: Latent features in MetaTrader 4 Client Terminal. Full screen; hot keys; Fast Navigation bar; minimizing windows; favorites; traffic reduction; disabling of news; symbol sets; Market Watch; templates for testing and independent charts; profiles; crosshair; electronic ruler; barwise chart paging; account history in the chart; types of pending orders; modifying of StopLoss and TakeProfit; undo deletion; chart print. |
|
mql4newbie
2008.12.02 19:29
//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. |
|
abstract_mind
2008.12.02 20:47
//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. |
|
mql4newbie
2008.12.04 05:17
Thanks. It works! I also added this GlobalVariableDel to delete the global variable once my exit signal is hit.
|