#MTF Moving Average doesn't add up.

 

here you can see what I mean, this indicator should show the same price, because it is reading from a different timeframe, but it seems to have different prices.

Indicator Link: http://www.35pip.com/metatrader-indicators/mtf-movingaverage-mq4/

Wanna see my code?

/**********************
    5026 MTF MA
***********************/
#property copyright "Copyright © 2012, Brian Lillard"
#property link      "brianlillard77@gmail.com"
#include <stderror.mqh>
/**********************
    INPUT PARAMETERS
***********************/
extern string    _INDICATORS="===================================";
extern int        TimeFrame            =1440; //0;  //1440
extern int        MAPeriod             =1; //20; //1
extern int        ma_shift             =0;
extern int        ma_method            =1;
extern int        applied_price        =0;
extern string    _FILTERS="===================================";
extern bool       UseCompletedBarsOnly =true;    datetime CurrTime=0;datetime PrevTime=0;string Sym="";int Per=0;
extern int        BarBuffer            =0;
//extern int        BarRange             =5;       int Bar=0;
//extern int        PipBuffer            =5;
//extern int        PipRange             =50;
//extern bool       UseSignalToSignal    =true;
//extern bool       UseConstantOrders    =true;
//extern int        MaxConstantOrders    =5;
extern string    _TIMES="===================================";
extern int        Start_Hour           =07;
extern int        Stop_Hour            =13;
extern bool   use_StartStopHour        =false;
extern string    _BROKER="===================================";
//extern bool       UseECNBroker         =true;
extern double     LotSize              =0.1;
extern int        StopLoss             =55;
//extern bool   use_StopLoss             =true;
extern int        TakeProfit           =45;
//extern bool       UseTakeProfit        =true;
//extern string    _CLIENT="===================================";
//extern int        TrailingStart        =26;
//extern bool   use_TrailingStart        =false;
//extern int        TrailingStop         =12;
//extern bool       UseTrailEntry        =false;
//extern bool   use_TrailingStop         =true;
//extern int        MaxSpread            =2;
//extern bool   use_MaxSpread            =true;
//extern int        MaxRetries           =4;
//extern int        MaxSlippage          =3;
extern string    _EXPERT="===================================";
extern bool       UseComments          =true; 
//extern int        Timeframe            =0;
extern int        MagicNumber          =304302;
//extern color      BuyArrowColor        =Blue;
//extern color      SellArrowColor       =Red;
/**********************
    GLOBAL VARIABLES
***********************/
int               SymDigits=5;
double            SymPoints=0.0001;
/**********************
    INITIALIZATION
***********************/
int init()
{
string OrderComments="tp:"+TakeProfit+", sl:"+StopLoss+".";
Sym=Symbol();
Per=Period();
return(0); //END OF INIT
}
/**********************
    START
***********************/
int start()
{
string OrderComments="tp:"+TakeProfit+", sl:"+StopLoss+".";
//TIME MANAGEMENT
if(use_StartStopHour){
  if(!(Hour()>=Start_Hour && Hour()<=Stop_Hour)){
    Comment("Trading Paused; StartHour="+Start_Hour+" & StopHour="+Stop_Hour); 
    return(0);
    }
  }
//---TRAILING STOPS
//PERMIT BARS ONLY??
if(UseCompletedBarsOnly){
  CurrTime=iTime(Sym,Per,1);
  if(CurrTime==PrevTime){
    return(0);
    }
  PrevTime=CurrTime;
  }
//ORDERS MANAGEMENT
if(CountAll(Sym,MagicNumber)==0){
  double MTFMA=iCustom(NULL,0,"#MTF_MovingAverage",TimeFrame,MAPeriod,ma_shift,ma_method,applied_price,0,1);
  
  Print(MTFMA);


/*double Price=Close[0];
  //Print("/MTF_MovingAverage/"+DoubleToStr(MTFMA,Digits)+" /EURUSD/"+DoubleToStr(Price,Digits)+".");
  if( DoubleToStr(Price,Digits) > DoubleToStr(MTFMA,Digits) ){ 
    //EnterBuy(Sym,LotSize,OrderComments);
    Print("BUY");
    }
  else if( DoubleToStr(Price,Digits) < DoubleToStr(MTFMA,Digits)  ){ 
    //EnterSell(Sym,LotSize,OrderComments);
    Print("SELL");
    }
//if(UseCompletedBarsOnly){if(!(BarRange==0)) {if(Bar>=BarRange) {return(0);} Bar++; Print("Bar: "+Bar);} }
*/
  
  }

return(0); //END OF START
}
/**********************
    CUSTOM FUNCTIONS
***********************/
int CountAll(string Symbole,int Magic)
{
int count=0;
for(int i=OrdersTotal()-1; i>=0; i--){
  OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  if(OrderMagicNumber()!= Magic) {continue;}
  if(OrderSymbol()!= Symbole)    {continue;}
       if(OrderType()==OP_BUY)   {count++;}
  else if(OrderType()==OP_SELL)  {count++;}
  }
return(count);
}
//*********************/
int EnterBuy(string FinalSymbol,double FinalLots,string EA_Comment)
{
int Ticket=-1; int err=0; bool OrderLoop=False; int TryCount=0;
while(!OrderLoop)
  {
  while(IsTradeContextBusy()){Sleep(10);}
  RefreshRates();
  double SymAsk=NormalizeDouble(MarketInfo(FinalSymbol,MODE_ASK),SymDigits);
  double SymBid=NormalizeDouble(MarketInfo(FinalSymbol,MODE_BID),SymDigits);
  Ticket=OrderSend(FinalSymbol,OP_BUY,FinalLots,SymAsk,0,0.0,0.0,EA_Comment,MagicNumber,0,CLR_NONE);
  int Err=GetLastError();
  switch (Err) 
    {
    case ERR_NO_ERROR: OrderLoop = true; 
    if(OrderSelect(Ticket,SELECT_BY_TICKET))
    {OrderModify(Ticket,OrderOpenPrice(),BuyStop(SymBid,StopLoss,SymPoints,SymDigits),BuyTake(SymAsk,TakeProfit,SymPoints,SymDigits),0,CLR_NONE);}
    break;
    //---- Retry Error     
    case            ERR_SERVER_BUSY:
    case          ERR_NO_CONNECTION:
    case          ERR_INVALID_PRICE:
    case             ERR_OFF_QUOTES:
    case            ERR_BROKER_BUSY:
    case     ERR_TRADE_CONTEXT_BUSY: TryCount++; break;
    case          ERR_PRICE_CHANGED:
    case                ERR_REQUOTE: continue;
    //---- Fatal known Error 
    case          ERR_INVALID_STOPS: OrderLoop = true; Print("Invalid Stops"); break; 
    case   ERR_INVALID_TRADE_VOLUME: OrderLoop = true; Print("Invalid Lots"); break; 
    case          ERR_MARKET_CLOSED: OrderLoop = true; Print("Market Close"); break; 
    case         ERR_TRADE_DISABLED: OrderLoop = true; Print("Trades Disabled"); break; 
    case       ERR_NOT_ENOUGH_MONEY: OrderLoop = true; Print("Not Enough Money"); break; 
    case  ERR_TRADE_TOO_MANY_ORDERS: OrderLoop = true; Print("Too Many Orders"); break; 
    //---- Fatal Unknown Error
    case              ERR_NO_RESULT:
                            default: OrderLoop=true; Print("Unknown Error - " +Err); break; 
    }
  if(TryCount>10){OrderLoop=true;}
  }         
return(Ticket);
}
//*********************/
double BuyStop(double price,double stop,double point,double SymDgts)
{
 if(stop==0) {return(0);}
 else        {return(NormalizeDouble( price-(stop*point),SymDgts));}
}
//*********************/
double BuyTake(double price,double take,double point,double SymDgts)
{
 if(take==0) {return(0);}
 else        {return(NormalizeDouble(price+(take*point),SymDgts));}
}
//*********************/
int EnterSell(string FinalSymbol,double FinalLots,string EA_Comment)
{int Ticket=-1; int err=0; bool OrderLoop=False; int TryCount=0;
while(!OrderLoop)
  {
  while(IsTradeContextBusy()){Sleep(10);}
  RefreshRates();
  double SymAsk=NormalizeDouble(MarketInfo(FinalSymbol,MODE_ASK),SymDigits);    
  double SymBid=NormalizeDouble(MarketInfo(FinalSymbol,MODE_BID),SymDigits);
  Ticket=OrderSend(FinalSymbol,OP_SELL,FinalLots,SymBid,0,0.0,0.0,EA_Comment,MagicNumber,0,CLR_NONE); 
  int Err=GetLastError();
  switch (Err)
    {
    case ERR_NO_ERROR: OrderLoop=true;
    if(OrderSelect(Ticket,SELECT_BY_TICKET))
    {OrderModify(Ticket,OrderOpenPrice(),SellStop(SymAsk,StopLoss,SymPoints,SymDigits),SellTake(SymBid,TakeProfit,SymPoints,SymDigits),0,CLR_NONE);}
    break;
    //---- Retry Error     
    case            ERR_SERVER_BUSY:
    case          ERR_NO_CONNECTION:
    case          ERR_INVALID_PRICE:
    case             ERR_OFF_QUOTES:
    case            ERR_BROKER_BUSY:
    case     ERR_TRADE_CONTEXT_BUSY: TryCount++; break;
    case          ERR_PRICE_CHANGED:
    case                ERR_REQUOTE: continue;
    //---- Fatal known Error 
    case          ERR_INVALID_STOPS: OrderLoop=true; Print("Invalid Stops"); break; 
    case   ERR_INVALID_TRADE_VOLUME: OrderLoop=true; Print("Invalid Lots"); break; 
    case          ERR_MARKET_CLOSED: OrderLoop=true; Print("Market Close"); break; 
    case         ERR_TRADE_DISABLED: OrderLoop=true; Print("Trades Disabled"); break; 
    case       ERR_NOT_ENOUGH_MONEY: OrderLoop=true; Print("Not Enough Money"); break; 
    case  ERR_TRADE_TOO_MANY_ORDERS: OrderLoop=true; Print("Too Many Orders"); break; 
    //---- Fatal Unknown Error
    case              ERR_NO_RESULT:
                            default: OrderLoop=true; Print("Unknown Error - "+Err); break;
    }
  if(TryCount>10){OrderLoop=true;}
  }           
return(Ticket);
}
//*********************/
double SellStop(double price,double stop,double point,double SymDgts)
{
 if(stop==0){return(0);}
 else       {return(NormalizeDouble( price+(stop*point),SymDgts));}
}
//*********************/
double SellTake(double price,double take,double point,double SymDgts)
{
 if(take==0){return(0);}
 else       {return(NormalizeDouble( price-(take*point),SymDgts));}
}
/**********************
    DEINITIALIZATION
***********************/
int deinit()
{
if(!(UseComments)){
  Comment("");
  }
return(0); //END OF DEINIT
}

the last that I changed is Print(DoubleToStr(MTFMA,Digits)); to see the 5th decimal.

I am not very well at telling what is going on with this indicator to tell if this is what should be happening because shouldn't the price be the same here instead of varying???

Files:
 

The prices are coorect when the timeframe is 0 and the period is 20 and not 1

 
You call iCustom with shift=1. That means the Open time of the previous bar in your timeframe (4h). If and when this Open time is later then midnight, the applied MTF Indicator sets the internal index for his iMA Call (to get the average) to zero. This relates to the time of the actual day. Applied Price ist set to PRICE_CLOSE. But Close at bar zero is always the actual price and varying (as long as the market is open...). Therefore, you should recalculate the shift position and set it to the last bar of the previous day in your timeframe.
 

So is it the indicator or maybe my expert?? I actually wanted to set the shift from the external inputs using int BarBuffer but have been trying various things...

I Since have been trying to see the whole number of the only index buffer using DoubleToStr,..,8 to see if its maybe rounding the price but its not. Only thing I see is it doesn't have the same price as the indicator itself.. when I am setting the MA to D1(1440) with period 1 (on the H1) the indicator is a straight lines at times with a price of 1.3335 for example and the problem is that if you wanted to print this price in progression of bars it is never the same and hardly every correct.

I am not really good with indicator programming yet but I am trying to figure out if this has anything to do with the indicator or not because the indicator call from an expert is the simplest part of it because there is only one index buffer, and the shift has been 0 or 1(because my BarBuffer was going to be set at 1) or variations.

Still doesn't make very much sense unless I have to have better tick data which is what I will have to expect that it is and try some good stuff I have eventually but I am going to have to decide to go with no timeframe for now because from what I have seen with this indicator it DOES NOT WORK.

 
 
I know I must have a valid point about tick data, but originally when I was trying to find signals they were the same as the close price of zero so when I ask the indicator to print the value of the indicator versus the close price of bar zero (with the indicator set to a higher period of 4 for instance) there is a price difference. But the problem I had was in strategy tester I could not find that the prices were ever the same and even though were talking bars, its a fact that alot of bars have the same price as close of bar price and its just not possible to see it with the tick data using strategy tester. I'll admit that it is extreme to use the day moving average almost like a pivot on the lower time frames but I will have to do with using an average bar value instead of just a 1 bar average of higher timeframes.
 

What the hell now it acts all weird like its pointing upward but doesn't on the demo, i just wiped out history and redownloaded and even made new EA and doesn't act the same.

Reason: