Coding help - page 782

 
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. mcaesart: But it doesn't work as I want.

    "Doesn't work" is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
    How To Ask Questions The Smart Way. 2004
              When asking about code

 
mcaesart

I have deleted your topic with the same subject.

 
KristijanO: I am getting a lot of errors … i am getting is unexpected token error.
  1. Don't Hijack other threads for your off-topic post. You are not asking for "coding help." Next time, make your own, new, thread.

  2. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. We can't see your broken code. There is no context for your one line. Your problem is likely above that.

  3. Post all relevant code (like what is above that line line.)
  4. Post the error messages and indicate what line has the error.

  5. How To Ask Questions The Smart Way. 2004
              Prune pointless queries.

 
auto_free_TEAMTRADER:

All symbols are available on my platforms.

Tried it with 3 different renko indicators and on three different platform but still nothing works on renko charts.

All other indicators operate correctly and they are CCI, RSI and stochs.

Has anyone else any suggestions?

TEAMTRADER

Hello Auto_free_Teamleader


I have the same issue , If you have found the solution pls reply

 
Rex Kalist:

Hello Auto_free_Teamleader


I have the same issue , If you have found the solution pls reply

auto_free_TEAMTRADER or Mladen , Pls assist 
 

Hi everyone,

I spent 3 weeks to create a custom indicator but clearly Im not good enough, hoping someone can help.

My indicator take 3 extern: "Timeframe", "number of display level on chart" and "min distance between each level".

All i need to code is to group, remove fractal point within min distance and then display the remaining fractal point level.

The first version(MainRS_AddOn2.mq4) i created do exactly what i want, however i use stupid method by drawing object and keep modify object, the indicator run extremely slow.

The second version(17_8_2020_RS_Indicator.mq4) store all level in buffer which run a lot faster, but i got issues which im not able fix.

----i believe i have logical error in storing new fractal level, which some display level didnt met the min distance requirement and got more duplicate level when run in tester.

  

left side is  17_8_2020_RS_Indicator.mq4, which have duplicated level.

Above is duplicate level inside tester.


 if(modify == false)// store new level when display level limit have no more room
                     {      
                                 if(RSMode[limit]==1)
                                    { 
                                       int index = ArrayMinimum(Display_level,WHOLE_ARRAY,0);
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }  
                                 if(RSMode[limit]==2)
                                    { 
                                       int index = ArrayMaximum(Display_level,WHOLE_ARRAY,0);
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }
                                    
                                  modify =true; 
                                      
                     } 
                 }          

Im thinking the above code may cause the logical error. But nobody can tell unless they willing to spend time to look into whole file.

Appreciate if anyone could help. Below is the complete code, you are welcome to copy and paste or download the attached file.

Many thanks.

//+------------------------------------------------------------------+
//|                                             MainRS_Indicator.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 "Indicator to show Grouped Fractal Support and Resisitance Level"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#define Confirm_Level 3
#define Up_Fractal  1
#define Down_Fractal  2
#define Combined_Up   4
#define Combined_Down  5
 
enum timeframe_display_option
   {
    Current = 0,
    PeriodM5 =5,
    PeriodM15 =15,
    PeriodM30 =30,
    PeriodH1 =60,
    PeriodH4 =240,
    PeriodD1 =1440,
    PeriodW1 =10080,
   };
double RSBuffer1[];//hold new form fractal
double RSMode[];//hold new form fractal status
double Display_level[];// hold fractal display level 
double Display_Mode[];// hold fractal display level status

extern int                       Show_Level_Limit =15;         //Max Level to be display on chart
extern timeframe_display_option  Level_of_TimeFrame=Current; //Option to display which timeframe level on chart
extern double                    sensitvity = 15;     // Min distance between each RS level,input in pips values
int DisplayIndex = 0;


//++++ These are adjusted for 5 digit brokers.
   int     pips2points;    // slippage  3 pips    3=points    30=points
   double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
   int     Digitspips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
   string indId ="SR_";    // string to name object on chart for delete and create object
   double fractal;         // to store fractal point value
   bool modify = false;    // to indicate a existing level on chart being modify or not
   double status;// status of display level, use to reduce and combine level within min distance
   color mark = clrRed;                 

   //--------------------------------------------------
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
                                            
     if (Digits % 2 == 1)
     {      // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                pips2dbl    = Point*10; 
                pips2points = 10;   
                Digitspips = 1;
     } 
     else 
     {   pips2dbl    = Point;    
         pips2points =  1;   
         Digitspips = 0; 
     }
   SetIndexBuffer(0, RSBuffer1);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,251);  //buffer 0 draw line not symbol
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(1, RSMode);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexArrow(1,251);  //buffer 0 draw line not symbol
   SetIndexEmptyValue(1,0.0);
   sensitvity = sensitvity * pips2dbl;// min distance of each display level/fractal point
    return(0);

  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   DeleteAllObjects();
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars > 0)       //---- the last calculated bar will be recalculated   
      counted_bars--;
   int limit = Bars - counted_bars-1;

//-------------------------------------------------------------------------------------------------  
//---- store fractal point to array   
//-------------------------------------------------------------------------------------------------  
   while(limit>0)
   { 
   fractal = iFractals(NULL, Level_of_TimeFrame, MODE_UPPER, limit);
      if(fractal != 0)
     {   
      RSBuffer1[limit]= fractal;
      RSMode[limit]= Up_Fractal;
     }
   fractal = iFractals(NULL, Level_of_TimeFrame, MODE_LOWER, limit);
       if(fractal != 0)
      {
      RSBuffer1[limit]= fractal;
      RSMode[limit]= Down_Fractal;
      }
//-----------------------------------------------------------------------------------------------------------------------------------------------      
//below status for fractal point reduction  
//Confirm_Level 3
//Up_Fractal  1
//Down_Fractal  2
//Combined_Up   4
//Combined_Down  5
//upper fractal point with another upper fractal point == combined up
//lower fractal point with another lower fractal point == combine down
//opposite fractal merge == confirm level (up & down || up & combine down || up && confirm || down & up || down & combine up ||down && confirm)
//--------------------------------------------------------------------------------------------------------------------------------------------------

   ArrayResize(Display_level,Show_Level_Limit+1);
   ArrayResize(Display_Mode,Show_Level_Limit+1);
     if( RSBuffer1[limit]!=0)
     { 
      for (int i=Show_Level_Limit-1;  i>=0; i--)
      {
         double diff = MathAbs(RSBuffer1[limit]-Display_level[i]);// calculate min distance between level
         modify = false;

                  if(diff<=sensitvity )//new fractal, check against Displaylevel
                     {  
                        if(Display_Mode[i]==1&& RSMode[limit] == 1)// 
                           {   
                                 Display_Mode[i]= 4;// mode up & up = combine up
                                 if(RSBuffer1[limit]<Display_level[i])
                                    Display_level[i]=Display_level[i];
                                    
                              Comment(  " Up & Up== " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                           }
                        if(Display_Mode[i]==4 && RSMode[limit] == 1)
                           {
                                    Display_Mode[i]= 4;// mode combine up & up = combine up
                                    if(RSBuffer1[limit]<Display_level[i])
                                       Display_level[i]=Display_level[i];
                              Comment(  " Up & combine Up== "+ Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                           }      
                        if(Display_Mode[i]==2 && RSMode[limit] == 2)
                           {  
                                  Display_Mode[i]= 5;// mode down & down = combine down
                                  if(RSBuffer1[limit]>Display_level[i])
                                    Display_level[i]=Display_level[i];
                              Comment(  "down & down== "+ Display_level[i]+ "Display_Mode = " +Display_Mode[i]); 
                           }
                        if(Display_Mode[i]==5 && RSMode[limit] == 2)
                           {
                                    Display_Mode[i]= 5;// mode down & combine down  = combine down
                                    if(RSBuffer1[limit]>Display_level[i])
                                       Display_level[i]=Display_level[i];
                              Comment(  " Down & combine down== "+ Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                           }   
                         
                     }    

                     if(diff<=sensitvity) 
                     {    
                         
                        if((Display_Mode[i]==2 && RSMode[limit] == 1 )||(Display_Mode[i]==1 && RSMode[limit] == 2  ))
                           {
                               Display_Mode[i]= 3;// mode  up & down & combine down  = confirm 
                                    Display_level[i]=Display_level[i];
                              Comment(  "Up & down or combine down == "+ Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                              modify = true;
                              break;
                           }                          
                         if( (Display_Mode[i]==3 || Display_Mode[i]==5))
                           {
                               Display_Mode[i]= 3;// mode  up & confirm level = confirm 
                               Display_level[i]=Display_level[i];
                              Comment(  "Up & confirm level== "+ Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                              modify = true;
                              break;
                           }
                           
                         if( Display_Mode[i]==3 || Display_Mode[i]==4)
                           {
                               Display_Mode[i]= 3;// mode  down & confirm level = confirm 
                               Display_level[i]=Display_level[i];
                              Comment(  "Down & confirm level== "+ Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                              modify = true;
                              break;
                           }
                           
                     }
                  
       }//end of modify existing level for loop 
                  
                  if(modify == false)// store disply level untill reacah show level limit
                  { 
                     for (int a=0;  a<Show_Level_Limit-1; a++)
                     { 
                        if (Display_Mode[a]==0)
                        {
                           Display_Mode[a]=RSMode[limit];
                           Display_level[a] = RSBuffer1[limit];
                           
                           modify =true;
                           break;
                        } 
                        a++;  
                     }
                 
                  if(modify == false)// store new level when display level limit have no more room
                     {      
                                 if(RSMode[limit]==1)
                                    { 
                                       int index = ArrayMinimum(Display_level,WHOLE_ARRAY,0);
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }  
                                 if(RSMode[limit]==2)
                                    { 
                                       int index = ArrayMaximum(Display_level,WHOLE_ARRAY,0);
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }
                                    
                                  modify =true; 
                                      
                     } 
                 }          
      }

      limit--;
      
   }    
                  DeleteAllObjects();
                 
                  int uplevel=1;
                  int downlevel=1;
                  ArraySort(Display_level,WHOLE_ARRAY,0,MODE_ASCEND);
                  DisplayIndex = 0;
                  for(int a=0;a<ArraySize(Display_level)-1; a++)
                  {
                        if (Display_level[a]<Bid && Display_level[a+1]>Bid)
                           DisplayIndex =a+1;
                  }         

                     for (int c =DisplayIndex ; c<=Show_Level_Limit; c++)
                  {         
                     HLine("SR_RES"+uplevel+ " # " + c, Display_level[c],mark);
                     uplevel++;
                  }   
                     for (int c =DisplayIndex-1 ; c>0; c--)
                  {         
                     HLine("SR_SUP"+downlevel+ " # " + c, Display_level[c],mark);
                     downlevel++;
                  }   

                     

       



return(0);
   } 
void HLine(string name, double P0, color clr)
      {
          #define WINDOW_MAIN 0
    /**/  if (ObjectMove( name, 0, Time[0], P0 )){}
            else if(!ObjectCreate( name, OBJ_HLINE, WINDOW_MAIN, Time[0], P0 ))
                    Alert("ObjectCreate(",name,",HLINE) failed: ", GetLastError() );
          if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
                  Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() );
          if (!ObjectSetText(name, PriceToStr(P0), 10))
                     Alert("ObjectSetText(",name,") [1] failed: ", GetLastError());
}
void DeleteAllObjects()
{
   // Delete all objects created by the indicator
   for (int i = ObjectsTotal() - 1;  i >= 0;  i--)
   {
      string name = ObjectName(i);
      
      if (StringSubstr(name, 0, StringLen(indId)) == indId)
         ObjectDelete(name);
   }
}
 
string  PriceToStr(double p)
   {
    string pFrc = DoubleToStr(p, Digits);       
    if(Digitspips==0) 
      return(pFrc);
    string pPip = DoubleToStr(p, Digits-1);
    if (pPip+"0" == pFrc)       
      return(pPip);           
      return(pFrc);          
   }
//---------------------------------------------------------------------------------------------  
double Price(double Old, double New, int result)//1 return larger value, 2 return smaller value
   { 
   double value=0;
   if(result==1)
   value=MathMax(Old,New);
   if(result==2)
   value=MathMin(Old,New);
   return(value);
   }
//---------------------------------------------------------------------------------------------   


 

 

I do apology if i had Hijack other threads. 

Just hoping someone can help point out the mistake i made inside my code so i can fix my duplicated display level problem.

Many thanks

 
wccmcd:

I'm trying to move from MQL4 to MQL5 but stucked on the first step.  for function iCCI, why there is no "shift" parameter any more? 

Please edit your post and

use the code button (Alt+S) when pasting code

This section is MQL4.

MQL5 you create a handle in OnInit and access the buffer values in the main code.

I suggest that you read the documentation for MQL5

 
Keith Watford:

Please edit your post and

use the code button (Alt+S) when pasting code

This section is MQL4.

MQL5 you create a handle in OnInit and access the buffer values in the main code.

I suggest that you read the documentation for MQL5

Sorry for that. I just realized I'm posting in the wrong place.  Thanks for your reply through. I just deleted it.
 
Hello,
I am just beginner in learning of mql4. I am trying to create a basic supertrend indicator.
I need some expert's help regarding alerts code.


Current Alert Code:
Alert(Symbol() + " (" + Period() + "M) --> " + LSignal + CPri);

Output coming like this:
Symbol Name (15M) --> Buy at 524.55

But, I need stoploss and targets also in the alert based on following simple calculation.

Assume our buy entry at 524.55.

Stoploss : Entry - 1.5% of the stock entry price (524.55 - 7.85 = 516.70)
Target 1 : Entry + 2.5% of the stock entry price (524.55 + 13.10 = 537.65)
Target 2 : Entry + 5% of the stock price (524.55 + 26.20 = 550.75)

(Note: Tick size is 0.05. So if stoploss or target calculation is comes an odd number, need to be rounded to nearest tick size. And if LSignal is a sell signal, need reverse calculation.


Finally I need following output:
Symbol Name (15M) --> Buy at 524.55, SL: 516.70, Target 1: 537.65, Target 2: 550.75


Can somebody please rewrite the code for my requirement?

TY in adv.
Reason: