MQL4 - automated forex trading   /  

Forum

Fixing Exit Signals that occur too soon?

Back to topics list To post a new topic, please log in or register

avatar
14
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?
article

MetaEditor:Templates as a Spot to Stand On

It may be news to many our readers that all preparations for writing an EA can be performed once and then used continuously.


avatar
14
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 line
Here'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.

avatar
235
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.


avatar
14
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.

Back to topics list  

To add comments, please log in or register