Price Data Components
Miscellaneous
0
Views
0
Downloads
0
Favorites
Ind_Seasonal_Trade
//+------------------------------------------------------------------+
//| Ind_Seasonal+Trade.mq4 |
//| Copyright 2012-2013, Evgeniy Trofimov |
//| http://www.mql4.com/ru/users/EvgeTrofi |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012-2013, Evgeniy Trofimov"
#property link "http://www.mql4.com/ru/users/EvgeTrofi"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Black
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_color3 LimeGreen
#property indicator_color4 MediumBlue
#property indicator_color5 Coral
#property indicator_color6 SaddleBrown
#property indicator_color7 DeepPink
#property indicator_color8 DarkSlateGray
extern string Formula = "PL-GC=2^1"; //Ôîðìóëà êîðçèíû, íàïðèìåð: ÀÀ+ÁÁ-ÑÑ=1^1^2
extern int Future = 50; //Ñäâèã ãðàôèêîâ ïðîøëûõ ëåò
extern int Past = 20; //Ñêîëüêî ñâå÷åé ðèñîâàòü â èñòîðèè
extern int BaseSymbol = 1; //Íîìåð áàçîâîãî èíñòðóìåíòà, ïî êîòîðîìó âû÷èñëÿþòñÿ ïèïñû (øàã öåíû) ïðèáûëè
//0 - ðàñ÷¸ò ýêâèòè ñïðåäà â ïóíêòàõ ïåðâîãî èíñòðóìåíòà
extern int Compress = 40; //Åñëè Compress>0 - âïèñûâàåò ïðîøëûå ãîäà â ñîâðåìåííûé ñïðåä.
//Ïðè ýòîì ïðèáûëè ïðîøëûõ ëåò èñêàæàþòñÿ!!!
//Compress - êîëè÷åñòâî ñâå÷åé ñïðåäà òåêóùåãî ãîäà, ïðèíèìàåìûõ çà îñíîâó.
extern bool Visual = true; //Îòîáðàæåíèå âñïîìîãàòåëüíîé èíôîðìàöèè íà ãðàôèêå
extern string Interval1 = "1-1";
extern string Interval2 = "2-1";
extern string Interval3 = "3-1";
extern string Interval4 = "5-1";
extern string Interval5 = "8-1";
extern string Interval6 = "13-1";
extern string Interval7 = "21-1";
double Buff_line0[];
double Buff_line1[];
double Buff_line2[];
double Buff_line3[];
double Buff_line4[];
double Buff_line5[];
double Buff_line6[];
double Buff_line7[];
string IndicatorName;
string gSymbol[]; //Ðàáî÷èå èíñòðóìåíòû
double gVolume[]; //Ñîîòâåòñòâóþùèå îáú¸ìû (ïîëîæèòåëüíîå çíà÷åíèå - ïîêóïêà, îòðèöàòåëüíîå - ïðîäàæà)
double gK[]; //Êîýôôèöèåíòû îòíîøåíèÿ k = TICKVALUE / TICKSIZE
double gLenta[]; //Âåñü ñïðåä â îäíîì ìàññèâå. Íóëåâîå - ýòî ñàìîå ñòàðîå çíà÷åíèå!
int IntervalBegin[7], IntervalEnd[7]; //Ìàññèâû èíòåðâàëüíûõ çíà÷åíèé
int mper[10]={0,1,5,15,30,60,240,1440,10080,43200};
color mcol[7]={Black,Red,LimeGreen,MediumBlue,Coral,SaddleBrown,DeepPink,DarkSlateGray};
datetime DateBeginSpread; //Äàòà íà÷àëà ñïðåäà
int YearBegin; //Ãîä íà÷àëà ñïðåäà
bool FirstTime = true; //Ïåðâûé çàïóñê
int indexPeriod; //Èíäåêñ ïåðèîäà îòêðûòîãî ãðàôèêà (îò 1 äî 9)
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
IndicatorBuffers(8);
if(BaseSymbol==0){
IndicatorDigits(2);
}else{
IndicatorDigits(0);
}
IndicatorName="Seasonal Trade "+StringUpper(Formula)+" ";
IndicatorShortName(IndicatorName);
int cnt = GlobalInit();
//Print("Âûïîëíåíà îáðàáîòêà ", cnt, " èíñòðóìåíòîâ");
for(int i = 0; i < cnt; i++){
//Print(gSymbol[i], " ", DoubleToStr(gVolume[i], 3));
gK[i] = MarketInfo(gSymbol[i], MODE_TICKVALUE)/MarketInfo(gSymbol[i], MODE_TICKSIZE);
//gVolume[i] = gVolume[i] * MarketInfo(gSymbol[i], MODE_TICKVALUE)/MarketInfo(gSymbol[i], MODE_TICKSIZE);
}
IntervalInput(1, Interval1);IntervalInput(2, Interval2);IntervalInput(3, Interval3);IntervalInput(4, Interval4);IntervalInput(5, Interval5);IntervalInput(6, Interval6);IntervalInput(7, Interval7);
LentaInit();
FirstTime = true;
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0,Buff_line0);
SetIndexLabel(0, DoubleToStr(Year(),0));
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1,Buff_line1);
SetIndexLabel(1, DoubleToStr(IntervalBegin[0],0)+"-"+DoubleToStr(IntervalEnd[0],0));
SetIndexShift(1, Future);
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2,Buff_line2);
SetIndexLabel(2, DoubleToStr(IntervalBegin[1],0)+"-"+DoubleToStr(IntervalEnd[1],0));
SetIndexShift(2, Future);
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(3,Buff_line3);
SetIndexLabel(3, DoubleToStr(IntervalBegin[2],0)+"-"+DoubleToStr(IntervalEnd[2],0));
SetIndexShift(3, Future);
SetIndexStyle(4, DRAW_LINE);
SetIndexBuffer(4,Buff_line4);
SetIndexLabel(4, DoubleToStr(IntervalBegin[3],0)+"-"+DoubleToStr(IntervalEnd[3],0));
SetIndexShift(4, Future);
SetIndexStyle(5, DRAW_LINE);
SetIndexBuffer(5,Buff_line5);
SetIndexLabel(5, DoubleToStr(IntervalBegin[4],0)+"-"+DoubleToStr(IntervalEnd[4],0));
SetIndexShift(5, Future);
SetIndexStyle(6, DRAW_LINE);
SetIndexBuffer(6,Buff_line6);
SetIndexLabel(6, DoubleToStr(IntervalBegin[5],0)+"-"+DoubleToStr(IntervalEnd[5],0));
SetIndexShift(6, Future);
SetIndexStyle(7, DRAW_LINE);
SetIndexBuffer(7,Buff_line7);
SetIndexLabel(7, DoubleToStr(IntervalBegin[6],0)+"-"+DoubleToStr(IntervalEnd[6],0));
SetIndexShift(7, Future);
return(0);
}//init()
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
for(int y=Year(); y>=YearBegin; y--){
ObjectDelete("YearLabel"+y);
}
VisualJalousieDelete();
return(0);
}//deinit()
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start(){
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
datetime t;
double spread;
int i, s;
double max, min;
double Profit;
for (i=0; i<limit; i++) {
t=Time[i];
if(t<DateBeginSpread) break;
spread=0;
for(s=0; s<ArraySize(gSymbol); s++){
Profit = gVolume[s] * gK[s] * GetPrice(gSymbol[s], t, indexPeriod);
spread = spread + Profit;
}//Next s
if(BaseSymbol>0 && BaseSymbol<=ArraySize(gSymbol)){
spread = GetTick(gSymbol[BaseSymbol-1], spread, MathAbs(gVolume[BaseSymbol-1]), gK[BaseSymbol-1]);
}
Buff_line0[i] = spread;
}
VisualCalc();
if(FirstTime){
FirstTime=false;
CreateMiddleSpread(Buff_line1, IntervalBegin[0], IntervalEnd[0]);
CreateMiddleSpread(Buff_line2, IntervalBegin[1], IntervalEnd[1]);
CreateMiddleSpread(Buff_line3, IntervalBegin[2], IntervalEnd[2]);
CreateMiddleSpread(Buff_line4, IntervalBegin[3], IntervalEnd[3]);
CreateMiddleSpread(Buff_line5, IntervalBegin[4], IntervalEnd[4]);
CreateMiddleSpread(Buff_line6, IntervalBegin[5], IntervalEnd[5]);
CreateMiddleSpread(Buff_line7, IntervalBegin[6], IntervalEnd[6]);
if(Compress>0){
Compression(Buff_line0, Buff_line1, Compress);
Compression(Buff_line0, Buff_line2, Compress);
Compression(Buff_line0, Buff_line3, Compress);
Compression(Buff_line0, Buff_line4, Compress);
Compression(Buff_line0, Buff_line5, Compress);
Compression(Buff_line0, Buff_line6, Compress);
Compression(Buff_line0, Buff_line7, Compress);
}
}
return(0);
}//start()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 10.01.2013 |
//| Îïèñàíèå : Âèçóàëüíîå âû÷èñëåíèå ïðèáûëè |
//+----------------------------------------------------------------------------+
void VisualCalc(){
if(!Visual) return;
int hwnd = WindowFind(IndicatorName);
if (ObjectFind("Date1")==-1) ObjectCreate("Date1",OBJ_VLINE,0,Time[Past-1],0);
if (ObjectFind("Date2")==-1) ObjectCreate("Date2",OBJ_VLINE,0,Time[0]+3*60*Period(),0);
datetime BeginTime = MathMin(ObjectGet("Date1", OBJPROP_TIME1), ObjectGet("Date2", OBJPROP_TIME1));
datetime EndTime = MathMax(ObjectGet("Date1", OBJPROP_TIME1), ObjectGet("Date2", OBJPROP_TIME1));
int BeginLenta, EndLenta;
if(BeginTime<=Time[0]) {
BeginLenta = Past-1 - iBarShift(Symbol(), Period(), BeginTime);
}else{
BeginLenta = Past+ (BeginTime-Time[0])/(Period()*60);
}
if(EndTime<=Time[0]) {
EndLenta = Past-1 - iBarShift(Symbol(), Period(), EndTime);
}else{
EndLenta = Past+ (EndTime-Time[0])/(Period()*60);
}
string t;
double Profit;
int i=0;
VisualJalousie(Year()-YearBegin+1, 4);
for(int y=Year(); y>=YearBegin; y--){
t = "YearLabel"+y;
if(ObjectFind(t)==-1){
ObjectCreate(t,OBJ_LABEL,hwnd,0,0);
ObjectSet(t, OBJPROP_XDISTANCE, 4);
ObjectSet(t, OBJPROP_YDISTANCE, 15+i*15);
ObjectSet(t, OBJPROP_COLOR, GetColor(y));
}
if(i==0){
Profit = Buff_line0[iBarShift(Symbol(), Period(), EndTime)]-Buff_line0[iBarShift(Symbol(), Period(), BeginTime)];
ObjectSetText(t, DoubleToStr(Year(),0)+" = "+DoubleToStr(Profit,0),8,"Arial",GetColor(y));
}else{
Profit = gLenta[EndLenta+(Past+Future)*(y-YearBegin)]-
gLenta[BeginLenta+(Past+Future)*(y-YearBegin)];
ObjectSetText(t, DoubleToStr(y,0)+" = "+DoubleToStr(Profit,0),8,"Arial",GetColor(y));
}
i++;
}//Next y
}//VisualCalc()
//+----------------------------------------------------------------------------+
color GetColor(int inYear){
if(inYear==Year()) return(mcol[0]);
for(int i=0; i<7; i++){
if(inYear>=IntervalBegin[i] && inYear<=IntervalEnd[i]){
return(mcol[i+1]);
}
}
return(mcol[0]);
}//GetColor()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 10.01.2013 |
//| Îïèñàíèå : Âðèñîâûâàåò â ãðàôèê A ãðàôèê B |
//| inA - Ìàññèâ ñî çíà÷åíèÿìè ãðàôèêà À (íå èñêàæàåìûé) |
//| outB - Ìàññèâ ñî çíà÷åíèÿìè ãðàôèêà B (èñêàæàåìûé) |
//| inCount - êîëè÷åñòâî çíà÷åíèé â ãðàôèêå À, ê êîòîðûì ïðèâîäÿòñÿ |
//| çíà÷åíèÿ ãðàôèêà B |
//+----------------------------------------------------------------------------+
void Compression(double inA[], double &outB[], int inCount){
double maxA, minA, maxB, minB;
inCount = MathMin(MathMin(ArraySize(inA), ArraySize(outB)), inCount);
maxA = inA[ArrayMaximum(inA, inCount)];
minA = inA[ArrayMinimum(inA, inCount)];
maxB = outB[ArrayMaximum(outB, Past+Future)];
minB = outB[ArrayMinimum(outB, Past+Future)];
for(int i = 0; i<ArraySize(outB); i++){
if(outB[i]==EMPTY_VALUE) continue;
//if((maxB - minB) * (maxA - minA) + minA==0) continue;
outB[i] = (outB[i] - minB) / (maxB - minB) * (maxA - minA) + minA;
}//Next i
}//Compression()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 22.01.2013 |
//| Îïèñàíèå : Âîçâðàùàåò ïðèáûëü â òèêàõ. |
//| inSymbol - ðàñ÷¸òíûé èíñòðóìåíò |
//| inProfit - ïðèáûëü ïî ðàñ÷¸òíîìó èíñòðóìåíòó â âàëþòå äåïîçèòà |
//| inLot - ðàçìåð ñäåëêè â ëîòàõ |
//| inK - êîýôôèöèåíò ïðèáûëüíîñòè èíñòðóìåíòà |
//+----------------------------------------------------------------------------+
double GetTick(string inSymbol, double inProfit, double inLot = 1, double inK = 0){
double res=0;
if(inK==0) inK=MarketInfo(inSymbol, MODE_TICKVALUE)/MarketInfo(inSymbol, MODE_TICKSIZE);
res = inProfit / (inLot * inK); //òóò ïîëó÷àåòñÿ öåíà
res = res / MarketInfo(inSymbol, MODE_TICKSIZE); //òóò - êîëè÷åñòâî òèêîâ
return(res);
}//GetTick()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 22.12.2012 |
//| Îïèñàíèå : Ñîçäà¸ò ìàññèâ outLast, ñîäåðæàùèé ñðåäíèé ñïðåä çà ãîäà, |
//| óêàçàííûå â èíòåðâàëå. Âîçâðàùàåò -1 ïðè íåóäà÷å. |
//| inIntervalB - ãîä íà÷àëà èíòåðâàëà |
//| inIntervalE - ãîä êîíöà èíòåðâàëà |
//+----------------------------------------------------------------------------+
int CreateMiddleSpread(double &outLast[], int inIntervalB, int inIntervalE){
//ArrayResize(outLast, Past+Future);
ArrayInitialize(outLast, EMPTY_VALUE);
if(inIntervalB<YearBegin){
return(-1);
}
int i, j, y;
for(i = 0; i<Past+Future; i++){
j = Past+Future-i-1;
outLast[j] = 0;
for(y = inIntervalB; y <= inIntervalE; y++){
outLast[j] = outLast[j] + gLenta[i+(Past+Future)*(y-YearBegin)];
}//Next y
outLast[j] = outLast[j] / (inIntervalE - inIntervalB + 1);
}//Next i
return(0);
}//CreateMiddleSpread()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 10.01.2013 |
//| Îïèñàíèå : Çàïîëíÿåò ìàññèâ gLenta. Âîçâðàùàåò êîëè÷åñòâî áàðîâ. |
//+----------------------------------------------------------------------------+
int LentaInit(){
//Ðàñ÷¸ò íà÷àëüíîé äàòû
int Total=0;
DateBeginSpread=0;
int Candle=0;
datetime FirstTime = 0;
string minSymbol="";
indexPeriod = GetNumberTimeFrame(Period());
for(int i=0; i<ArraySize(gSymbol); i++){
//Candle = iBars(gSymbol[i], PERIOD_MN1);
FirstTime = ÑàìàÿÑòàðàÿÑâå÷à(gSymbol[i], indexPeriod);
if(FirstTime>DateBeginSpread) {
DateBeginSpread = FirstTime;
minSymbol = gSymbol[i];
}
}
//Ïóñòü íà÷àëüíàÿ äàòà áóäåò ïÿòíèöåé:
FirstTime = DateBeginSpread + 60 * PERIOD_D1 * (5 - TimeDayOfWeek(DateBeginSpread));
if(FirstTime < DateBeginSpread) DateBeginSpread = DateBeginSpread + 60 * PERIOD_D1 * 7;
YearBegin = TimeYear(DateBeginSpread);
if(TimeDayOfYear(DateBeginSpread) > TimeDayOfYear(Time[Past])) YearBegin++;
Print("Íà÷àëüíûé ãîä: "+YearBegin,", íà÷àëüíàÿ äàòà: ", TimeToStr(DateBeginSpread)," ïðèíÿòû ïî ñèìâîëó ", minSymbol);
//Ñîçäàíèå ìàññèâà ñïðåäà
int YearLeft = TimeYear(Time[Past-1]); //íàñòîÿùèé ãîä ñ íà÷àëà çàïðîñà
Total = (Past + Future) * (YearLeft - YearBegin +1);
ArrayResize(gLenta, Total);
i=0;
int k=0, s=0;
string LastDate;
double Profit;
//Ïðè ïåðåõîäå òåêóùåãî äèàïàçîíà ÷åðåç 1 ÿíâàðÿ äîëæíà ïðîèñõîäèòü ñìåíà ãîäà!
int YearCurrent = 0, YearLast=0;
if(YearLeft<TimeYear(Time[0])) YearBegin++;
for(int j = YearBegin; j <= YearLeft; j++){
YearCurrent = j;
if(YearLeft<TimeYear(Time[0])) YearCurrent--;
YearLast = YearLeft;
for(k = Past-1; k >= -Future; k--){
if(k>=0){
if(YearLast!=TimeYear(Time[k])) {
YearCurrent=YearCurrent+1;
YearLast = TimeYear(Time[k]);
//Print(YearCurrent, " ãîä ñâå÷è ", k, " = ", TimeYear(Time[k]));
}
LastDate = DoubleToStr(YearCurrent,0)+"."+DoubleToStr(TimeMonth(Time[k]),0)+"."+DoubleToStr(TimeDay(Time[k]),0)+
" "+DoubleToStr(TimeHour(Time[k]),0)+":"+DoubleToStr(TimeMinute(Time[k]),0);
}else{
if(YearLast!=TimeYear(Time[0]-k*Period()*60)) {
YearCurrent=YearCurrent+1;
YearLast = TimeYear(Time[0]-k*Period()*60);
//Print(YearCurrent, " ãîä ñâå÷è ", k, " = ", TimeYear(Time[0]-k*Period()*60));
}
LastDate = DoubleToStr(YearCurrent,0)+"."+DoubleToStr(TimeMonth(Time[0]-k*Period()*60),0)+"."+DoubleToStr(TimeDay(Time[0]-k*Period()*60),0)+
" "+DoubleToStr(TimeHour(Time[0]-k*Period()*60),0)+":"+DoubleToStr(TimeMinute(Time[0]-k*Period()*60),0);
}
for(s=0; s<ArraySize(gSymbol); s++){
Profit = gVolume[s] * gK[s] * GetPrice(gSymbol[s], StrToTime(LastDate), indexPeriod);
gLenta[i] = gLenta[i] + Profit;
}//Next s
if(BaseSymbol>0 && BaseSymbol<=ArraySize(gSymbol))
gLenta[i] = GetTick(gSymbol[BaseSymbol-1], gLenta[i], MathAbs(gVolume[BaseSymbol-1]), gK[BaseSymbol-1]);
i++;
}//Next k
}//Next j
//Print("Çàïîëíåíî ", i , " ïîçèöèé. Ïëàíèðîâàëîñü çàïîëíèòü: ", Total);
return(Total);
}//LentaInit()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 18.12.2012 |
//| Îïèñàíèå : Âîçâðàùàåò çíà÷åíèå öåíû Close äëÿ çàäàííîãî âðåìåíè.  ñëó÷àå |
//| åñëè óêàçàííàÿ äàòà íå äîñòóïíà, òî òàéìôðåéì ïîâûøàåòñÿ äî |
//| òåõ ïîð ïîêà öåíà íå áóäåò äîñòóïíà äëÿ èíòåðïîëÿöèè. |
//|  ñëó÷àå íåóäà÷è - âîçâðàùàåò -1 |
//| inSymbol - íàèìåíîâàíèå èíñòðóìåíòà |
//| inDate - äàòà, äëÿ ðàñ÷¸òà öåíû |
//| inTimeFrame - íà÷àëüíûé íîìåð òàéìôðåéìà (îò 1 äî 9) |
//+----------------------------------------------------------------------------+
double GetPrice(string inSymbol, datetime inDate, int inTimeFrame=1){
double res=-1;
datetime timeA, timeB;
double priceC, priceD;
int Candle=0;
timeA = ÑàìàÿÑòàðàÿÑâå÷à(inSymbol, inTimeFrame);
if(timeA>inDate){
Print("Îøèáêà! Ïðåäïðèíÿòà ïîïûòêà çàïðîñà öåíû èíñòðóìåíòà ",inSymbol,
" çà ", TimeToStr(inDate), "! Îäíàêî, ñàìàÿ ñòàðàÿ ñâå÷à ", TimeToStr(timeA));
return(-1);
}
Candle = iBarShift(inSymbol, mper[inTimeFrame], inDate);
datetime ResultTime = iTime(inSymbol, mper[inTimeFrame], Candle);
if(ResultTime>inDate){
if(inTimeFrame == 9) return(-1);
res = GetPrice(inSymbol, inDate, inTimeFrame+1);
}else{
timeA = ResultTime;
priceC = iClose(inSymbol, mper[inTimeFrame], Candle);
timeB = timeA;
while(timeB==timeA && Candle>0){
Candle--;
timeB = iTime(inSymbol, mper[inTimeFrame], Candle);
}
if(timeB-timeA==0) return(priceC);
priceD = iClose(inSymbol, mper[inTimeFrame], Candle);
res = priceD - (timeB - inDate) * (priceD - priceC) / (timeB - timeA);
}
return(res);
}//GetPrice()
//+----------------------------------------------------------------------------+
datetime ÑàìàÿÑòàðàÿÑâå÷à(string inSymbol, int inTimeFrame=1){
datetime res=0, t=0;
int Candle=0;
for(int i = inTimeFrame; i<10; i++){
Candle = iBars(inSymbol, mper[i]);
t=iTime(inSymbol, mper[i], Candle-1);
if(t<res || res==0){
res=t;
// }else{
// break;
}
}
return(res);
}//ÑàìàÿÑòàðàÿÑâå÷à()
//+----------------------------------------------------------------------------+
int GetNumberTimeFrame(int inPeriod){
for(int i = 8; i>=0; i--){
if(inPeriod>mper[i]){
return(i+1);
}
}
return(0);
}//GetNumberTimeFrame()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 18.12.2012 |
//| Îïèñàíèå : Çàïîëíÿåò ìàññèâû IntervalBegin[], IntervalEnd[]. |
//| inNum - íîìåð ëèíèè áóôåðà èíäèêàòîðà |
//| inInterval - ñòðîêà ñ óêàçàíèåì äèàïàçîíà ëåò èëè îäíîãî ãîäà |
//+----------------------------------------------------------------------------+
void IntervalInput(int inNum, string inInterval=""){
if(StringLen(inInterval)==0) return;
int pos = StringFind(inInterval, "-");
if(pos>0){
IntervalBegin[inNum-1] = Year() - MathAbs(StrToDouble(StringSubstr(inInterval, 0, pos)));
IntervalEnd[inNum-1] = Year() - MathAbs(StrToDouble(StringSubstr(inInterval, pos+1)));
}else{
IntervalBegin[inNum-1] = Year() - MathAbs(StrToDouble(inInterval));
IntervalEnd[inNum-1] = Year() - IntervalBegin[inNum-1];
}
}//IntervalInput()
//+----------------------------------------------------------------------------+
//| Àâòîð : Åâãåíèé Òðîôèìîâ (EvgeTrofi) |
//+----------------------------------------------------------------------------+
//| Âåðñèÿ : 17.12.2012 |
//| Îïèñàíèå : Çàïîëíÿåò ìàññèâû gSymbol è gVolume. |
//| Âîçâðàùàåò êîëè÷åñòâî îáðàáîòàííûõ èíñòðóìåíòîâ. |
//+----------------------------------------------------------------------------+
int GlobalInit(){
int Total=0, pos1=0, pos2=0;
int pos=StringFind(Formula, "=");
string sLeft = "", sRight = "";
if(pos>0){//Åñëè çíàê ðàâåíñòâà åñòü
sLeft = StringSubstr(Formula, 0, pos);
sRight = StringSubstr(Formula, pos+1);
}else{//Åñëè çíàêà ðàâåíñòâà íåò
sLeft = Formula;
sRight = "";
}
int length=StringLen(sLeft);
while (pos2<length){
Total++;
ArrayResize(gSymbol,Total);
ArrayResize(gVolume,Total+1);
ArrayResize(gK, Total);
int char=0;
if(Total==1){
char=StringGetChar(sLeft, 0);
if(char==43){
gVolume[0]=1;
pos2++;
}else if(char==45){
gVolume[0]=-1;
pos2++;
}else{
gVolume[0]=1;
}
}
pos1=pos2;
char=0;
while (char!=43 && char!=45){ //íå ïëþñ è íå ìèíóñ
pos2++;
char = StringGetChar(sLeft, pos2);
if ((length-1)<pos2) break;
}
if(char==43){ //ïëþñ
gVolume[Total]=1;
}else if(char==45){ //ìèíóñ
gVolume[Total]=-1;
}
gSymbol[Total-1] = StringUpper(StringSubstr(sLeft, pos1, pos2-pos1));
pos2++;
}
ArrayResize(gVolume, Total);
if(StringLen(sRight)==0) return(Total);
pos=0;
pos1=0;
pos2=StringFind(sRight, "^");
while(pos2>=0){
gVolume[pos] = gVolume[pos] * StrToDouble(StringSubstr(sRight, pos1, pos2-pos1));
pos1 = pos2 + 1;
pos2 = StringFind(sRight, "^", pos1);
pos++;
}
gVolume[pos] = gVolume[pos] * StrToDouble(StringSubstr(sRight, pos1));
return(Total);
}//GlobalInit()
//+----------------------------------------------------------------------------+
// Ïåðåâîäèì ñòðîêó â âåðõíèé ðåãèñòð
string StringUpper(string s) {
int c, i, k=StringLen(s), n;
for (i=0; i<k; i++) {
n=0;
c=StringGetChar(s, i);
if (c>96 && c<123) n=c-32; // a-z -> A-Z
if (c>223 && c<256) n=c-32; // à-ÿ -> À-ß
if (c==184) n=168; // ¸ -> ¨
if (n>0) s=StringSetChar(s, i, n);
}
return(s);
}//StringUpper()
//+----------------------------------------------------------------------------+
void VisualJalousie(int inRows, int inColumns, int inSize=25, color inColor = White){
//Ñîçäàíèå æàëþçè
string JName;
int hwnd = WindowFind(IndicatorName);
for(int i=0; i<inRows; i++){
for(int j=0; j<inColumns; j++){
JName = "jalousie"+i+j;
ObjectCreate(JName, OBJ_LABEL, hwnd, 0, 0);
ObjectSet(JName, OBJPROP_CORNER, 0);
ObjectSet(JName, OBJPROP_XDISTANCE, 0.6*inSize*j);
ObjectSet(JName, OBJPROP_YDISTANCE, 8+0.6*inSize*i);
ObjectSet(JName, OBJPROP_BACK, 0);
ObjectSet(JName, OBJPROP_COLOR, inColor);
ObjectSetText(JName, "n", inSize, "Wingdings");
}
}
}//VisualJalousie()
//+----------------------------------------------------------------------------+
void VisualJalousieDelete(){
string JName;
for(int i=0; i<100; i++){
for(int j=0; j<100; j++){
JName = "jalousie"+i+j;
if(ObjectFind(JName)>-1) ObjectDelete(JName);
}
}
}//VisualJalousie()
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---