Elliot Wave - TD D wave - need help converting from MQ4 to AFL

icytrader

Active Member
#1
Hi guys,

I am trying to convert this MQ4 code for Demark's elliott wave into Amibroker afl code. At the moment, I am fairing miserably. I'll post the code here. Any help will be appreciated. If I can complete the code, I'll share it here as expected on the forum.

Code:
//+------------------------------------------------------------------+
//| TD D-Wave.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "clam61"
#property link ""
#property indicator_chart_window

//---- input parameters

datetime time;
int i;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
  return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
  for(i = 0; i < Bars; i++)
	 ObjectDelete(""+i);

  return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {

   if(time!=Time[0]){for(i = 0; i < Bars; i++)
	 ObjectDelete(""+i);time=Time[0];}

  int counted_bars = IndicatorCounted();

  // check for possible errors
  if(counted_bars < 0) 
    return (-1);

  // last counted bar will be recounted
  if(counted_bars>0) 
    counted_bars--;
    
  int limit = 500;//Bars - counted_bars;
  
  int waveNumber = 0;

  // For all bars starting 21 days from the earliest
  for(int i = limit - 22; i >= 0; i--) {
    //If wave has not started
    if (waveNumber == 0) { //Alert("0");
      //find a 21 day low
      if (isMinClose(21, i)) {
        ObjectCreate(""+i, OBJ_TEXT, 0, Time[i], Low[i] - 10 * Point );
        ObjectSetText(""+i, "A", 15, "Arial", Lime);
        waveNumber = 1;
      }
    }
    else if (waveNumber == 1) {
      //find a 13 day high
      if (isMaxClose(13, i)) {
        ObjectCreate(""+i, OBJ_TEXT, 0, Time[i], High[i] + 10 * Point );
        ObjectSetText(""+i, "1", 15, "Arial", Lime);
        
        waveNumber = 2;
      }
    }
    else if (waveNumber == 2) {
      //find a 8 day low
      if (isMinClose(8, i)) {
        ObjectCreate(""+i, OBJ_TEXT, 0, Time[i], Low[i] - 10 * Point );
        ObjectSetText(""+i, "2", 15, "Arial", Lime);
        
        waveNumber = 3;
      }
    }
    else if (waveNumber == 3) {
      //find a 21 day high
      if (isMaxClose(21, i)) {
        ObjectCreate(""+i, OBJ_TEXT, 0, Time[i],High[i] + 10 * Point );
        ObjectSetText(""+i, "3", 15, "Arial", Lime);
        
        waveNumber = 4;
      }
    }
    else if (waveNumber == 4) {
      //find a 13 day low
      if (isMinClose(13, i)) {
        ObjectCreate(""+i, OBJ_TEXT, 0, Time[i],Low[i] - 10 * Point );
        ObjectSetText(""+i, "4", 15, "Arial", Lime);
        
        waveNumber = 5;
      }
    }
    else if (waveNumber == 5) {
      //find a 34 day high
      if (isMaxClose(34, i)) {
        ObjectCreate(""+i, OBJ_TEXT, 0, Time[i],High[i] + 10 * Point );
        ObjectSetText(""+i, "5", 15, "Arial", Lime);
        
        waveNumber = 0;
      }
    }
  }
    
  return(0);
}

bool isMinClose(int daysBack, int startDay) {

  for (int i = 1; i < daysBack + 1; i++) {
    //if today's close greater than a close in the past x days
    if (Close[startDay] >= Close[startDay + i])
      return (false);
  }
  
  return (true);
}    

bool isMaxClose(int daysBack, int startDay) {

  for (int i = 1; i < daysBack + 1; i++) {
    //if today's close less than a close in the past x days
    if (Close[startDay] <= Close[startDay + i])
      return (false);
  }
  
  return (true);
}


This at the very beginning itself is confusing me

if(time!=Time[0]){for(i = 0; i < Bars; i++)
ObjectDelete(""+i);time=Time[0];}

int counted_bars = IndicatorCounted();

// check for possible errors
if(counted_bars < 0)
return (-1);

// last counted bar will be recounted
if(counted_bars>0)
counted_bars--;

int limit = 500;//Bars - counted_bars;

int waveNumber = 0;


I have already converted the Bool function to amibroker function but I can't get a move on the loop due to this first set of arguments.
 

icytrader

Active Member
#2
Ok So I have tried to make this a proper afl. From what I gathered I now have the correct function in place but it seems I have some sort of syntax error somewhere in the afl.

I am down to only 1 error and thats driving me nuts.

Code:
//+------------------------------------------------------------------+
//| TD D-Wave.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
/*#property copyright "clam61"
#property link ""
#property indicator_chart_window
*/
//---- input parameters
/*
datetime time;
int i;
*//*
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
  return(0);
}*/

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+

  //for(i = 0; i < BarCount; i++)
	// ObjectDelete(""+i);

//  return(0);
//}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
 //start() {
 
 
 SetBarsRequired(sbrAll);

    
i=0;
TimeNum()==0;
counted_bars = BarCount;
daysback=0;
dist= 1.5*ATR(10);
   
   function isMaxClose(daysBack,startDay) {

  for ( i = 1; i < daysBack + 1; i++) {
    //if today's close less than a close in the past x days
    if (Close[startDay] <= Close[startDay + i])
      false;
  }
  
  return (True);
}   
 function isMinClose(daysBack,startDay) {

  for (i = 1; i < daysBack + 1; i++) {
    //if today's close greater than a close in the past x days
    if (Close[startDay] >= Close[startDay +i ])
      False;
  }
  
  return (True);
}    




   for(i = 0; i < BarCount; i++) {
	 // for (i=0; i < BarCount; i++) {
	 // if(TimeNum()> 0);
	 //ObjectDelete(""+i);time=Time[0];}

   counted_bars = BarCount;
   

  // check for possible errors
  if(counted_bars < 0) 
    -1;
    

  // last counted bar will be recounted
  if(counted_bars>0) 
    counted_bars--;
    
   limit = 500;//Bars - counted_bars;
  
   waveNumber = 0;
   
   
   

  // For all bars starting 21 days from the earliest
  for(i = limit - 22; i >= 0; i--) {
    //If wave has not started
    if (waveNumber == 0) { //Alert("0");
      //find a 21 day low
      if (isMinClose(21, i)) {
       PlotText( "1" , i , H[i]+dist[i]*0.15, colorBlack  );
        //ObjectCreate(""+i, OBJ_TEXT, 0, Time[i], Low[i] - 10 * Point );
       // ObjectSetText(""+i, "A", 15, "Arial", Lime);
        waveNumber = 1;
      }
    }
    else if (waveNumber == 1) {
      //find a 13 day high
      if (isMaxClose(13, i)) {
        //ObjectCreate(""+i, OBJ_TEXT, 0, Time[i], High[i] + 10 * Point );
        //ObjectSetText(""+i, "1", 15, "Arial", Lime);
        
        waveNumber = 2;
      }
    }
    else if (waveNumber == 2) {
      //find a 8 day low
      if (isMinClose(8, i)) {
        //ObjectCreate(""+i, OBJ_TEXT, 0, Time[i], Low[i] - 10 * Point );
        //ObjectSetText(""+i, "2", 15, "Arial", Lime);
        
        waveNumber = 3;
      }
    }
    else if (waveNumber == 3) {
      //find a 21 day high
      if (isMaxClose(21, i)) {
       // ObjectCreate(""+i, OBJ_TEXT, 0, Time[i],High[i] + 10 * Point );
       // ObjectSetText(""+i, "3", 15, "Arial", Lime);
        
        waveNumber = 4;
      }
    }
    else if (waveNumber == 4) {
      //find a 13 day low
      if (isMinClose(13, i)) {
       // ObjectCreate(""+i, OBJ_TEXT, 0, Time[i],Low[i] - 10 * Point );
       // ObjectSetText(""+i, "4", 15, "Arial", Lime);
        
        waveNumber = 5;
      }
    }
    else if (waveNumber == 5) {
      //find a 34 day high
      if (isMaxClose(34, i)) {
       // ObjectCreate(""+i, OBJ_TEXT, 0, Time[i],High[i] + 10 * Point );
       // ObjectSetText(""+i, "5", 15, "Arial", Lime);
        
        waveNumber = 0;
}

   
 }
 }
 

Similar threads