Download MetaTrader 5
To add comments, please log in or register
Are you used to trading from your smartphone? Mobile version of MetaTrader 5 will suit you best!
ankityadav
208
ankityadav 2014.03.30 11:04 
//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "anky.legend712"


//--- indicator settings
#property  indicator_chart_window
#import "user32.dll"
#import
#import "Kernel32.dll"
#property  indicator_buffers 4
#property  indicator_color1  Yellow
#property  indicator_color2  Red
#property  indicator_color1  Yellow
#property  indicator_color2  Red
//--- indicator parameters
extern int InpFastSMA=10;   
extern int InpSlowSMA=16; 
extern double FastInpdev=2;
extern double SlowInpdev=4;
extern double Xbars=50;
extern double DistancePips=300;
//extern double leveldistance=
extern color color1=Yellow;
extern color color2=Red;
extern color color3=Yellow;
extern color color4=Red;
//--- indicator buffers
double    ExtBuffer1[];
double    ExtBuffer2[];
double winIndex;
int pipsmultiplier=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- drawing settings
    SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1,color3);
    SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,1,color4);
   
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer1);
   SetIndexBuffer(1,ExtBuffer2);
   winIndex = WindowFind("MarioIndicator");
  if( winIndex == -1 )
    winIndex = 1;
    return ;
 }
 int start()
 {
  int    limit;
  int i=0;
  string s1=Symbol();
  if(Bars<InpSlowSMA) return(0); 
  int   counted_bars=IndicatorCounted();
  if(counted_bars<0) return(-1);
   int lookback = MathMax(InpFastSMA, InpSlowSMA)+1;
  if(counted_bars < lookback) counted_bars = lookback;
  //if(counted_bars>0) counted_bars--;
  limit=Bars-counted_bars-1;
  while(limit>=0)
   {  
    double fastPre=iBands(NULL,0,InpFastSMA,FastInpdev,0,PRICE_CLOSE,MODE_SMA,limit+1);
    double slowPre =iBands(NULL,0,InpSlowSMA,SlowInpdev,0,PRICE_CLOSE,MODE_SMA,limit+1);
    double fastsma=iBands(NULL,0,InpFastSMA,FastInpdev,0,PRICE_CLOSE,MODE_SMA,limit);
    double slowsma =iBands(NULL,0,InpSlowSMA,SlowInpdev,0,PRICE_CLOSE,MODE_SMA,limit);
    bool wasAbove = fastPre > slowPre;
    bool isAbove = fastsma > slowsma;
    bool isCross = wasAbove != isAbove;
    double mPoint=MarketInfo(s1,MODE_POINT)*pips(s1);
    Print("MArket valueup",Bid+DistancePips*mPoint);
    if(limit<=Xbars)
    {
     if(isCross)
      { 
       if(fastsma>=slowsma && fastsma>=MarketInfo(Symbol(),MODE_BID)+(NormalizeDouble(DistancePips*mPoint,Digits)))                                                      
         {
           if(ObjectFind("fastsma")==-1)
           {
             ObjectCreate("fastsma"+Time[limit],OBJ_HLINE,0,0,fastsma);
             ObjectSet("fastsma"+Time[limit],OBJPROP_COLOR,color1);
             ObjectSet("fastsma"+Time[limit],OBJPROP_STYLE,STYLE_DASH);
             WindowRedraw();
           }
         } 
      }
       else if(fastsma<=slowsma && fastsma<=MarketInfo(Symbol(),MODE_BID)-(NormalizeDouble(DistancePips*mPoint,Digits)))
        {
           if(ObjectFind("slowsma")==-1){
           ObjectCreate("slowsma"+Time[limit],OBJ_HLINE,0,0,slowsma);
           ObjectSet("slowsma"+Time[limit],OBJPROP_COLOR,color2);
           ObjectSet("slowsma"+Time[limit],OBJPROP_STYLE,STYLE_DASH);
           WindowRedraw();
            }
      } 
    }  
    ExtBuffer1[limit]=fastsma;
    ExtBuffer2[limit]=slowsma; 
    limit--;
    i++;
  } 
   return; 
 }
 
 
  double pips(string sym1) {
        if (MarketInfo(sym1, MODE_DIGITS) == 3 || MarketInfo(sym1, MODE_DIGITS) == 5) {
            pipsmultiplier = 10;
        } else {
            pipsmultiplier = 1;
        }
        return (pipsmultiplier);
    }
void deinit()
{
  for(int i = ObjectsTotal() -1; i >=0; i--) {
  ObjectDelete(ObjectName(i));
  }

}
Hi the code is not running in m1,m5 and m15 cahrt on't know why can some body help to sort out this problem Thanks
qjol
3243
qjol 2014.03.30 11:23  
work fine for me
ankityadav
208
ankityadav 2014.03.30 11:25  
qjol:
work fine for me

Thanks for your reply Are you sure because if you see it doesn't show lines in m1 m5 and m15 charts yellow and red ??
qjol
3243
qjol 2014.03.30 11:55  

oops my mistake

i thought you were talking about the MA lines sorry

ankityadav
208
ankityadav 2014.03.30 12:02  
qjol:

oops my mistake

i thought you were talking about the MA lines sorry


Not an issue but can you help me why this is happening??
Keith Watford
Moderator
7887
Keith Watford 2014.03.30 12:11  
ankityadav:
Hi the code is not running in m1,m5 and m15 cahrt on't know why can some body help to sort out this problem Thanks

The default setting

extern double DistancePips=300;

and

if(fastsma>=slowsma && fastsma>=MarketInfo(Symbol(),MODE_BID)+(NormalizeDouble(DistancePips*mPoint,Digits))) 
if(fastsma<=slowsma && fastsma<=MarketInfo(Symbol(),MODE_BID)-(NormalizeDouble(DistancePips*mPoint,Digits)))

How often do you think that the the sma will be 300 pips above or below Bid in the lower timeframes?

ankityadav
208
ankityadav 2014.03.30 12:17  
GumRai:

The default setting

and

How often do you think that the the sma will be 300 pips above or below Bid in the lower timeframes?


But if you make it on 100pips and make for 1000bars at that point also it does'nt seems to be work i have checked it in all time frames
Daniel Petrovai
440
Daniel Petrovai 2014.04.05 07:54  
ankityadav:
Hi the code is not running in m1,m5 and m15 cahrt on't know why can some body help to sort out this problem Thanks


When you say not running, it means you don't see anything on the chart, do you get any errors at all?

Can you explain what you want this indicator to do ? And what is this MarioIndicator ?

If the yellow and red horizontal lines are what you're looking for, you need to explain your calculations because you can't see lines on M1 chart if they are 1000 pips away.

Give some more details if you can.

Cheers.

ankityadav
208
ankityadav 2014.04.07 21:24  
thrdel:


When you say not running, it means you don't see anything on the chart, do you get any errors at all?

Can you explain what you want this indicator to do ? And what is this MarioIndicator ?

If the yellow and red horizontal lines are what you're looking for, you need to explain your calculations because you can't see lines on M1 chart if they are 1000 pips away.

Give some more details if you can.

Cheers.


Hi thanks for your reply if you see the code above what i m going here is making an indicator which show lines yellow when fast bollinger crosses low to up the slow bollinger and vice versa .I have filtered by using certain bars criteria so that it only show the yellow and red about this criteria .Lets say i have inputted 50 bars then it will show only lines which satisfy this criteria between 50 bars.Now where i m getting problem is when i m using criteria number two is the maket price.I m filtering using market value price like current market value price+Input pip.So i mtrying to see the yellow lines and red lines .

When fast bollinger us also greater than current market value +pips value then it show only those lines which satisfy this criteria and vice viceversa.


Thanks

Daniel Petrovai
440
Daniel Petrovai 2014.04.08 10:03  
ankityadav:

Hi thanks for your reply if you see the code above what i m going here is making an indicator which show lines yellow when fast bollinger crosses low to up the slow bollinger and vice versa .I have filtered by using certain bars criteria so that it only show the yellow and red about this criteria .Lets say i have inputted 50 bars then it will show only lines which satisfy this criteria between 50 bars.Now where i m getting problem is when i m using criteria number two is the maket price.I m filtering using market value price like current market value price+Input pip.So i mtrying to see the yellow lines and red lines .

When fast bollinger us also greater than current market value +pips value then it show only those lines which satisfy this criteria and vice viceversa.


Thanks



I get you man. Let's start by fixing some errors, OK?

The obvious one is the way you try to get the values for upper and lower bands :

    double fastPre=iBands(NULL,0,InpFastSMA,FastInpdev,0,PRICE_CLOSE,MODE_SMA,limit+1);
    double slowPre =iBands(NULL,0,InpSlowSMA,SlowInpdev,0,PRICE_CLOSE,MODE_SMA,limit+1);
    double fastsma=iBands(NULL,0,InpFastSMA,FastInpdev,0,PRICE_CLOSE,MODE_SMA,limit);
    double slowsma =iBands(NULL,0,InpSlowSMA,SlowInpdev,0,PRICE_CLOSE,MODE_SMA,limit);

For Bollinger Bands you have a buffer that holds values for upper band and one buffer for lower band for each bar . You can't have MODE_SMA . I suggest you try to highlight iBands in your code and press F1.

Use it any time you're not sure or want to check your code.

Here is what you get :

iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0);

You can have PRICE_CLOSE, PRICE_LOW, etc, but not MODE_SMA.

Now, I'll let you figure out how to get the correct value for the upper band .... ; )

Also, it's easier for everyone if you use more meaningful names for your variables (ie : fastLowerBand or fastUpper, slowUpper etc) .

And again, what is and what purpose serves this :

   winIndex = WindowFind("MarioIndicator");
  if( winIndex == -1 )
    winIndex = 1;

Remember, I'm not very good at explaining things so if you have any questions just ask.

I'll be back with more.

Daniel Petrovai
440
Daniel Petrovai 2014.04.08 11:30  


Ready for a bit more fun ? Nothing to worry about, you did a good job, just some bits and pieces to fix.

1. You don't declare 4 buffers if you only need 2

#property  indicator_buffers 2

2. Don't leave #import like that and don't double either :

#import                              // delete this
#import "Kernel32.dll"
#property  indicator_buffers 4
#property  indicator_color1  Yellow
#property  indicator_color2  Red
#property  indicator_color1  Yellow // delete this
#property  indicator_color2  Red    // delete this

3. Which one you want to use ?

extern color color1=Yellow;
extern color color2=Red;
extern color color3=Yellow;
extern color color4=Red;
// or
#property  indicator_color1  Yellow
#property  indicator_color2  Red

4.Delete this

   winIndex = WindowFind("MarioIndicator");
  if( winIndex == -1 )
    winIndex = 1;

5. int OnInit() has to return an int value . If no value, then return(0);

We should discuss Start function last, after we fix all other stuff.

6. Please don't do this :

void deinit()
{
  for(int i = ObjectsTotal() -1; i >=0; i--) {
  ObjectDelete(ObjectName(i));
  }

}

It will delete everything, trend lines,fibs, any object on chart even when you switch time frames everything goes away. Use this instead, I'll show you how to create object name t work with it :

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void deinit()
  {
   for(int i=ObjectsTotal(); i>=0; i--)
     {
      string name1="slowsma"+i;
      string name2="fastsma"+i;
      string name =ObjectName(i);
      if(name==name1 || name==name2)
         ObjectDelete(0,name);
     }

  }
//+------------------------------------------------------------------+

7. Function pips is of double type and returns an int type (pipsmultiplier) !

double pips(string sym1)   

Change to int type .

Now, to create name for your lines, a simple way would be by adding a counter to the name instead of time .

int pips=0,objectCount=0; // objectCount is my counter of objects

objectCount gets added to the name of the object and then increased by one :

if(ObjectFind("fastsma"+objectCount)==-1)
                 {
                  ObjectCreate("fastsma"+objectCount,OBJ_HLINE,0,Time[0],fastsma,0);
                  ObjectSet("fastsma"+objectCount,OBJPROP_COLOR,color1);
                  ObjectSet("fastsma"+objectCount,OBJPROP_STYLE,STYLE_DASH);
                  objectCount++;
                  WindowRedraw();

or you can have :

string lineName="fastema"+objectCount;
if(ObjectFind(lineName)==-1)
                 {
                  ObjectCreate(lineName,OBJ_HLINE,0,Time[0],fastsma,0);
                  ObjectSet(lineName,OBJPROP_COLOR,color1);
                  ObjectSet(lineName,OBJPROP_STYLE,STYLE_DASH);
                  objectCount++;
                  WindowRedraw();
                 }
lineName="slowema"+objectCount;
if(ObjectFind(lineName)==-1)
                 {....

Same for "slowema".

You still end up with a bunch of lines. If you want 1 line only you should think about ObjectMove.

Are we good so far ?

/ /12
To add comments, please log in or register