Download MetaTrader 5
To add comments, please log in or register
All articles are available from MetaTrader 5. Contribute your own one!
richbois
29
richbois 2016.11.24 11:18 

Hi All 

I am having a small problem  and I am pretty new at this

#property indicator_chart_window

extern color TTT_PH_Color = LawnGreen;
extern color TTT_BdL_Color = Red;
extern color TTT_PL_Color = Tomato;
extern color TTT_p_Color = Orange;
extern color TTT_Color = Orange;
extern color TTT_v_Color = Orange;
extern color TTT_MAp_Color = Magenta;
extern color TTT_MA_Color = Magenta;
extern color TTT_MAv_Color = Magenta;
extern color TTT_Day_Color = White;

int deinit()
   {
    ObjectsDeleteAll(0, "TTT");  
    return( 0 );    
   }
  
int start()
  {

 the rest of the code I have managed to make it work in MLQ5

the issue is that when I start MT5  it does not update automatically   I have to go to each chart and put back the indicator on the chart

also the indicator dont appear anywhere as it use to but just the lines and text in the objects.

this is the start of the MLQ5

#property indicator_chart_window

extern color TTT_PH_Color = LawnGreen;
extern color TTT_BdL_Color = Red;
extern color TTT_PL_Color = Tomato;
extern color TTT_p_Color = Orange;
extern color TTT_Color = Orange;
extern color TTT_v_Color = Orange;
extern color TTT_MAp_Color = Magenta;
extern color TTT_MA_Color = Magenta;
extern color TTT_MAv_Color = Magenta;
extern color TTT_Day_Color = White;

int deinit()
   {
    ObjectsDeleteAll(0, "TTT");  
    return( 0 );    
   }
  
int start()
  {

 

the int deinit dont seem to do anything   as i had to add  the delete function on each of the objectcreate

 

any help would be appeciated

Thank you in advance

Alain Verleyen
Moderator
29414
Alain Verleyen 2016.11.24 11:20  
Alain Verleyen
Moderator
29414
Alain Verleyen 2016.11.24 11:22  
richbois:

the int deinit dont seem to do anything   as i had to add  the delete function on each of the objectcreate

There is no deinit() on mql5, only OnDeinit(). Please check mql5 documentation.
richbois
29
richbois 2016.11.24 11:30  
Alain Verleyen:
Please edit your post.
#property copyright "2016, Taylor Trading Technique."
#property link      "http://www.taylortradingtechnique.net"
#property version   "1.00"

//--- global variables
string data[10][2];
input color TTT_PH_Color = LawnGreen;
input color TTT_BdL_Color = Red;
input color TTT_PL_Color = Tomato;
input color TTT_p_Color = Orange;
input color TTT_Color = Orange;
input color TTT_v_Color = Orange;
input color TTT_MAp_Color = Magenta;
input color TTT_MA_Color = Magenta;
input color TTT_MAv_Color = Magenta;
input color TTT_Day_Color = White;


int deinit()
   {
      ObjectsDeleteAll(0, "TTT");        
      return( 0 );    
   }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   string separator=",";
   int m_handle=-1, count = 0, line_count = 1;
   string symb = Symbol();
   string m_filename = symb + ".CSV";
      
   m_handle=FileOpen(m_filename,FILE_CSV|FILE_ANSI|FILE_READ,separator,CP_ACP);
   if(m_handle<0)
     {
     Print("I can't open the file.");
     }
     else
     {
     Print("File successfully open.");
     while (FileIsEnding(m_handle) == false)
     {
     data[count][0]=FileReadString(m_handle, 10);
     if (FileIsLineEnding(m_handle) == true)line_count ++;
     count ++;
     }
    
      double val1 = StringToDouble(data[0][0]);
      double val2 = StringToDouble(data[1][0]);
      double val3 = StringToDouble(data[2][0]);
      double val4 = StringToDouble(data[3][0]);
      double val5 = StringToDouble(data[4][0]);
      double val6 = StringToDouble(data[5][0]);
      double val7 = StringToDouble(data[6][0]);
      double val8 = StringToDouble(data[7][0]);
      double val9 = StringToDouble(data[8][0]);
      string val10= data[9][0];
      
/*      Print ("val 1   " + DoubleToString(val1));
      Print ("val 2   " + DoubleToString(val2));
      Print ("val 3   " + DoubleToString(val3));
      Print ("val 4   " + DoubleToString(val4));
      Print ("val 5   " + DoubleToString(val5));
      Print ("val 6   " + DoubleToString(val6));
      Print ("val 7   " + DoubleToString(val7));
      Print ("val 8   " + DoubleToString(val8));
      Print ("val 9   " + DoubleToString(val9));          
      Print ("val 10   " + val10);
*/
  
      FileClose(m_handle);
      
      int p = Period();        
      int marg =   (p);            
      if(p > 16380) marg = p;                        
      if(p <= 60) marg = 16385 * p / 60;                        
      
      ObjectsDeleteAll(0, "TTT");    
  
      ObjectCreate(0, "TTT Previous Day High Level", OBJ_HLINE, 0, NULL, val1 );
      ObjectSetInteger(0,"TTT Previous Day High Level",OBJPROP_COLOR,TTT_PH_Color);
      ObjectSetInteger(0,"TTT Previous Day High Level",OBJPROP_WIDTH,2);
      
    
      if(ObjectFind(0,"TTT Day label")<0)
        {          
        ObjectCreate(0,"TTT Day label",OBJ_LABEL,0,0,0);            
        ObjectSetInteger(0,"TTT Day label",OBJPROP_XDISTANCE,20);        
        ObjectSetInteger(0,"TTT Day label",OBJPROP_YDISTANCE,20);        
        ObjectSetInteger(0,"TTT Day label",OBJPROP_COLOR,TTT_Day_Color);        
        ObjectSetString(0,"TTT Day label",OBJPROP_TEXT,val10 + " Day");        
        ObjectSetString(0,"TTT Day label",OBJPROP_FONT,"Times New Roman");        
        ObjectSetInteger(0,"TTT Day label",OBJPROP_FONTSIZE,25);        
        ChartRedraw(0);      
        }            
        
      if(ObjectFind(0,"TTT label")<0)
        {            
        ObjectCreate(0,"TTT label",OBJ_LABEL,0,0,0);          
        ObjectSetInteger(0,"TTT label",OBJPROP_XDISTANCE,20);        
        ObjectSetInteger(0,"TTT label",OBJPROP_YDISTANCE,890);        
        ObjectSetInteger(0,"TTT label",OBJPROP_COLOR,TTT_Day_Color);        
        ObjectSetString(0,"TTT label",OBJPROP_TEXT,"TTT data by www.taylortradingtechnique.net");        
        ObjectSetString(0,"TTT label",OBJPROP_FONT,"Times New Roman");        
        ObjectSetInteger(0,"TTT label",OBJPROP_FONTSIZE,14);
        ChartRedraw(0);      
        }
            
      if(ObjectFind(0, "TTT Previous Day High") != 0)
        {
         ObjectCreate(0, "TTT Previous Day High", OBJ_TEXT, 0,TimeCurrent()+ marg , val1);        
         ObjectSetInteger(0,"TTT Previous Day High",OBJPROP_COLOR,TTT_PH_Color);        
         ObjectSetString(0,"TTT Previous Day High",OBJPROP_TEXT,"TTT PH    ");          
         ObjectSetString(0,"TTT Previous Day High",OBJPROP_FONT,"Times New Roman");        
         ObjectSetInteger(0,"TTT Previous Day High",OBJPROP_FONTSIZE,12);
         ChartRedraw(0);
         }
         else
         {  
          ObjectMove(0, "TTT Previous Day High", 0, TimeCurrent()+ marg , val1);
          ObjectSetInteger(0,"TTT Previous Day High",OBJPROP_COLOR,TTT_PH_Color);        
          ObjectSetString(0,"TTT Previous Day High",OBJPROP_TEXT,"TTT PH    ");          
          ObjectSetString(0,"TTT Previous Day High",OBJPROP_FONT,"Times New Roman");        
          ObjectSetInteger(0,"TTT Previous Day High",OBJPROP_FONTSIZE,12);
          ChartRedraw(0);      
         }
                
     }
    
            
            
   PlaySound("wait.wav");
  
  }
richbois
29
richbois 2016.11.24 11:56  

i had to remove some of the code as  it was too long    but it is only to create additional line and labels

same as the  TTT Previous Day High

If you want to test it  you will need this CSV file in the file folder

this is for EURUSD.csv     cant upload CSV  but here is the content  and you could save is as CSV

 1.0643

1.0582

1.0525

1.07

1.0734

1.0464

1.0672

1.0651

1.0489

SellShort


richbois
29
richbois 2016.11.24 17:32  

sorry  fixed one but not the 1st

Alain Verleyen
Moderator
29414
Alain Verleyen 2016.11.24 19:49  
richbois:

sorry  fixed one but not the 1st

Please attach files (mql5, data). Don't include them in the post.
Bruri Setiya Budi
116
Bruri Setiya Budi 2016.11.30 18:36  

Hi...

Can somebody help me to converting this indicator to MQL5?

Regards 

Alain Verleyen
Moderator
29414
Alain Verleyen 2016.11.30 19:02  
richbois
29
richbois 2016.12.01 18:23  

Thank you Alain for your help 

got most of it figured out

Need the dayhigh and daylow for the last x candles

I got the array to print  but i need the the actual dayhi and daylo

 I must be blind  or missing a small detail

please help

double dayhi = 0 , daylo =0;

void  OnStart()
  {
    int h = 0;
   int hours, minutes;
  
//  Comment("Loading...");
   int maxBars= 24;
   string comment="";

   string timestring = TimeToString(TimeCurrent(),TIME_MINUTES) ;
   Print( timestring);

// ConvertTime(string timeString, int &hours, int &minutes)
  {
   //string must be 5 characters long
   if(StringLen(timestring)==5)
     {
      //split the string
      string splits[];
      if(StringSplit(timestring,':',splits)==2)
        {
         hours   = (int)StringToInteger(splits[0]);
         minutes = (int)StringToInteger(splits[1]);

         //verifiy time validity
         if(hours>=0 && hours<=23 && minutes>=0 && minutes<=59)
           {
            h = hours ;
            maxBars = h + 3;
            
            Print( h  );  Print( maxBars  );
           }
        }
     }
   }
    
      double High[];
   // number of elements to copy
ArraySetAsSeries(High,true);
CopyHigh(_Symbol,PERIOD_H1,0,18,High);




  Print( maxBars  );
  Print(dayhi);
   MqlRates  rates_array[];
   ArraySetAsSeries(rates_array,true);
   int bars=CopyRates(_Symbol,PERIOD_H1,0,maxBars,rates_array);
   string fileName=_Symbol+ IntegerToString(60)+"test.csv";

   if(bars>1)
     {
      int filehandle=FileOpen(fileName,FILE_WRITE|FILE_CSV);
      for(int i=bars-1; i>=0; i--)
        {
         FileWrite(filehandle,
          
            rates_array[i].high,
            rates_array[i].low);
            
            
            dayhi =rates_array[i].high;
            daylo =rates_array[i].low;
         Print(rates_array[i].high); //Print(daylo);  
            if( rates_array[i].high > dayhi) {dayhi = rates_array[i].high;}
            if( rates_array[i].low < daylo) {daylo = rates_array[i].low;}
          Print(dayhi); //Print(daylo);  
            
        }
      FileFlush(filehandle);
      FileClose(filehandle);
   //High
  //    Print(dayhi); Print(daylo);

     }
}


 

Jose Francisco Casado Fernandez
1977
Jose Francisco Casado Fernandez 2016.12.05 09:43  
OnStart() function only for scripts. For indicators, use OnCalculate(.....). Regards
/
To add comments, please log in or register