indiTraders - Forum for the Active Indian Trader  

Go Back   indiTraders - Forum for the Active Indian Trader > Tools > Software > Amibroker

Reply
 
Bookmark and Share LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 16-12-2016, 02:24 AM
icytrader icytrader is offline
Newbie
 
Join Date: Nov 2015
Posts: 9
Thanks: 1
Thanked 14 Times in 7 Posts
icytrader is on a distinguished road
Default Elliot Wave - TD D wave - need help converting from MQ4 to AFL

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);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 3 Users Say Thank You to icytrader For This Useful Post:
  #2 (permalink)  
Old 16-12-2016, 09:58 AM
no1lives4ever no1lives4ever is offline
Newbie
 
Join Date: Jul 2009
Posts: 3,296
Thanks: 19,013
Thanked 5,549 Times in 2,358 Posts
no1lives4ever has a reputation beyond repute
no1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond repute
Default

Originally Posted by icytrader View Post
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);
}



Can you post the version that you came up with in Amibroker AFL. That would help us figure out where you were going wrong and help you out.

-- no1lives4ever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 3 Users Say Thank You to no1lives4ever For This Useful Post:
  #3 (permalink)  
Old 17-12-2016, 01:29 AM
icytrader icytrader is offline
Newbie
 
Join Date: Nov 2015
Posts: 9
Thanks: 1
Thanked 14 Times in 7 Posts
icytrader is on a distinguished road
Default

Honestly, I have no idea where to begin in converting this to ami AFL. I pretty much suck at the looping part, but besides that I will try my best to convert what I can and reduce the errors in compiling this afl from 48 errors to as low as I can go. Should be able to put up the edited stuff for more rectification here tomorrow.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 3 Users Say Thank You to icytrader For This Useful Post:
  #4 (permalink)  
Old 20-12-2016, 04:18 PM
icytrader icytrader is offline
Newbie
 
Join Date: Nov 2015
Posts: 9
Thanks: 1
Thanked 14 Times in 7 Posts
icytrader is on a distinguished road
Default

Code:
 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;
How do I convert this initial set of code before beginning the loop? I am stuck here. I have converted the bool c++ functions in the code to amibroker afl. to move ahead with the loop I need to fix these lines. Any help would be appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to icytrader For This Useful Post:
  #5 (permalink)  
Old 20-12-2016, 06:10 PM
icytrader icytrader is offline
Newbie
 
Join Date: Nov 2015
Posts: 9
Thanks: 1
Thanked 14 Times in 7 Posts
icytrader is on a distinguished road
Default

Originally Posted by no1lives4ever View Post
Can you post the version that you came up with in Amibroker AFL. That would help us figure out where you were going wrong and help you out.

-- no1lives4ever

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.

Could you take a look at this please. I have not entered all the other waves except for wave 1 as I'd like to keep errors at a minimum till I can fix the basic afl first.

Here is the modified code.
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;
}

   
 }
 }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to icytrader For This Useful Post:
  #6 (permalink)  
Old 20-12-2016, 08:46 PM
no1lives4ever no1lives4ever is offline
Newbie
 
Join Date: Jul 2009
Posts: 3,296
Thanks: 19,013
Thanked 5,549 Times in 2,358 Posts
no1lives4ever has a reputation beyond repute
no1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond repute
Default

Originally Posted by icytrader View Post
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.

Could you take a look at this please. I have not entered all the other waves except for wave 1 as I'd like to keep errors at a minimum till I can fix the basic afl first.

Here is the modified code.
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;
}

   
 }
 }

You cant just do a simple modification to mql code to get amibroker afl. You need to understand the code and then re-write it as per amibroker afl.

This strategy will not help

-- no1lives4ever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to no1lives4ever For This Useful Post:
  #7 (permalink)  
Old 20-12-2016, 11:59 PM
icytrader icytrader is offline
Newbie
 
Join Date: Nov 2015
Posts: 9
Thanks: 1
Thanked 14 Times in 7 Posts
icytrader is on a distinguished road
Default

Originally Posted by no1lives4ever View Post
You cant just do a simple modification to mql code to get amibroker afl. You need to understand the code and then re-write it as per amibroker afl.

This strategy will not help

-- no1lives4ever

Thanks for replying. Could you please elaborate on how to modify mq4 code to turn it to afl? I have no idea how to do it or else I would have just done it. If you can tell me what I need to do I will look into it and try to write it. I am pretty much a novice at coding. To put into perspective, I've just started to understand how loops work, ata very basic level. So I'll appreciate any guidance I can get to learn it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to icytrader For This Useful Post:
  #8 (permalink)  
Old 21-12-2016, 02:04 AM
icytrader icytrader is offline
Newbie
 
Join Date: Nov 2015
Posts: 9
Thanks: 1
Thanked 14 Times in 7 Posts
icytrader is on a distinguished road
Default

Ok, I finally realised what I was doing wrong, I quite forgot that in AFL the syntax for inside the loop is pretty much the same as c++. I kept referencing startday when I should have been referencing the current bar. made a few changes. Here is the code. It now plots however as you will see it plots too many points. I need to now figure out a loop to count through the bars and select the highest/lowest point in a wave to place the specific number.

Code:
 
 




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 (daysback[i] <= startday [i+ 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 (daysback[i] >= startday [i+1])
      False;
  }
  
  return (True);
}    


/*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();*/

  // counted_bars = 0;
   

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

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

  // For all bars starting 21 days from the earliest
 // if (BarCount >= limit) {
  for(i = BarCount - 20; i >= 0; i--) {
    //If wave has not started
    if (waveNumber == 0) { //Alert("0");
      //find a 21 day low
      if (isMinClose(21, i)) {
       PlotText( "0" , i , L[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)) {
      PlotText( "1" , i , H[i]+dist[i]*0.15, colorBlack  );
        //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)) {
      PlotText( "2" , i , L[i]-dist[i]*0.15, colorBlack  );
        //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)) {
      PlotText( "3" , i , H[i]+dist[i]*0.35, colorBlack  );
       // 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)) {
      
      PlotText( "4" , i , L[i]-dist[i]*0.35, colorBlack  ) ;
       // 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)) {
      PlotText( "5" , i , H[i]+dist[i]*0.55, colorBlack  );

       // ObjectCreate(""+i, OBJ_TEXT, 0, Time[i],High[i] + 10 * Point );
       // ObjectSetText(""+i, "5", 15, "Arial", Lime);
        
        waveNumber = 0;
}

   
 }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following 2 Users Say Thank You to icytrader For This Useful Post:
  #9 (permalink)  
Old 21-12-2016, 08:17 AM
no1lives4ever no1lives4ever is offline
Newbie
 
Join Date: Jul 2009
Posts: 3,296
Thanks: 19,013
Thanked 5,549 Times in 2,358 Posts
no1lives4ever has a reputation beyond repute
no1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond reputeno1lives4ever has a reputation beyond repute
Default

Thing is that MQL code works with a very different execution model. Amibroker AFL can run in loop mode, but it also has the array mode, where it can do things real fast.

e.g. You have function calls to check if today's close is less than the close of last n days, this is easily coded in Amibroker using the following simple code fragment:

isMaxClose = C < Ref(LLV(C, n), 1);

And then you can reffer to this value as isMaxClose[i] inside a loop.

There is no real 1:1 conversion between mql code and afl code. You will need to understand the logic of the mql code and then re-write it in AFL.

I dont have the time to do this conversion for you I originally thought you got stuck at some small errors. But with your current approach, to get somethign with similar functionality, you will need to spend way more time than just changing a few things here and there.

-- no1lives4ever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to no1lives4ever For This Useful Post:
Reply

indiTraders - Forum for the Active Indian Trader > Tools > Software > Amibroker


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 08:23 PM.


vBulletin Copyright by vBulletin

Content Relevant URLs by vBSEO 3.3.2