Author: Victor Nicolaev aka Vinin
returns
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
returns
//+------------------------------------------------------------------+
//|                                                      returns.mq4 |
//|                                                  Victor Nicolaev |
//|                                                    vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Victor Nicolaev aka Vinin"
#property link      "mailto: vinin@mail.ru"

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Maroon
#property indicator_color2 Blue
#property indicator_color3 DarkSlateGray
#property indicator_color4 Red
#property indicator_color5 DodgerBlue
#property indicator_color6 LimeGreen

#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2

#property indicator_level1 0.5
#property indicator_level2 0
#property indicator_level3 -0.5
#property indicator_levelcolor Gray

#property indicator_maximum 1
#property indicator_minimum -1
//---- input parameters

extern int CountBar1= 60;
extern int CountBar2= 240;
extern int CountBar3= 1440;
extern int MACountBar= 12;

//---- buffers
double ExtMapBuffer0[];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
//---- drawing settings
   for (int i=0;i<6;i++) {
      SetIndexStyle(i,DRAW_LINE);
      SetIndexDrawBegin(i,MathMax(CountBar1,MathMax(CountBar2,CountBar3))+MACountBar);
  }
   
      
   SetIndexBuffer(0,ExtMapBuffer0);      
   SetIndexBuffer(1,ExtMapBuffer1);
   SetIndexBuffer(2,ExtMapBuffer2);
   SetIndexBuffer(3,ExtMapBuffer3);
   SetIndexBuffer(4,ExtMapBuffer4);
   SetIndexBuffer(5,ExtMapBuffer5);

   IndicatorShortName("Returns");
   
//---- initialization done
   return(0); }//int init() 
//+------------------------------------------------------------------+
int start() {
   int limit;
   int counted_bars=IndicatorCounted();
   int i;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if (limit>1440) limit = 1440;
   for (i = limit;i>=0;i--){
      ExtMapBuffer0[i] = Value(CountBar1,i);
      ExtMapBuffer1[i] = Value(CountBar2,i);
      ExtMapBuffer2[i] = Value(CountBar3,i);
   }
   for (i = limit;i>=0;i--){
      ExtMapBuffer3[i] = iMAOnArray(ExtMapBuffer0,0,MACountBar,0,MODE_SMA,i);
      ExtMapBuffer4[i] = iMAOnArray(ExtMapBuffer1,0,MACountBar,0,MODE_SMA,i);
      ExtMapBuffer5[i] = iMAOnArray(ExtMapBuffer2,0,MACountBar,0,MODE_SMA,i);
   }



   return(0); 
}// int start()

double Value(int CountBar, int pos) {
   double RetVal=0, tmpHigh, tmpLow;
   tmpHigh=High[iHighest(NULL,0,MODE_HIGH,CountBar,pos)];
   tmpLow=Low[iLowest(NULL,0,MODE_LOW,CountBar,pos)];
   if (tmpHigh>tmpLow) RetVal=((Close[pos]-tmpLow)/(tmpHigh-tmpLow)*2.0-1);
   return(RetVal);
}
   
   

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---