dema crossing

 

Hi

Trying to get a signal for dema crossing similar to ema crossing, but since iDEMA isn't available like iMA where I can just use "iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 1)", I'm trying to create this myself.

I can get the values for dema on the first tick of each new bar, but not for the last bar, or 1 before that. My idea was that the result of dema will be written to an array, and then I can just get the elements when needed with dema_array[0], dema_array[1] etc.

But that doesn't seem to work as both elements give the same value.

//+------------------------------------------------------------------+
//|                                                   test array.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


static datetime LastTradeBarTime;

double dema14_buffer[5];

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
     LastTradeBarTime = Time[1]; // initialise the variable
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

int    i,limit=ArraySize(dema14_buffer);
ArraySetAsSeries(dema14_buffer,true);

//----
if (LastTradeBarTime == Time[0]) return(0); // Not <first detected tick> on this bar so quit

  else LastTradeBarTime = Time[0]; // and continue

// dema 14  buffer
        for(i=0; i<limit; i++)
        dema14_buffer[i]=iCustom(NULL,0,"dema",14,0,0);

  Alert ("Dema 14 array 0 = " + dema14_buffer[0]);
       Alert ("Dema 14 array 1 = " + dema14_buffer[1]);
       
//----
   return(0);
  }
//+------------------------------------------------------------------+

 

roelfsch:

Trying to get a signal for dema crossing similar to ema crossing, but since iDEMA isn't available like iMA where I can just use "iMA(NULL, 0, 14, 0, MODE_SMA, PRICE_CLOSE, Current + 1)", I'm trying to create this myself.

I can get the values for dema on the first tick of each new bar, but not for the last bar, or 1 before that.

dema14_buffer[i]=iCustom(NULL,0,"dema",14,0,0);

What is the difference between the last argument in the iMA() call and the last argument in your iCustom() call, and why?
 
WHRoeder:
What is the difference between the last argument in the iMA() call and the last argument in your iCustom() call, and why?


They should both be price shifts, so I think they are the same? (The iMA just sets it depending on the value of "Current" + 1)

I have tried this as well ...

int start()
  {

double dema14;
double dema14_1;
//----
if (LastTradeBarTime == Time[0]) return(0); // Not <first detected tick> on this bar so quit

  else LastTradeBarTime = Time[0]; // and continue

// dema 14  buffer, only need 2 or 3 bars
        dema14=iCustom(NULL,0,"dema",14,0,0);
        dema14_1=iCustom(NULL,0,"dema",14,0,1);

  Alert ("Dema 14 = " + dema14);
  Alert ("Dema 14_1 = " + dema14_1);
       
//----
   return(0);
  }

but the I still get this ...

Now I think that Dema 14_1 @ 16:50 should be equal to Dema 14 @ 16:45 as it should have shifted on the new bar. But from the screenshot you can see this is not so.

 
  1. dema14_buffer[i]=iCustom(NULL,0,"dema",14,0,0);
    You are ONLY looking at bar zero so of course you only get that "not for the last bar, or 1 before that"
  2.         dema14=iCustom(NULL,0,"dema",14,0,0);
            dema14_1=iCustom(NULL,0,"dema",14,0,1);
    
    You are only looking at the start of a bar, so the difference between dema(open[0]) and dema(close[1]) will always be very close, because close[1] and open[0] is one tick different.
 
WHRoeder:
  1. You are ONLY looking at bar zero so of course you only get that "not for the last bar, or 1 before that"
  2. You are only looking at the start of a bar, so the difference between dema(open[0]) and dema(close[1]) will always be very close, because close[1] and open[0] is one tick different.


Thanks, think I got it now, just had to shift another bar down so not to use the current bar.

dema14=iCustom(NULL,0,"dema",14,0,1);

dema14_1=iCustom(NULL,0,"dema",14,0,2);