How Can I Change Line Style In MQL4

 

Hello, I just started learning MQL4 and am doing some small experiments. My request is to draw the line as "Dot" but I couldn't manage to do it. Can you help me with this? 


//+------------------------------------------------------------------+
//|                                                   dotBro.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrWhite
#property indicator_width1 2
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_DASH
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

double buffer[];

int OnInit()
  {
//--- indicator buffers mapping
   
//---
   SetIndexBuffer(0,buffer);
   //SetLevelStyle(0,3);
   SetIndexStyle(0,DRAW_LINE,STYLE_DOT);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
  
   int limit = rates_total - prev_calculated;
   if (prev_calculated>0) limit++;
   
   for(int i=limit-1;i>=0;i--)
     {
      double c = iClose(NULL,0,i);
      double z = iOpen(NULL,0,i);
      if(c>z)
        {
         buffer[i] =  c;
        }
       else
         {
          buffer[i] = EMPTY_VALUE;
         }
     }
   Comment("Rates: " + rates_total + " Prev: " + prev_calculated);
   
  
  
   
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Umut Altındağ: My request is to draw the line as "Dot" but I couldn't manage to do it.
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.

  2. #property indicator_style1 STYLE_DASH
    ⋮
       SetIndexStyle(0,DRAW_LINE,STYLE_DOT);

    Style dot in property or use the function call, not both.

  3. #property indicator_width1 2

    Can't have a width more than one.

 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.

  2. Style dot in property or use the function call, not both.

  3. Can't have a width more than one.


Sorry for my mistake, thank you for your help.


It worked, but it doesn't work in a different script even though I did as you specified.


//+------------------------------------------------------------------+
//|                                                 Trend Ribbon.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 4




double fastMa[];
double slowMa[];
double up[];
double dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexStyle(0,DRAW_LINE,STYLE_DOT,2,clrGreen);
   SetIndexBuffer(0,fastMa);
   SetIndexBuffer(1,slowMa);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT,2,clrRed);
   SetIndexBuffer(2,up);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1,clrGreen);
   SetIndexBuffer(3,dn);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,1,clrRed);
   SetIndexEmptyValue(3,0.0);
   
   //---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
  
  
//---
    int limit = rates_total - prev_calculated;
      if (prev_calculated>0) limit++;
      
      for(int i=limit-1;i>=0;i--)
        {
         
        double fast = iMA(NULL,0,12,0,0,0,i);
        double slow = iMA(NULL,0,20,0,0,0,i);
         fastMa[i] = fast;
         slowMa[i] = slow;
         if(fast>slow)
           {
            up[i] = fast;
           }
         else if(fast<slow)
           {
            dn[i] = slow;
           }
         
        
        
        
        
         }
      
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Umut Altındağ #:


Sorry for my mistake, thank you for your help.


It worked, but it doesn't work in a different script even though I did as you specified.


I got it, thank you for your help