Price Cannel Osc Comp.1.2

Author: Copyright 2015, Tor
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Price Cannel Osc Comp.1.2
ÿþ//+------------------------------------------------------------------+

//|                                        Price Cannel Osc Comp.mq4 |

//|                                              Copyright 2015, Tor |

//|                                             http://einvestor.ru/ |

//+------------------------------------------------------------------+

#property copyright "Copyright 2015, Tor"

#property link      "http://einvestor.ru/"

#property version   "1.2"

#property strict

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_plots   3



input int lim=1000;//Bars limit

input string Val="Symbol";//Symbol 1

input string Val2="GBPCAD";//Symbol 2

input int MAPeriod=200;//Price channel period

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

enum TypeGraph

  {

   Lines=0,// Lines

   Delta=1,// Delta

  };

//--- input parameters

input TypeGraph TypeGr=Lines; // Type graph



input bool Alerts = true; // Alerts

input double AlertLevel1 = 60; // Delta level for Alert

input int Shifts = 1; // Candle which look for the signal (0 = current candle)

input bool AlertLevel2 = true; // Cross line Alert



input ENUM_MA_METHOD MAMethod=MODE_EMA;//MA Method

input ENUM_APPLIED_PRICE ApPrice=PRICE_CLOSE;//Applied price

input color clrLine=clrRed;//Color line 1

input color clrLine2=clrBlue;//Color line 2



double delta[],line[],line2[];

string Vals1,Vals2, ExpName = "PCOC_", shortname = "";

static datetime lastAlert = 0, lastAlert2 = 0;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   if(Val=="Symbol" || Val=="")

     {

      Vals1=_Symbol;

     }

   else

     {

      Vals1=Val;

     }

   Vals2=Val2;

   shortname = "Price Channel Osc ("+Vals1+"/"+Vals2+")";

   IndicatorShortName(shortname);

   SetIndexBuffer(0,line);

   SetIndexBuffer(1,line2);

   SetIndexBuffer(2,delta);

   if(TypeGr==0)

     {

      SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,clrLine);

      SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,clrLine2);

      SetIndexStyle(2,DRAW_NONE,STYLE_SOLID,2,clrLine2);

     }

   else

     {

      SetIndexStyle(0,DRAW_NONE,STYLE_SOLID,2,clrLine);

      SetIndexStyle(1,DRAW_NONE,STYLE_SOLID,2,clrLine2);

      SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2,clrLine);

     }



   SetLevelValue(1,0);

   SetLevelValue(2,100);

   IndicatorSetDouble(INDICATOR_MAXIMUM,100);

   if(TypeGr==0)

     {

      SetLevelValue(3,50);

      SetLevelValue(4,20);

      SetLevelValue(5,80);

      IndicatorSetDouble(INDICATOR_MINIMUM,0);

     }

   else

     {

      IndicatorSetDouble(INDICATOR_MINIMUM,-100);

      SetLevelValue(3,-60);

      SetLevelValue(4,60);

      SetLevelValue(5,-80);

      SetLevelValue(6,80);

     }

   SetLevelStyle(STYLE_DOT, 1);

   SetIndexLabel(0,Vals1+" Price");

   SetIndexLabel(1,Vals2+" Price");

   SetIndexLabel(2,"Delta ("+Vals1+"-"+Vals2+")");



   if(Vals1!="")

     {

      ObjectCreate(0,ExpName+"pair1", OBJ_TEXT, ChartWindowFind(0, shortname), Time[0]+Period()*60*5, 0);

      ObjectSetString(0,ExpName+"pair1",OBJPROP_TEXT,Vals1);

      ObjectSetInteger(0,ExpName+"pair1",OBJPROP_FONTSIZE,6);

      ObjectSetInteger(0,ExpName+"pair1",OBJPROP_COLOR, clrLine);

      ObjectSetInteger(0,ExpName+"pair1",OBJPROP_WIDTH,2);

     }

   if(Vals2!="")

     {

      ObjectCreate(0,ExpName+"pair2", OBJ_TEXT, ChartWindowFind(0, shortname), Time[0]+Period()*60*5, 0);

      ObjectSetString(0,ExpName+"pair2",OBJPROP_TEXT,Vals2);

      ObjectSetInteger(0,ExpName+"pair2",OBJPROP_FONTSIZE,6);

      ObjectSetInteger(0,ExpName+"pair2",OBJPROP_COLOR, clrLine2);

      ObjectSetInteger(0,ExpName+"pair2",OBJPROP_WIDTH,2);

     }

//---

   return(INIT_SUCCEEDED);

  }



//+------------------------------------------------------------------+

int deinit()

  {

   ObjectDelete(ExpName+"pair1");

   ObjectDelete(ExpName+"pair2");

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   int limit;

   if(rates_total<=1)

     {

      return(0);

     }

//--- last counted bar will be recounted

   limit=rates_total-prev_calculated;

   if(prev_calculated>0)

      limit=limit+2;



   if(lim>0 && limit>lim)

     {

      limit=lim;

     }



   for(int x=limit-1; x>=0; x--)

     {

      line[x]=EMPTY_VALUE;

      line2[x]=EMPTY_VALUE;

      delta[x]=EMPTY_VALUE;



      line[x]=iCustom(Vals1,_Period,"Price Cannel Osc",Vals1,MAPeriod,0,x);

      line2[x] = iCustom(Vals2,_Period,"Price Cannel Osc",Vals2,MAPeriod,0,x);

      if(TypeGr==1)

        {

         delta[x]=line[x]-line2[x];

        }



     }

   if(Alerts && lastAlert<Time[0])

     {

      if(MathAbs(line[Shifts]-line2[Shifts])>=AlertLevel1)

        {

         Alert(" 074286:0 "+Vals1+" / "+Vals2+" 1>;LH5 "+(string)AlertLevel1);

         lastAlert = Time[0];

        }

     }

   if(Alerts && AlertLevel2 && lastAlert2<Time[0])

     {

      if(((line[Shifts+1]-line2[Shifts+1])>=0 && (line[Shifts]-line2[Shifts])<0)

         || ((line[Shifts+1]-line2[Shifts+1])<=0 && (line[Shifts]-line2[Shifts])>0))

        {

         Alert("@5@5G5=85 "+Vals1+" / "+Vals2+" =0 "+(string)TimeCurrent());

         lastAlert2 = Time[0];

        }

     }

   if(ObjectFind(0,ExpName+"pair1")>0)

     {

      ObjectMove(0,ExpName+"pair1", 0, Time[0]+Period()*60*5, line[0]);

     }

   if(ObjectFind(0,ExpName+"pair2")>0)

     {

      ObjectMove(0,ExpName+"pair2", 0, Time[0]+Period()*60*5, line2[0]);

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments