PriceTrenderChartTest





//+------------------------------------------------------------------+
//|                                                 PriceTrender.mq4 |
//|                                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Gold
#property indicator_color3 OrangeRed


// Use short MA lengths for testing purposes

extern int TimeFrame = 15,
           Price = 0,
           MaType = 0,
           MaPrice = 0,
           MaLength = 2;
           

double price[], trend[], trend_dir[];
int cur_trend = 0, last_trend = 0;
string trade_direction;
 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
IndicatorBuffers(3);
SetIndexBuffer(0,price);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,0);

SetIndexBuffer(1,trend);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,0);

SetIndexBuffer(2,trend_dir);
SetIndexStyle(2,DRAW_ARROW,0);
SetIndexArrow(2,108);

    
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    limit, bigshift; 
   int    counted_bars=IndicatorCounted(); 
//---- 
   if (counted_bars<0) return(-1); 
   if (counted_bars>0) counted_bars--; 
   limit=Bars-counted_bars; 
   

  
      
// Has trend direction changed?
  if (cur_trend != last_trend)
  {
     if (cur_trend ==1) 
     {
        trend_dir[1] = Low[1]-1*Point;
        trade_direction = "Up cross at price ";
     }   
     else
     {
     trend_dir[1] = High[1]+1*Point;
     trade_direction = "Down cross at price ";
     }
            
    last_trend = cur_trend;
    Comment(trade_direction+iClose(NULL,5,1));  // +Period()+" minute chart.");
   }
   
   
    
   for (int i=limit; i>=0; i--) 
   { 
      bigshift = iBarShift(Symbol(),TimeFrame,Time[i]); 
      price[i] = getPrice(bigshift);
      trend[i] = iMA(Symbol(),TimeFrame,MaLength,0,MaType,MaPrice,bigshift);
   }
   

   // Identify trend direction
   if (price[1] > trend[1])
   {
      cur_trend = 1; 
      // Comment("Trend is up");
   }

   if (price[1] < trend[1])
   {
      cur_trend = -1;
      // Comment("Trend is down");
   }   
       
//---- 
   return(0);
  } 
//+------------------------------------------------------------------+


double getPrice(int shift)
{
   switch(Price)
   {
      case 0 : return ( iClose(Symbol(),TimeFrame,shift) );
      case 1 : return (iOpen(Symbol(),TimeFrame,shift));
      case 2 : return (iHigh(Symbol(),TimeFrame,shift));
      case 3 : return (iLow(Symbol(),TimeFrame,shift));
      case 4 : return ((iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/2);
      case 5 : return ((iClose(Symbol(),TimeFrame,shift)+iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/3);
      case 6 : return ((iOpen(Symbol(),TimeFrame,shift)+iClose(Symbol(),TimeFrame,shift)+iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/4);
   }
}



Sample





Analysis



Market Information Used:

Series array that contains the lowest prices of each bar
Series array that contains the highest prices of each bar
Series array that contains close prices for each bar
Series array that contains open time of each bar
Series array that contains open prices of each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_ARROW

Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: