Your ideas to simplify and factorization of code.

 
Hello,

Is an "indicator" that displays parallel closes to close, and parallel highs to high.
No interest as an indicator, I just want to know your ideas for simplifying and factorization code.

Uncoded: How don't display the highs when the timeframe is less than the daily timeframe.

//+------------------------------------------------------------------+
//|                                                   MultiIndic.mq4 |
//|                                         Copyright 2014, Pierre8r |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Pierre8r"
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 12
#property indicator_color1 Red
#property indicator_color2 Tomato
#property indicator_color3 Pink
#property indicator_color4 SpringGreen
#property indicator_color5 LimeGreen
#property indicator_color6 Green
#property indicator_color7 Green
#property indicator_color8 Green
#property indicator_color9 Green
#property indicator_color10 Green
#property indicator_color11 Green
#property indicator_color12 Green

//---- buffers

double Trend_Open01[];
double Trend_Open02[];
double Trend_Open03[];

double Trend_High01[];
double Trend_High02[];
double Trend_High03[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---- indicators

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Trend_Open01);
   SetIndexLabel(0,"Trend_Open01");

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Trend_Open02);
   SetIndexLabel(1,"Trend_Open02");

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Trend_Open03);
   SetIndexLabel(2,"Trend_Open03");

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Trend_High01);
   SetIndexLabel(3,"Trend_High01");

   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,Trend_High02);
   SetIndexLabel(4,"Trend_High02");

   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,Trend_High03);
   SetIndexLabel(5,"Trend_High03");

//---
   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[])
  {
//---

//--- counting from 0 to rates_total
   ArraySetAsSeries(open,false);
   ArraySetAsSeries(high,false);

   ArraySetAsSeries(Trend_Open01,false);
   ArraySetAsSeries(Trend_Open02,false);
   ArraySetAsSeries(Trend_Open03,false);

   ArraySetAsSeries(Trend_High01,false);
   ArraySetAsSeries(Trend_High02,false);
   ArraySetAsSeries(Trend_High03,false);


   int i,limit;
   int Canal =80;

   limit=prev_calculated-1;
   if(limit<0)
     {
      limit=0;
     }

//--- main loop
   for(i=limit; i<rates_total && !IsStopped(); i++)
     {
      Trend_Open01[i]=open[i]+Canal;
      Trend_Open02[i]=open[i]+Canal*2;
      Trend_Open03[i]=open[i]+Canal*3;

      Trend_High01[i]=high[i]+Canal;
      Trend_High02[i]=high[i]+Canal*2;
      Trend_High03[i]=high[i]+Canal*3;

     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

 
I like your code, it is very simple and functional. Thank you very much.

I think what you want is to scale the screen. You can do this with ChartGetInteger and ChartSetInteger commands. They handle everything having to do with windows and subwindows.

There is a long list ENUM_CHART_PROPERTY_INTEGER wherein is included the scaling.

Greetings and I hope I've helped.