Author: Copyright � 2010, Ivan Kornilov. All rights reserved.
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
BrakeExp
//+------------------------------------------------------------------+
//|                                   Copyright © 2012, Ivan Kornilov|
//|                                                      BrakeExp.mq4|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Ivan Kornilov. All rights reserved."
#property link "excelf@gmail.com"

//property  indicator_separate_window
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color2 Red
#property indicator_color1 Green

extern double a = 3;
extern double b = 1;

extern bool isLine = false;


double upValue[];
double downValue[];



int init() {
   IndicatorShortName("BrakeExp (" + DoubleToStr(a, 2) + "," + DoubleToStr(b, 2) + " )");
   b = b * Point;
   a = a * 0.1;

   SetIndexBuffer(0, upValue);
   SetIndexLabel(0, "Up Value");
   
   SetIndexBuffer(1, downValue);
   SetIndexLabel(1, "Down Value");
   
   if(isLine) {
      SetIndexStyle(0, DRAW_LINE, EMPTY, 2);
      SetIndexStyle(1, DRAW_LINE, EMPTY, 2);
   } else {
      SetIndexStyle(0, DRAW_ARROW, EMPTY, 2);
      SetIndexArrow(0, 159);
      SetIndexStyle(1, DRAW_ARROW, EMPTY, 2);
      SetIndexArrow(1, 159);
   }
   
   IndicatorDigits(Digits);   
}

double beginPrice = -1;
datetime beginTime = 0;
bool isLong = true;
double maxPrice = -999;
double minPrice = 999;

int start() {
   int indicatorCounted = IndicatorCounted();
   if (indicatorCounted < 0) { 
        return (-1);
   }
   if (indicatorCounted > 0) {
        indicatorCounted--;
   }
   int limit = Bars - indicatorCounted -2;
   for (int i = limit; i >= 0; i--) {
      if(beginPrice == -1) {
         beginPrice = Low[i];
         beginTime = Time[i];
         isLong = true;
         Print("init");
      }
      
      if(maxPrice < High[i]) {
         maxPrice = High[i];
      }
      if(minPrice > Low[i]) {
         minPrice = Low[i];
      }
      double value;
      int beginBar = iBarShift(NULL, 0, beginTime, false);
      double exp = (MathExp((beginBar - i) * a) - 1) * b;
      if(isLong) {
         value = beginPrice + exp;
      } else {
         value = beginPrice - exp;
      }
      if(isLong && value > Low[i]) {
         //upValue[i] = value;   
         isLong = false;
         beginPrice = maxPrice;
         value = beginPrice;
         beginTime = Time[i];
         
         maxPrice = -999;
         minPrice = 999;  
         
      } else if(!isLong && value < High[i]) {
       //  downValue[i] = value;
         isLong = true;
         beginPrice = minPrice;
         value = beginPrice;
         beginTime = Time[i];
         
         maxPrice = -999;
         minPrice = 999;
         
         
      }
      if(isLong) {
         upValue[i] = value;
         downValue[i] = EMPTY_VALUE;
      } else {
         upValue[i] = EMPTY_VALUE;
         downValue[i] = value;
      }
   }
}

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 ---