MA cross H1 Level Indicator

To add comments, please log in or register
Tradert618
23
Tradert618  

Hi All,

I'm wondering if someone could help me with this?

I'm am a VERY BASIC CODER. :):)

I have written some code that will give the 21 H1 EMA Level when the 7 H1 EMA crosses it.

It looks fine on the Hourly chart, but when I go down to a 5 min chart it shows the same indicator scale from the H1.

It would be greatly appreciated if someone could help me out as I am very lost on how to get it working.

Thank you. :)

Below is the code... Very simple...but so am I. :):)

//+------------------------------------------------------------------+
//|                                                       vvv.mq4 |
//|                                                               Me |
//|                                                          Missing |
//+------------------------------------------------------------------+
#property copyright "Me"
#property link      "Missing"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LightBlue
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   IndicatorShortName("MA Trend Level");
   SetIndexLabel(0,"Level");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   
//----
   return(0);
  }

  
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int limit = Bars-counted_bars-1;
 
   for (int i=limit; i >= 0; i--) 
   {

      
      // Binary Signal:
      static double BinSig;
      {
      if(iMA(NULL,PERIOD_H1,7,0,MODE_EMA,PRICE_CLOSE,i+1)>iMA(NULL,PERIOD_H1,21,0,MODE_EMA,PRICE_CLOSE,i+1) && iMA(NULL,PERIOD_H1,7,0,MODE_EMA,PRICE_CLOSE,i+2)<iMA(NULL,PERIOD_H1,21,0,MODE_EMA,PRICE_CLOSE,i+2))
      BinSig =iMA(NULL,PERIOD_H1,21,0,MODE_EMA,PRICE_CLOSE,i+1);
      else 
      BinSig=BinSig;
      }
      ExtMapBuffer1[i] = BinSig;
      }
  
//----
   return(0);
  }
//+------------------------------------------------------------------+

paul selvan
588
paul selvan  

don't specify PERIOD_H1

if(iMA(_Symbol,_Period,7,0,MODE_EMA,PRICE_CLOSE,i+1)>iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE,i+1) && iMA(_Symbol,_Period,7,0,MODE_EMA,PRICE_CLOSE,i+2)<iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE,i+2))
      BinSig =iMA(_Symbol,_Period,21,0,MODE_EMA,PRICE_CLOSE,i+1);
      
      
William Roeder
18310
William Roeder  
if(iMA(NULL,PERIOD_H1,7,0,MODE_EMA,PRICE_CLOSE,i+1)
You are mixing apples and oranges.
Tradert618
23
Tradert618  
paul selvan:

don't specify PERIOD_H1

Hi Paul,


Thank you for your response. :)

What I find is that If I don't specify a period it will give me the level of a 5 min MA cross on a 5 min chart, but I was wondering if there is a way to show the 1 hour cross level as a line for the 12 (12 individual 5 min bars per 1 hour bar) 5 min in that particular hour.


Thank you for all your help with this... I am a super beginner, but picking it up slowly. :)

Have a great day. :)

Cheers.

Tradert618
23
Tradert618  
whroeder1:
You are mixing apples and oranges.

Hi Whroeder1,

Should I just use a "1" instead of "I+1"?

Thanks again, and sorry it's taking me a while to grasp... :)

As I mentioned to Paul..."I was wondering if there is a way to show the 1 hour cross level as a line for the 12 (12 individual 5 min bars per 1 hour bar) 5 min in that particular hour."

Unfortunately I can't even think of a way that my simple coding skills could get that to work. :)

Thanks again and I'll try a couple of things.

In my head it works. :):)

You'll see in the pictures below what happens.

The 1st Chart looks fine with the 1 Hour level perfectly drawn.

The 2nd Chart however, keeps exactly the same lines for the cross level on the 1 Hour, but just overlays it on the 5 minute.

I know it's probably something really simple... That's why I ask you guys with the brains. :):):)

GBPUSD 1 Hour

GBPUSD 5 Min

Thanks again.

Cheers. 

paul selvan
588
paul selvan  

if you are asking EMA timeframe independant of the current timeframe,

e.g. 5mn EMA plotted on current chart ..

then parametrize EMA as :

ENUM_TIMEFRAMES ema_TF=PERIOD_M5;
   for (int i=limit; i >= 0; i--) 
   {  
      // Binary Signal:
      static double BinSig;
      
      if(iMA(NULL,ema_TF,7,0,MODE_EMA,PRICE_CLOSE,i+1)>iMA(NULL,ema_TF,21,0,MODE_EMA,PRICE_CLOSE,i+1) 
      && iMA(NULL,ema_TF,7,0,MODE_EMA,PRICE_CLOSE,i+2)<iMA(NULL,ema_TF,21,0,MODE_EMA,PRICE_CLOSE,i+2))
      BinSig =iMA(NULL,ema_TF,21,0,MODE_EMA,PRICE_CLOSE,i+1);
 
      ExtMapBuffer1[i] = BinSig;
   }
Tradert618
23
Tradert618  
paul selvan:

if you are asking EMA timeframe independant of the current timeframe,

e.g. 5mn EMA plotted on current chart ..

then parametrize EMA as :

Hi Paul,

Thank you very much. :):)

That makes total sense now.

I am a mere Jedi apprentice compared to all you Yoda's. :):)


Thanks again.

Cheers.

Tradert618
23
Tradert618  
paul selvan:

if you are asking EMA timeframe independant of the current timeframe,

e.g. 5mn EMA plotted on current chart ..

then parametrize EMA as :

Hi Paul,

Sorry about this... It still gives me the same problem. 

It still shows the same sort of look as the 2 pictures in the reply to Whroeder.

It just doesn't seems to scale itself for a lower time frame.

I'll try a couple of things tonight, but I really appreciate the help though. :)

Chat soon.

Cheers,

William Roeder
18310
William Roeder  
Tradert618: Should I just use a "1" instead of "I+1"?

No! Do not use 1, do not use I, do not use I+1. Go read and understand the links provided. Stop mixing apples and oranges.

To add comments, please log in or register