Download MetaTrader 5
To add comments, please log in or register
Are you a real pro? Share your knowledge with millions of traders!
fly7680
307
fly7680 2016.05.28 12:57 
Hello everyone, I wrote this code but I have a doubt, the MACD 10 6 5 when the Crossing State and the MACD 2 6 3 exceeds the level  0 signal.

I would rather that the MACD 10 6 5 a cross-time need to wait for the MACD 2 6 3 then gives me the signal.

How could I do? Unfortunately I am a neophyte.

Thank you


//Indicator Buffer 1 BUY
      if(iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 6,  1+i) < iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 7, 1+i)
      && iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 6,  2+i) > iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 7, 2+i) //MACD_Lnx_v1 crosses below MACD_Lnx_v1
      && iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1",  2, 6, 3, 0, 1, 0, 7,  1+i) > 0 
      && iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1",  2, 6, 3, 0, 1, 0, 7,  2+i) < 0 
      )
        {
         Buffer1[i] = Low[i] - 1 * myPoint; //Set indicator value at Candlestick Low - fixed value
        }
      else
        {
         Buffer1[i] = 0;
        }
fly7680
307
fly7680 2016.05.28 14:35  

Is possible? 

Carl Schreiber
5937
Carl Schreiber 2016.05.28 15:10  

You can check this yourself?

Use either Print or Comment() or the debugger or the strategy tester in visualmode.

whroeder1
13599
whroeder1 2016.05.29 14:55  
if(iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 6,  1+i) < iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 7, 1+i)
&& iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 6,  2+i) > iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", 10, 6, 5, 0, 1, 0, 7, 2+i) //MACD_Lnx_v1 crosses below MACD_Lnx_v1
&& iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1",  2, 6, 3, 0, 1, 0, 7,  1+i) > 0
&& iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1",  2, 6, 3, 0, 1, 0, 7,  2+i) < 0
  1. Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code.
  2. Detailed explanation of iCustom - MQL4 forum  Make your code readable and drop useless comment
    #define BUF6 6 // A description name for buffer # 6
    #define BUF7 7 // A description name for buffer # 7
    double Lnx(int L, int M, int S, int B, int i){ return iCustom(NULL, PERIOD_CURRENT, "MACD_Lnx_v1", L, M, S, 0, 1, 0, B, i); }
    double LnxSlow(int B,int i){                   return Lnx(10, 6, 7, B, i); }
    double LnxFast(int B,int i){                   return Lnx( 2, 6, 3, B, i); }
    :
    double slow6cur = LnxSlow(BUF6, i+1); // use descriptive variable names.
    double slow7cur = LnxSlow(BUF7, i+1);
    double slow6pre = LnxSlow(BUF6, i+2); 
    double slow7pre = LnxSlow(BUF7, i+2);
    double fast7cur = LnxFast(BUF7, i+1);
    double fast7pre = LnxFast(BUF7, i+2);
    if(slow6cur < slow7cur && slow6pre > slow7pre //MACD_Lnx_v1 crosses below MACD_Lnx_v1
    && fast7cur > 0 && fast7pre < 0
  3. Your if says the two different periods must cross on the same bar. Unlikely. More likely you want both to agree.
    bool  isSlowRising = slow6cur < slow7cur;
    bool  isFastRising = fast7cur > 0;
    bool  isSignal     = isSlowRising && isFastRising;
    
    bool wasSlowRising = slow6pre < slow7pre;
    bool wasFastRising = fast7pre > 0;
    bool wasSignal     = wasSlowRising && wasFastRising;
    
    bool signal        = isSignal && !wasSignal;
/
To add comments, please log in or register