Open trade when middle bollinger band crossed by lwma (my attempt does not work )

 

I want to buy or sell when middle bollinger band crossed by lwma (my attempt does not work ).

Where did I do my mistake? 

   double BBBTop =iCustom(NULL, PERIOD_CURRENT,"Better Bollinger Bands",20,2.0,0,0,0);
   double BBBMid =iCustom(NULL, PERIOD_CURRENT,"Better Bollinger Bands",20,2.0,0,2,0);
   double BBBBot =iCustom(NULL, PERIOD_CURRENT,"Better Bollinger Bands",20,2.0,0,1,0);
  
   double MALine0 = iMA(NULL,0,3,0,MODE_LWMA,PRICE_CLOSE,0);
   double MALine1 = iMA(NULL,0,3,0,MODE_LWMA,PRICE_CLOSE,1);

//****
// WRITE HERE THE CONDITION FOR OPENING A PUT
//
//****


   if
   ( BBBMid == MALine0 && MALine1 > MALine0)
     {
      pIsDirectionUp=false;
      return true;
     }

//****
// WRITE HERE THE CONDITION FOR OPENING A CALL
//****
   if
   ( BBBMid == MALine0 && MALine1 < MALine0)
     {
      pIsDirectionUp=true;
      return true;
     }

   return false;
  }

regards,

salexes 

 

EDIT:


I might have found the problem, the MA got .00000 5 ditgits while the better bollinger bands only got 4 digits .0000  
What should I do now ?

 

EDIT2: Changed the better bollinger bands to 5 digits. Still it is not working, recommendations ? 

 
salexes:

I want to buy or sell when middle bollinger band crossed by lwma (my attempt does not work ).

Where did I do my mistake? 

2 suggestions:

1) You're using a custom indicator for the BB - are you sure you have the parameters in the right places? I suggest trying it with the built in BB first to get it working how you want
2) Use Period() rather than PERIOD_CURRENT (Current returns zero: https://docs.mql4.com/constants/chartconstants/enum_timeframes )
Chart Timeframes - Chart Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
Chart Timeframes - Chart Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Chart Timeframes - Chart Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
 
Stuart Browne:
2 suggestions:

1) You're using a custom indicator for the BB - are you sure you have the parameters in the right places? I suggest trying it with the built in BB first to get it working how you want
2) Use Period() rather than PERIOD_CURRENT (Current returns zero: https://docs.mql4.com/constants/chartconstants/enum_timeframes )
Hi Stuart, happy to see you here around :-)
 

Thank you for your answer! 

With the normal Bollinger Bands I seem not to have a value for the middle line.

I attached the better bollinger bands mq4 file.

Could someone give me an advice? It seems that this is never the case: BBBMid == MALine0

 
salexes: Could someone give me an advice? It seems that this is never the case: BBBMid == MALine0
double MALine0 = iMA(NULL,0,3,0,MODE_LWMA,PRICE_CLOSE,0);

( BBBMid == MALine0 && MALine1 < MALine0)
  1. Did you look at your indicator's code and understand what it is computing?
    tBuffer[r][iMt1] = tBuffer[r-1][iMt1] + alpha*(price           -tBuffer[r-1][iMt1]);
    tBuffer[r][iUt1] = tBuffer[r-1][iUt1] + alpha*(tBuffer[r][iMt1]-tBuffer[r-1][iUt1]);
       double dt  = ((2-alpha)*tBuffer[r][iMt1]-tBuffer[r][iUt1])/(1-alpha);
    MaBuffer[i]  = dt;
    Looks like some low lag exponential. Definitely not linear weighted. It will never be the case that they are close to equal.
  2. Doubles are almost never equal. Understand The == operand. - MQL4 forum
 


Look at this there the  MALine0 and the BBBMid have the same value. That is the moment when I want to buy/sell.

From what I read in the other thread:  "can't do is get the iband value between bars,  so if the cross happens between bars Bid will never == iband"

So how do I recognize the crossing then ? Not possible? If yes any tips, so I can try to figure it out myself after that (to learn and understand it)

(Sorry for all the questions I just started to learn MQL (first coding attempts right now)) 

 
salexes: Look at this there the  MALine0 and the BBBMid have the same value.
  1. No they don't. They are only the same to 5 digits.one is 1.05999000000001 and the other might be 1.05999000000002 and those are not equal.
  2. Why are you worrying about equality when your title is about "crossed?" Check for a cross:
    bool wasAbove = BBBMidPrev > MALine0Prev
    bool  isAbove = BBBMidCurr > MALine0Curr;
    bool cross = wasAbove != isAbove;

 
Got it working thanks!