why ema in mt4 draw things and in treadingview another things ?

 

hy guys  i try to convert  tradingview indicator to mt4 the  code is simple  open-close  and  result  insert in ema 1500 period

this is my code

//+------------------------------------------------------------------+
//|                                                     MM2Smoth.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "  "
#property strict
#property indicator_separate_window  // indicatore in seprata window
#property indicator_buffers 1       // Number of buffers
#property indicator_color1 Green     //  

int  barsbackN = 1500;
extern string   b10="=== SET. TIME FRAME ===";
extern int  timeframe = 0;

double ArrayNClose[1];
double ArrayNOpen[1];
double ArrayDifN[1];
 
double EmaA[1];
 

 

double Buf_0[],Buf_1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   ChartSetSymbolPeriod(0,Symbol(),PERIOD_M5);

   IndicatorShortName("SilverWave 1.0");
   SetIndexBuffer(0,Buf_0);         // Assigning an array to a buffer
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2); // Line style
   
//--- indicator buffers mapping
//--  BLOCK A
   ArrayResize(ArrayNClose,barsbackN);
   ArrayResize(ArrayNOpen,barsbackN);
   ArrayResize(ArrayDifN,barsbackN);
   ArrayResize(EmaA,barsbackN);
    

//---
 
   SetIndexDrawBegin(0,barsbackN);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

// NUMERATOR
   CopyClose(Symbol(),Period(),0,barsbackN,ArrayNClose);
   CopyOpen(Symbol(),Period(),0,barsbackN,ArrayNOpen);
   for(int i=0; i<=(barsbackN-1); i++)
     {
      ArrayDifN[i]=MathAbs(((ArrayNOpen[i]-ArrayNClose[i]));
     }
   for(int i=0; i<=(barsbackN-1); i++)
     {
      EmaA[i] =  iMAOnArray(ArrayDifN,0,1500,0,MODE_EMA,i);
     }
  
// FUNCTION 4 DRAW INDICATOR

   int Counted_bars=barsbackN;
   int J=Bars-Counted_bars-1;
   while(J>=0)
     {
    
        Buf_0[J]= ( EmaA[J] );
      J--;
     }
   return 0;
  }

//+------------------------------------------------------------------+

and this is my graph

in treading view return this

anyone  have some idea ? thanks  at all

 
faustf:

hy guys  i try to convert  tradingview indicator to mt4 the  code is simple  open-close  and  result  insert in ema 1500 period

this is my code

and this is my graph

in treading view return this

anyone  have some idea ? thanks  at all

are these charts have 2 different Time Frames?

 
I have noticed same with adx indicator - on trading view and metatrader its huge difference even when settings are same - 14 days period. Does not make sense. Could try to see code, in trading view I guess it is visible, but in metatrader when I tried - could not see source.
 

@poker_player

this is a tradingview code

//=========================================================================
//@version=4
study("SilverLine A1","SilverLine A1", overlay = false)

// ————————————————————————————————————————————————————————————
// >>>>>>>>>>>>>>>>>>>>>>>>  Inputs  <<<<<<<<<<<<<<<<<<<<<<<<<<
// ————————————————————————————————————————————————————————————
tf        = input("")
Mom = input(1500)
Smooth = input(2)

SW =  security("",tf,ema(close-open,Mom),Smooth)

plot(SW, color = color.white, style=plot.style_line, title="SW", transp=0, linewidth =2)

@Irwan Adnan i use different time frame because  when i set 1 minuts in MT4  tell me  , in this li ne

   Buf_0[J]= ( EmaA[J] );

array out of range .but  with the same time frame have 2 graph unlike