mikko_painmeter2

Author: Mikko
mikko_painmeter2
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
mikko_painmeter2
//+------------------------------------------------------------------+
//|                                             MinMax indicator     |
//|                                                            Mikko |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Mikko"
#property link      "noneOfYOurBusiness"

#property indicator_separate_window
//#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Gray
#property indicator_color4 White
#property indicator_color5 Yellow
#property indicator_color6 Orange
#property indicator_color7 YellowGreen

double bullPain[];
double bearPain[];
double painDiff[];
double painMA[];
double buy[];
double sell[];
double symmetry[];

extern int ma = 30;
extern int count = 60; 
extern int arrowPeak = 150;
extern int step = 1;
extern int mamode = MODE_LWMA;
extern int symmetryCount = 5;

/*
extern int count2 = 50; 
extern int step2 = 1; 
extern double multiplier2 = 2;

extern int count3 = 100; 
extern int step3 = 1; 
extern int multiplier3 = 3;
*/

int init() {

   IndicatorBuffers(7);

   SetIndexBuffer(0, bullPain);     
   SetIndexStyle(0, DRAW_LINE, EMPTY, 1);

   SetIndexBuffer(1, bearPain);     
   SetIndexStyle(1, DRAW_LINE, EMPTY, 1);
   
   SetIndexBuffer(2, painDiff);     
   SetIndexStyle(2, DRAW_LINE, EMPTY, 1);
   
   SetIndexBuffer(3, painMA);     
   SetIndexStyle(3, DRAW_LINE, EMPTY, 1);

   SetIndexBuffer(4, buy);
   SetIndexStyle(4, DRAW_ARROW, EMPTY, 1); 
   SetIndexArrow(4, SYMBOL_ARROWUP);
   
   SetIndexBuffer(5, sell);
   SetIndexStyle(5, DRAW_ARROW, EMPTY, 1);
   SetIndexArrow(5, SYMBOL_ARROWDOWN);
   
   SetIndexBuffer(6, symmetry);
   SetIndexStyle(6, DRAW_HISTOGRAM, EMPTY, 1);
      
   IndicatorShortName("Mikko PainMeter "+count+"/"+ma);
   
   //SetIndexDrawBegin(0, 0);  
   
   return(0);
}
  
int deinit() {
   return(0);
}
     
int start() {
       
   int counted_bars=IndicatorCounted();
  
   if(counted_bars < 0) 
       return(-1);
   if(counted_bars > 0)  
       counted_bars--;
       
   int limit = Bars - counted_bars;
   double move;
   int j;
   
   for(int i = limit; i >= 0; i--) {
       move = 0;
       bullPain[i] = 0;
       bearPain[i] = 0;
       painMA[i] = 0;
       
       
       int k;
       for(k=0; k<count; k+=step) {
            j = i+k;
              double jval = (High[j]+Low[j]+Close[j]*2)/4;
              double nowval = (High[i]+Low[i]+Close[i]*2)/4;
              
              // volume does not represent deal count!
              double multiplier = 1; 
              
              /** Pain/ecstacy of loss for each step **/
              bullPain[i] += (jval-nowval)*multiplier;              
              bearPain[i] += (nowval-jval)*multiplier;

              /** Pain of gaining something and not cashing at the high point or
                  perfect entry ecstacy **/

               /*   
              int highPos = iHighest(Symbol(),0,MODE_HIGH,k,i);
              int lowPos = iLowest(Symbol(),0,MODE_LOW,k,i);
                                 
              if(High[highPos] > nowval)                            
                  bullPain[i] += High[highPos]-nowval;
                  
              if(Low[lowPos] < nowval)
                  bearPain[i] += nowval-Low[lowPos];
               */
             
           painDiff[i] = bearPain[i]-bullPain[i];

       }         
   }    
   
   for(i=limit; i>=0; i--) {
       painMA[i] = iMAOnArray(painDiff, 0, ma, 0, mamode, i);              

       //Print(painMA[i+1]+"["+i+"]("+arrowPeak+") < "+painMA[ArrayMinimum(painMA, arrowPeak, i+2)]+"["+ArrayMinimum(painMA, arrowPeak, i+2)+"]");

/*
       if(bearPain[i] > bullPain[i] &&
          bearPain[i] < bearPain[i+1] && bearPain[i+1] > bearPain[i+2]) {
          if(bearPain[i+1] > bearPain[ArrayMinimum(bearPain, arrowPeak, i+2)]) 
         {
           buy[i] = bearPain[i];
         }
       }
       if(bearPain[i] < bullPain[i] &&
          bullPain[i] < bullPain[i+1] && bullPain[i+1] > bullPain[i+2]) {
          if(bullPain[i+1] > bullPain[ArrayMaximum(bullPain, arrowPeak, i+2)]) 
         {
           sell[i] = bullPain[i];
         }
       }
*/
    
       
       if(painMA[i] > painMA[i+1] && painMA[i+1] < painMA[i+2]) {
         if(painMA[i+1] < painMA[ArrayMinimum(painMA, arrowPeak, i+2)]) {
           buy[i] = painMA[i];
         }
       }
       if(painMA[i] < painMA[i+1] && painMA[i+1] > painMA[i+2]) {
         if(painMA[i+1] > painMA[ArrayMaximum(painMA, arrowPeak, i+2)]) {
           sell[i] = painMA[i];
         }
       }
      // calculate symmetry for this Point
      symmetry[i] = (painMA[i]-painMA[i+1])*3;
   }

   
   return(0);
}

double dist(double a, double b) {
   if(a > b)
      return(a-b);
   else
      return(b-a);
}

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