PDA

View Full Version : Time Frame Expert Advisors, Indicator & Script



aurora
05-30-2014, 01:55 PM
42846

Many traders who already understand the usefulness of the time frame. no other function is an indication that the time to look at the price of close or from afar. to that end, the time frame is very flexible and traders in analyzing the market needs. but what about the EA, can it be done wearing a certain timeframe?

We will discuss what is called a tiime frame. discussion time frame in the end will bring determine how to trade. maybe when we are doing so much browsing on the internet, you find there are a lot of ways traders to trade in different ways and produce different gains.

What causes it? One of the main causes is the Time Frame. Time Frame makes you do a technical analysis with a certain time limit so that ultimately benefit limit (Limit) and limit losses (Stop Loss) to be different.

To facilitate this part, planting only in the minds of the meaning of time itself, ie the time.

Candlestick chart both show fluctuations in the price of a certain period of time called the timeframe. in MetaTrader trading platform, we can choose the timeframe of 1 minute (M1), 5 min (M5), 15 min (M15), 30 min (M30), 1 hour (H1), 4 hours (H4), daily (D1), weekly (W1), and monthly (MN).

If we use the chart timeframe 1 hour (H1), then each bar or candle represents the price movement for an hour . If we peg the 15 -minute timeframe (M15) for example, then each bar or candle represents the price movement for 15 minutes, and so on.

In MQL4 already provided the use of the programming timeframe. so EA will be applied as desired trader. timeframe or time frame chart can also be called the period of the graph. This can be one of the values ​​in the EA :

Constant | | Value | | Description
-------------------------------------------------- --------------------------
PERIOD_M1 | | 1 | | 1 minutes.
PERIOD_M5 | | 5 | | 5 minutes.
PERIOD_M15 | | 15 | | 15 minn.
PERIOD_M30 | | 30 | | 30 min.
PERIOD_H1 | | 60 | | 1 hour.
PERIOD_H4 | | 240 | | 4 hours.
PERIOD_D1 | | 1.440 | | Daily.
PERIOD_W1 | | 10080 | | Weekly.
PERIOD_MN1 | | 43200 | | Monthly.
0 ( zero ) | | 0 | | all

aurora
05-31-2014, 01:15 PM
You can attach your expert advisor to one candle chart to be processed at that timeframe for your MT4, however also easily pull in prices and indicators from timeframes for calculations in your EA. as long as you have date for the timeframes to use, it should also work in trading peformance.

quadsi
05-31-2014, 02:13 PM
You can attach your expert advisor to one candle chart to be processed at that timeframe for your MT4, however also easily pull in prices and indicators from timeframes for calculations in your EA. as long as you have date for the timeframes to use, it should also work in trading peformance.

use time frame for know how the market position adn trend movement is realy help. but for me is newbies that is very hard, so is luck have the time frame robot in here.

aurora
05-31-2014, 03:25 PM
for the newbies better continue learning to become proficient, then thinking to start trading. or if you want to more easily use expeert advisors may can guaranteed to help you.

quadsi
05-31-2014, 03:40 PM
for the newbies better continue learning to become proficient, then thinking to start trading. or if you want to more easily use expeert advisors may can guaranteed to help you.

yeah you right so I want learn mroe from this forum to know how for built a powerfull trading strategy I want created one trading system for increase muy profitable trading opportunites.

aurora
05-31-2014, 03:55 PM
to create a powerfull trading system that is powerfull and guaranteed, requiring an waktud sacrifice for all the training. we have to need practicing to reach a level of expertise.

aurora
06-01-2014, 08:03 AM
Time Period table setting on MQL Scripts

PERIOD_M1 1 1 minute.
PERIOD_M5 5 5 minutes.
PERIOD_M15 15 15 minutes.
PERIOD_M30 30 30 minutes.
PERIOD_H1 60 1 hour.
PERIOD_H4 240 4 hour.
PERIOD_D1 1440 Daily.
PERIOD_W1 10080 Weekly.
PERIOD_MN1 43200 Monthly.

quadsi
06-01-2014, 09:25 AM
Time Period table setting on MQL Scripts

PERIOD_M1 1 1 minute.
PERIOD_M5 5 5 minutes.
PERIOD_M15 15 15 minutes.
PERIOD_M30 30 30 minutes.
PERIOD_H1 60 1 hour.
PERIOD_H4 240 4 hour.
PERIOD_D1 1440 Daily.
PERIOD_W1 10080 Weekly.
PERIOD_MN1 43200 Monthly.


is very hard mathematic calculation, so you can created it now? how much you want take a payment for created the one expert advisors?

aurora
06-02-2014, 10:29 AM
script for the time frame 1 :

extern string TimeFrame = "Current time frame";
extern double Phase = 0;
extern int mode = 1;

aurora
06-03-2014, 01:15 PM
#property copyright ""
#property link "[email protected]"
extern bool trade=true;
extern int barstocount=50;
extern double lots=0.1;
extern int slippage=2;
extern int magicnumber=11;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}

aurora
06-04-2014, 07:07 AM
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(trade==true)
{
static datetime tmp;

if (tmp!= Time[0])
{
tmp = Time[0];

aurora
06-05-2014, 02:31 PM
//M1
double M1_resistance=iCustom(NULL,PERIOD_M1,"!LinRegrBuf","true",barstocount,2,0);
double M1_resistance_p=iCustom(NULL,PERIOD_M1,"!LinRegrBuf","true",barstocount,2,barstocount-1);
double M1_line=iCustom(NULL,PERIOD_M1,"!LinRegrBuf","true",barstocount,0,0);
double M1_support=iCustom(NULL,PERIOD_M1,"!LinRegrBuf","true",barstocount,1,0);
double slopeM1=((M1_resistance-M1_resistance_p)/barstocount)/Point;

//M5
double M5_resistance=iCustom(NULL,PERIOD_M5,"!LinRegrBuf","true",barstocount,2,0);
double M5_resistance_p=iCustom(NULL,PERIOD_M5,"!LinRegrBuf","true",barstocount,2,barstocount-1);
double M5_line=iCustom(NULL,PERIOD_M5,"!LinRegrBuf","true",barstocount,0,0);
double M5_support=iCustom(NULL,PERIOD_M5,"!LinRegrBuf","true",barstocount,1,0);
double slopeM5=((M5_resistance-M5_resistance_p)/barstocount)/Point;

//M15
double M15_resistance=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,2,0);
double M15_resistance_p=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,2,barstocount-1);
double M15_line=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,0,0);
double M15_support=iCustom(NULL,PERIOD_M15,"!LinRegrBuf","true",barstocount,1,0);
double slopeM15=((M15_resistance-M15_resistance_p)/barstocount)/Point;

//M30
double M30_resistance=iCustom(NULL,PERIOD_M30,"!LinRegrBuf","true",barstocount,2,0);
double M30_resistance_p=iCustom(NULL,PERIOD_M30,"!LinRegrBuf","true",barstocount,2,barstocount-1);
double M30_line=iCustom(NULL,PERIOD_M30,"!LinRegrBuf","true",barstocount,0,0);
double M30_support=iCustom(NULL,PERIOD_M30,"!LinRegrBuf","true",barstocount,1,0);
double slopeM30=((M30_resistance-M30_resistance_p)/barstocount)/Point;

aurora
06-09-2014, 01:11 PM
Time formating script

datetime tm=TimeCurrent();
string str1="Date and time with minutes: "+TimeToString(tm);
string str2="Date only: "+TimeToString(tm,TIME_DATE);
string str3="Time with minutes only: "+TimeToString(tm,TIME_MINUTES);
string str4="Time with seconds only: "+TimeToString(tm,TIME_SECONDS);
string str5="Date and time with seconds: "+TimeToString(tm,TIME_DATE|TIME_SECONDS);
//--- output results
Alert(str1);
Alert(str2);
Alert(str3);
Alert(str4);
Alert(str5);

aurora
06-10-2014, 09:55 AM
Timeframes (Method)

int Timeframes() const

bool Timeframes(
int new_timeframes // Visibility flags
)

//--- example for CChartObject::Timeframes
#include <ChartObjects\ChartObject.mqh>
//---
void OnStart()
{
CChartObject object;
//--- get timeframes of chart object
int timeframes=object.Timeframes();
if(!(timeframes&OBJ_PERIOD_H1))
{
//--- set timeframes of chart object
object.Timeframes(timeframes|OBJ_PERIOD_H1);
}
}

aurora
06-11-2014, 10:36 AM
AFL Indicatot Part-1

#property copyright ""
#property link "https://login.mql5.com/en/users/avoitenko"

#property indicator_separate_window
#property indicator_buffers 3
//---
#property indicator_color1 Lime
#property indicator_width1 3
#property indicator_style1 STYLE_SOLID
//---
#property indicator_color2 Red
#property indicator_width2 3
#property indicator_style2 STYLE_SOLID
//---
#property indicator_color3 Black
#property indicator_width3 3
#property indicator_style3 STYLE_SOLID

//--- extern
extern int PERIOD = 10;
extern int AVERAGE = 5;

aurora
06-12-2014, 05:56 AM
AFL Indicatot Part-2

//--- buffers
double ExtHighBuffer[];
double ExtLowBuffer[];
double ExtColorBuffer[];
double cost[];
double pa5[];
double rsv[];
double pak[];
double pad[];

//--- global variables
double pa;
double scost5;
long svolume5;
int w1,w2;
int offset;
double min,max;
ushort periods;
ushort average;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{

aurora
06-12-2014, 03:58 PM
AFL Indicator part 3

{
//--- check input parameters
if(PERIOD < 2) PERIOD = 2;
if(AVERAGE < 2) AVERAGE = 2;
offset = PERIOD + AVERAGE*AVERAGE;

IndicatorBuffers(8);

//--- buffers
SetIndexBuffer(0, BullHBuffer);
SetIndexBuffer(1, BearHBuffer);
SetIndexBuffer(2, ZeroBuffer);
SetIndexBuffer(3, pa);
SetIndexBuffer(4, pa5);
SetIndexBuffer(5, rsv);
SetIndexBuffer(6, pak);
SetIndexBuffer(7, pad);
//---
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
//---
SetIndexLabel(0,"Bull High");
SetIndexLabel(1,"Bear High");
SetIndexLabel(2,"Low");
//---
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
SetIndexEmptyValue(2,0);
//---
IndicatorDigits(2);
IndicatorShortName("Winner (" + PERIOD + ", " + AVERAGE + ") ");
return(0);
}

aurora
06-13-2014, 11:46 AM
AFL Indicator part 4

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit;

if(counted_bars<0)return(0);
if(counted_bars==0)
{
limit= Bars-offset;
ArrayInitialize(BullHBuffer,0);
ArrayInitialize(BearHBuffer,0);
ArrayInitialize(ZeroBuffer,0);
}

aurora
06-13-2014, 04:16 PM
else limit = Bars-counted_bars-1;

//--- main cycle
for(i=limit; i>=0; i--)
{
pa[i] = (2*Close[i]+High[i]+Low[i])/4;

scost5=0;
for(k=0; k < AVERAGE; k++)
scost5 += Volume[i+k]*pa[i+k];

svolume5=0;
for(k=0; k < AVERAGE; k++)
svolume5 += Volume[i+k];

if(svolume5==0)continue;
pa5[i] = scost5/svolume5;

min = LLV(pa5,i,PERIOD);
max = HHV(pa5,i,PERIOD);

rsv[i] = ((pa5[i] - min)/MathMax(max-min,Point))*100;
}

aurora
06-14-2014, 03:38 PM
//--- wma
for(i=limit; i>=0; i--)
pak[i] = iMAOnArray(rsv,0,AVERAGE,0,MODE_LWMA,i);

for(i=limit; i>=0; i--)
pad[i] = iMAOnArray(pak,0,AVERAGE,0,MODE_LWMA,i);

//--- histo
for(i=limit; i>=0; i--)
{
if(pak[i]>pad[i])
{
BullHBuffer[i]=pak[i];
ZeroBuffer[i]=pad[i];
BearHBuffer[i]=0;
}
else
{
BearHBuffer[i]=pad[i];
ZeroBuffer[i]=pak[i];
BullHBuffer[i]=0;
}

aurora
06-15-2014, 01:51 PM
//--- wma
LinearWeightedMAOnBuffer(rates_total,prev_calculated,0,average,rsv,pak,w1);
LinearWeightedMAOnBuffer(rates_total,prev_calculated,0,average,pak,pad,w2);

//--- draw histogram
for(int i=limit; i>=0 && !_StopFlag; i--)
{
ExtHighBuffer[i] = pak[i];
ExtLowBuffer[i] = pad[i];
ExtColorBuffer[i] = 0;
if(pak[i]<pad[i])ExtColorBuffer[i]=1;
}
//---
return(rates_total);
}
//+------------------------------------------------------------------+
//| Sum |
//+------------------------------------------------------------------+
template<typename T>
T Sum(const T &buffer[],uint index,uint count)
{
T sum=0;
int total=ArraySize(buffer);
for(uint i=index; i<fmin(total,index+count); i++)
sum+=buffer[i];
return(sum);
}
//+------------------------------------------------------------------

aurora
06-15-2014, 05:06 PM
cronex chaikin

#property copyright
#property link
//--- indicator version
#property version "1.00"
//--- drawing the indicator in a separate window
#property indicator_separate_window
//--- number of indicator buffers is 2
#property indicator_buffers 2
//--- one plot is used
#property indicator_plots 1
//+-----------------------------------+
//| Parameters of indicator drawing |
//+-----------------------------------+
//--- drawing the indicator as a colored cloud
#property indicator_type1 DRAW_FILLING
//--- the following colors are used as the indicator colors
#property indicator_color1 clrYellowGreen,clrDeepPink
//--- displaying the indicator label
#property indicator_label1 "CronexChaikin"
//+-----------------------------------+
//| Описание класса CXMA |
//+-----------------------------------+
#include <SmoothAlgorithms.mqh>
//+-----------------------------------+
//--- declaration of the CXMA class variables from the SmoothAlgorithms.mqh file
CXMA XMA1,XMA2;
//+-----------------------------------+
//| declaration of enumerations |
//+-----------------------------------+
/*enum Smooth_Method - enumeration is declared in SmoothAlgorithms.mqh
{
MODE_SMA_, // SMA
MODE_EMA_, // EMA
MODE_SMMA_, // SMMA
MODE_LWMA_, // LWMA
MODE_JJMA, // JJMA
MODE_JurX, // JurX
MODE_ParMA, // ParMA
MODE_T3, // T3
MODE_VIDYA, // VIDYA
MODE_AMA, // AMA
}; */
//+-----------------------------------+
//| declaration of constants |
//+-----------------------------------+
#define RESET 0 // The constant for returning the indicator recalculation command to the terminal
//+-----------------------------------+
//| Indicator input parameters |
//+-----------------------------------+
input ENUM_MA_METHOD ChaikinMethod=MODE_SMA; // Chaikin averaging method
input uint ChaikinFastPeriod=3; // Fast period of Chaikin
input uint ChaikinSlowPeriod=10; // Slow period of Chaikin
input Smooth_Method XMA_Method=MODE_SMA; // Method of averaging
input uint FastPeriod=14; // Period of fast averaging
input uint SlowPeriod=25; // Method of the slow averaging
input int XPhase=15; // Smoothing parameter (-100..+100)
input ENUM_APPLIED_VOLUME VolumeType=VOLUME_TICK; // Volume
//+-----------------------------------+
//--- declaration of dynamic arrays that
//--- will be used as indicator buffers
double ExtABuffer[],ExtBBuffer[];
//--- Declaration of integer variables for storing indicator handles
int Ind_Handle;
//--- declaration of integer variables of data starting point
int min_rates_1,min_rates_2,min_rates_total;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{

aurora
06-16-2014, 10:34 AM
wlxBWACsig

#property copyright "Copyright © 2005 Aurora"
#property link
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 HotPink
//---- input parameters
extern int updown=8;
//---- buffers
double BWACup[];
double BWACdown[];
int pos=0;
double AC1,AC2,AC3,AC4,AC5;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,119);
SetIndexBuffer(0,BWACup);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,119);
SetIndexBuffer(1,BWACdown);
SetIndexEmptyValue(1,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int cbars=IndicatorCounted();
if (cbars<0) return(-1);
if (cbars>0) cbars--;
//---- TODO: add your code here
if (cbars > (Bars-40)) pos=(Bars-40);
else pos=cbars;
// pos=10;
while(pos > 0)
{
BWACup[pos]=NULL;
BWACdown[pos]=NULL;
AC1=iAC(NULL,0,pos);
AC2=iAC(NULL,0,pos+1);
AC3=iAC(NULL,0,pos+2);
AC4=iAC(NULL,0,pos+3);
AC5=iAC(NULL,0,pos+4);
//----
if (((AC4>0 && AC3>0 && AC2>0 && AC1>0) && (AC4>AC3 && AC2>AC3 && AC1>AC2)) ||
((AC4<0 && AC3<0 && AC2<0 && AC1>0) && (AC4>AC3 && AC2>AC3 && AC1>AC2)) ||
((AC5<0 && AC4<0 && AC3<0 && AC2<0 && AC1<0) &&
(AC5>AC4 && AC4<AC3 && AC3<AC2 && AC2<AC1)))
BWACup[pos]=(High[pos]+updown*Point) ;
//----
if (((AC4<0 && AC3<0 && AC2<0 && AC1<0) && (AC4<AC3 && AC2<AC3 && AC1<AC2)) ||
((AC4>0 && AC3>0 && AC2>0 && AC1<0) && (AC4<AC3 && AC2<AC3 && AC1<AC2)) ||
((AC5>0 && AC4>0 && AC3>0 && AC2>0 && AC1>0) &&
(AC5<AC4 && AC4>AC3 && AC3>AC2 && AC2>AC1)))
BWACdown[pos]=(Low[pos]-updown*Point);
pos--;
}
return(0);
}
//+------------------------------------------------------------------+---------------------+

aurora
06-16-2014, 02:06 PM
STOP Level MF Indicator part-1

#property copyright "Aura"
#property link

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 Blue
#property indicator_color4 Orange
#property indicator_color5 Orange
#property indicator_color6 Red
#property indicator_color7 Red
//--- input parameters
extern string Timeframe="D";
extern double L1=100.0;
extern double L2=50.0;
extern double L3=0.0;
extern double L4=150.0;
extern double L5=-50.0;
extern double L6=200.0;
extern double L7=-100.0;
//--- buffers
double L1Buffer[];
double L2Buffer[];
double L3Buffer[];
double L4Buffer[];
double L5Buffer[];
double L6Buffer[];
double L7Buffer[];
//-- local vars
double L1v,L2v,L3v,L4v,L5v,L6v,L7v;
double LastHigh,LastLow,R;
bool PeriodBreak,Ready;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{

aurora
06-16-2014, 04:15 PM
part-2

//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,L1Buffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,L2Buffer);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,L3Buffer);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,L4Buffer);
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,L5Buffer);
SetIndexStyle(5,DRAW_LINE);
SetIndexBuffer(5,L6Buffer);
SetIndexStyle(6,DRAW_LINE);
SetIndexBuffer(6,L7Buffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;

if(counted_bars < 0) return(-1);

limit=Bars-counted_bars-1;
if(counted_bars==0) limit-=2;

if(counted_bars==0)
{
LastHigh= High [limit+1];
LastLow = Low [limit+1];
Ready=false;
}

for(i=limit; i>=0; i--)
{
if(High[i+1]>LastHigh)
LastHigh=High[i+1];

if(Low[i+1]<LastLow)
LastLow=Low[i+1];

if(Timeframe=="D")
{
PeriodBreak=TimeDay(Time[i])!=TimeDay(Time[i+1]);
} else if(Timeframe=="W") {
PeriodBreak=TimeDayOfWeek(Time[i])<TimeDayOfWeek(Time[i+1]);
} else if(Timeframe=="M") {
PeriodBreak=TimeMonth(Time[i])!=TimeMonth(Time[i+1]);
} else if(Timeframe=="Q") {
PeriodBreak=MathFloor((TimeMonth(Time[i])-1)/3)!=MathFloor((TimeMonth(Time[i+1])-1)/3);
} else if(Timeframe=="Y") {
PeriodBreak=TimeYear(Time[i])!=TimeYear(Time[i+1]);
} else {
PeriodBreak=false;
}

aurora
06-18-2014, 10:25 AM
part-3

if(PeriodBreak)
{
R=LastHigh-LastLow;
L1v = LastLow + R * L1 / 100;
L2v = LastLow + R * L2 / 100;
L3v = LastLow + R * L3 / 100;
L4v = LastLow + R * L4 / 100;
L5v = LastLow + R * L5 / 100;
L6v = LastLow + R * L6 / 100;
L7v = LastLow + R * L7 / 100;

LastHigh= High [i];
LastLow = Low [i];

Ready=true;
}

if(Ready)
{
L1Buffer[i] = L1v;
L2Buffer[i] = L2v;
L3Buffer[i] = L3v;
L4Buffer[i] = L4v;
L5Buffer[i] = L5v;
L6Buffer[i] = L6v;
L7Buffer[i] = L7v;
}
}

return(0);
}

//+------------------------------------------------------------------+

aurora
06-18-2014, 11:51 AM
HG and Scale representation part-1

#property copyright
#property link
#property version "1.00"
#property strict //--- For compatibility with MT4
#property indicator_chart_window
//---
#property indicator_plots 0

//--- ENUMS
enum ENUM_SCALE_TYPE {DYNAMIC,FIXED};
enum ENUM_INDICATOR_TYPE {SCALE,GRADIENT,HEATMAP};

//--- INPUTS
input string indicatorSettings = "----- Indicator Settings"; // ■ Indicator Management
input ENUM_INDICATOR_TYPE indicatorType = HEATMAP; // Indicator Type

//--- GLOBALS
string marketWatchSymbolsList[];
double percentChange[];
color colorArray[];
//---
int symbolsTotal=0;
//---
MqlRates DailyBar[];
//+------------------------------------------------------------------+
//| Indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if(SymbolsTotal(true)<5)
{
Alert("The minimum number of symbols must be 5 (five).");
return(INIT_PARAMETERS_INCORRECT);
}
//---
EventSetTimer(1);
//---
ArraySetAsSeries(DailyBar,true);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- Delete only what is drawn by your code
deleteScale(symbolsTotal);
ChartRedraw();
}
//+------------------------------------------------------------------+
//| 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 &tickVolume[],
const long &volume[],
const int &spread[])
{

//---
return(rates_total);
}

aurora
06-20-2014, 11:26 AM
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
int currentSymbolsTotal=SymbolsTotal(true);

//--- If we add or remove a symbol to the market watch
if(symbolsTotal!=currentSymbolsTotal)
{
//--- resize arrays
ArrayResize(marketWatchSymbolsList,currentSymbolsTotal);
ArrayResize(percentChange,currentSymbolsTotal);
ArrayResize(colorArray,currentSymbolsTotal);
//--- update arrays of symbol's name
for(int i=0;i<currentSymbolsTotal;i++) marketWatchSymbolsList[i]=SymbolName(i,true);
//--- remove panel in excess
deleteScale(symbolsTotal,currentSymbolsTotal);
//---
symbolsTotal=currentSymbolsTotal;
}

//--- call right drawing function
switch(indicatorType)
{
case SCALE : Scale(); break;
case GRADIENT : Gradient(); break;
case HEATMAP : Heatmap(); break;
}
ChartRedraw();
}
//+------------------------------------------------------------------+
//| SCALE |
//+------------------------------------------------------------------+
void Scale()
{
//--- Variables for the color gradient
int length=SymbolsTotal(true); // Number os symbols on market watch

//--- Set values through for-loop
for(int i=0;i<length;i++)
{
//---
if(CopyRates(marketWatchSymbolsList[i],PERIOD_D1,0,2,DailyBar)!=2)
{
printf("Not all data available yet (%s) !",marketWatchSymbolsList[i]);
return;
}

//--- Color 1 parameters
int r_1 = 0;
int g_1 = 64;
int b_1 = 255;

//--- Color 2 parameters
int r_2 = 255;
int g_2 = 255;
int b_2 = 255;

//--- Interpolation functions
int r_value = r_1-i*((r_1-r_2)/(length-1));
int g_value = g_1-i*((g_1-g_2)/(length-1));
int b_value = b_1-i*((b_1-b_2)/(length-1));

//---
string rgbColor=IntegerToString(r_value)+","+IntegerToString(g_value)+","+IntegerToString(b_value);

//---
colorArray[i]=StringToColor(rgbColor);
marketWatchSymbolsList[i]=SymbolName(i,true);
percentChange[i]=((DailyBar[0].close/DailyBar[1].close)-1)*100;

//--- Texts and boxes
SetPanel("Panel "+IntegerToString(i),0,10,32+i*32,50,30,StringToColor(rgbColor),clrWhite,1);
SetText("Text "+IntegerToString(i),marketWatchSymbolsList[i],13,33+i*32,clrBlack,8);
//---
if(percentChange[i]>=0)
{
SetText("Variation "+IntegerToString(i),"+"+DoubleToString(percentChange[i],2)+"%",17,46+i*32,clrBlack,8);
}
else
{
SetText("Variation "+IntegerToString(i),DoubleToString(percentChange[i],2)+"%",17,46+i*32,clrBlack,8);
}
}

}

aurora
06-20-2014, 02:09 PM
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
int currentSymbolsTotal=SymbolsTotal(true);

//--- If we add or remove a symbol to the market watch
if(symbolsTotal!=currentSymbolsTotal)
{
//--- resize arrays
ArrayResize(marketWatchSymbolsList,currentSymbolsTotal);
ArrayResize(percentChange,currentSymbolsTotal);
ArrayResize(colorArray,currentSymbolsTotal);
//--- update arrays of symbol's name
for(int i=0;i<currentSymbolsTotal;i++) marketWatchSymbolsList[i]=SymbolName(i,true);
//--- remove panel in excess
deleteScale(symbolsTotal,currentSymbolsTotal);
//---
symbolsTotal=currentSymbolsTotal;
}

//--- call right drawing function
switch(indicatorType)
{
case SCALE : Scale(); break;
case GRADIENT : Gradient(); break;
case HEATMAP : Heatmap(); break;
}
ChartRedraw();
}