PAMA GannGrid_indv4.3 //+------------------------------------------------------------------+ //| PAMA GannGrid_indv4.3.mq4 | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010.01.

24, SwingMan" #property link "" /*+------------------------------------------------------------------+ v 4.1 draw trading lines v 4.3 text shift for values //+-----------------------------------------------------------------*/ string sIndicatorName = "PAMA GannGrid_indv4.3"; //---- window bool Draw_InMainWindow = true; //set this parameter! //#property indicator_separate_window #property indicator_chart_window #property indicator_buffers 8 #property #property #property #property #property #property #property #property #property #property #property #property #property #property #property #property indicator_color1 indicator_color2 indicator_color3 indicator_color4 indicator_color5 indicator_color6 indicator_color7 indicator_color8 indicator_width1 indicator_width2 indicator_width3 indicator_width4 indicator_width5 indicator_width6 indicator_width7 indicator_width8 Black //price line Red //price dots Silver //max,min; identical with MainGrid_Color Silver LimeGreen //up arrow Black //up line Red //dn arrow Red //dn line 1 1 1 1 2 2 2 2 //price line //price dots //max,min; identical with MainGrid_Color // //up arrow //up line //dn arrow //dn line

#property indicator_style3 STYLE_SOLID #property indicator_style4 STYLE_SOLID //---- extern inputs //+------------------------------------------------------------------+ extern string ____GridBegin____ = ""; extern bool UseBeginDate = false; //extern string BeginDate = "2010.01.21"; //extern string BeginDate = "2009.11.01"; extern string BeginDate = "2010.01.01 00:00"; extern int nBarsBack = 120;//250; Page 1

extern int MainGrid_Width = 1. MaxPriceLine[]. thisTime. extern color GannGrid_Color = Silver.indicator (Draw_InMainWindow = true) extern bool Show_GridMatrix = true. MinPriceLine[].//Gray. //default=35(!) extern double GannGrid_Interval = 8. //extern bool Show_GannGrid = true.if (Draw_InMainWindow == true) extern int GannGrid_Style = STYLE_DOT. extern string ____GannGrid____ = "". extern int GannGrid_Width = 1.//Green. string sWindowName.0. //---. //---. Page 2 . extern int Price_Mode = 5. upLine[].3 extern string prices = "0=close.if (Draw_InMainWindow == false) //extern int GannGrid_Style = STYLE_SOLID. extern string ____MainGrid____ = "".variables int iWindow.oscillator (Draw_InMainWindow = false) //extern bool Show_GridMatrix = true. 4=median. 5=typical". //default=35(!) //double GannGrid_Interval = 8. //-. dnLine[]. and 9 is too large extern int Text_Shift = 50. extern bool Show_Comments = false. oldTime. extern color MainGrid_Color = Silver.5 is the time interval not OK. extern bool Show_HiloArrows = true. extern bool Draw_AdditionalGrids = false. extern int MainGrid_Style = STYLE_DOT.//with default 8.0. dotPrice[].default input parameters //string ____DefaultGridInterval____ = "". //+------------------------------------------------------------------+ //---. upArrow[]. extern bool Show_PriceArrows = false. extern bool Show_GannGrid = true.//Sienna.5 is the time interval not OK. extern int MainGrid_Intervals = 36. //int MainGrid_Intervals = 36. dnArrow[]. extern string ____Default_GridParameters____ = "Recomanded GridInterval 35 or 36".PAMA GannGrid_indv4. extern int fontSize = 8. //-. extern bool Draw_AllGrids = false. and 9 is too large //---double double double buffers price[]. extern int MinMaxGrid_Style = STYLE_SOLID.//with default 8. datetime firstTime. //---.

SetIndexBuffer(1.MainGrid_Width."maxPrice")."minPrice"). iHalfInterval. SetIndexBuffer(4. //---string sName = sIndicatorName + " ".DRAW_ARROW).indicators SetIndexBuffer(0.EMPTY_VALUE). SetIndexBuffer(5.DRAW_LINE). SetIndexStyle(3.241)."dnLine"). SetIndexBuffer(2. gridStep. //#################################################################### //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---.MainGrid_Color). SetIndexStyle(5. IndicatorShortName(sWindowName). //---. SetIndexBuffer(6. SetIndexLabel(5. datetime maxPriceTime. int nMainGrid_Intervals. sWindowName = sName+sPrice. SetIndexLabel(1.NULL).DRAW_ARROW). bool UseBeginDateOriginal. SetIndexLabel(7.MainGrid_Width. SetIndexStyle(0.242). SetIndexStyle(2. SetIndexLabel(6.price).dnArrow). SetIndexLabel(3. if (Price_Mode == 0) string sPrice = "(ClosePrices) ". SetIndexStyle(7. SetIndexArrow(4.NULL). SetIndexStyle(6. SetIndexLabel(0."upLine").initialisations if (UseBeginDate == true) { firstTime = StrToTime(BeginDate + " 00:00"). SetIndexArrow(6.DRAW_LINE.MaxPriceLine).MinMaxGrid_Style.dnLine).DRAW_LINE. SetIndexStyle(4. else if (Price_Mode == 4) sPrice = "(MedianPrices) ". SetIndexLabel(4. SetIndexStyle(1.upArrow)."PAMA Price").dotPrice). nBarsBack = 0.159). IndicatorDigits(Digits). SetIndexLabel(2. minPriceTime.MinMaxGrid_Style.NULL).DRAW_LINE). //---SetIndexEmptyValue(7. minPrice.DRAW_ARROW). Page 3 . int nDigits. double maxPrice. SetIndexBuffer(7. SetIndexArrow(1.upLine).MinPriceLine). SetIndexBuffer(3.3 bool bGridOK = false.MainGrid_Color). int iGannGrid_Interval.PAMA GannGrid_indv4. else if (Price_Mode == 5) sPrice = "(TypicalPrices) ".DRAW_LINE).

iHalfInterval = iGannGrid_Interval / 2. i++) { upArrow[i] = EMPTY_VALUE. nMainGrid_Intervals = MainGrid_Intervals. MaxPriceLine[i] = EMPTY_VALUE.MODE_DIGITS). if (Show_Comments) Comment(""). bGridOK = false.window if (Draw_InMainWindow) iWindow = 0.PAMA GannGrid_indv4. dnLine[i] = EMPTY_VALUE. iGannGrid_Interval = GannGrid_Interval. double dPrice. else iWindow = WindowFind(sWindowName). } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { Delete_GannObjects(). MinPriceLine[i] = EMPTY_VALUE.3 } else firstTime = 0. nDigits = MarketInfo(Symbol(). //---return(0). } //#################################################################### //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //datetime testTime1=TimeCurrent(). UseBeginDateOriginal = UseBeginDate. for (int i=0. //---. dnArrow[i] = EMPTY_VALUE. i<nBarsBack+20. upLine[i] = EMPTY_VALUE. } //---return(0). if (nDigits == 5 || nDigits == 3) nDigits--. Page 4 .

limit = thisBarShift. dotPrice[i] = dPrice. Delete_GannObjects(). i<limit. 0).3 if (Draw_InMainWindow==false) if (iWindow < 1) iWindow = WindowFind(sWindowName). if (thisTime != oldTime) { oldTime = thisTime.first min.PAMA GannGrid_indv4.max prices //================================================================ for(int i=0. } } //---. if (bGridOK == false) { //---.Date after first calculation { nBarsBack = 0. if(counted_bars>0) counted_bars--. i++) { dPrice = CurrentPrice(Price_Mode. } //---. if ( (UseBeginDate == false && firstTime != 0) || //-. UseBeginDate = true. int counted_bars=IndicatorCounted(). maxPriceTime = Time[0].draw prices.max prices if (bGridOK == false) { dPrice = CurrentPrice(Price_Mode. //---. caculate min. //firstTime is now allowable for nBarsBack int thisBarShift = iBarShift(Symbol().nBarsBack after first calculation (UseBeginDate == true && limit < 4) ) //-. minPrice = dPrice. price[i] = dPrice. minPriceTime = Time[0]. maxPrice = dPrice. int limit = Bars-counted_bars.Period().check newBar thisTime = Time[0].use fix date as begin if (UseBeginDate == true) Page 5 . if(counted_bars<0) return(-1). i). bGridOK = false.false).firstTime.

} nBarsBack++.dummy lines for uper and lower prices for(i=0.use nBarsBack as begin if (UseBeginDate == false) { if (i < nBarsBack) { if (dPrice > maxPrice) {maxPrice = dPrice.// . } //---. gridStep = NormalizeDouble(diffMinMax / nMainGrid_Intervals.iHalfInterval *gridStep. Write_PriceValue(minPrice).minPrice. i++) { MaxPriceLine[i] = maxPrice. i<limit.} if (dPrice < minPrice) {minPrice = dPrice.} firstTime = Time[i].Digits).write matrix data Page 6 . minPriceTime = Time[i]. } } else //---.PAMA GannGrid_indv4. maxPriceTime = Time[i]. minPriceTime = Time[i].adjust nBarsBack if (UseBeginDate == true) nBarsBack++. //---. Write_PriceValue(maxPrice). } } } } //---.// + iHalfInterval *gridStep.calculate data for MainGrid if (bGridOK == false) { double diffMinMax = maxPrice .draw matrix and GannGrid //=================================================================== if (bGridOK == false) { //---. } //-.} if (dPrice < minPrice) {minPrice = dPrice. maxPriceTime = Time[i].3 { if (Time[i] > firstTime) { if (dPrice > maxPrice) {maxPrice = dPrice. MinPriceLine[i] = minPrice.

st = st + "mainStep= " + DoubleToStr(gridStep*iHalfInterval. k++) Draw_HorizontalLine(maxPrice+k*gridStep). st = st + "GridStep= " + DoubleToStr(gridStep.additional grids if (Show_GridMatrix == true) if (Draw_AdditionalGrids) { for (int k=1. if (Show_Comments) Comment(st). string sMaxPriceTime = " (" + TimeToStr(maxPriceTime) + ")". k++) //k=2 for 35 Page 7 .3 string st.Digits) + sMinPriceTime + "\n".PAMA GannGrid_indv4. st = st + "nBarsBack= " + nBarsBack + "\n". //nMainGrid_Intervals+1 for 35 if (Show_GridMatrix == true) for (i=1. double gridPerc= percent / nMainGrid_Intervals. if (UseBeginDateOriginal) string sBegin = " (Date)". else { if (MathMod(i.2) + " % )".write price values if (MathMod(i. } //-. st = st + "minPrice= " + DoubleToStr(minPrice. string sGridPercent = " ( " + DoubleToStr(gridPerc. double percent = 100.i*gridStep). st = st + "maxPrice= " + DoubleToStr(maxPrice.2) + " %\n". else nMainGrids = nMainGrid_Intervals+1.iHalfInterval) == 0) Draw_HorizontalLine(maxPrice .Digits) + sMaxPriceTime + "\n". k<=iHalfInterval. else sBegin = " (nBars)". i<nMainGrids.draw horizontal lines (35+1=36 HLines) ---------------------if (MainGrid_Intervals == 36) int nMainGrids = nMainGrid_Intervals. i++) { if (Draw_AllGrids == true) Draw_HorizontalLine(maxPrice .TIME_DATE|TIME_MINUTES) + sBegin + "\n". for (k=1.Digits) + sGridPercent + "\n". st = st + "Percent= " + DoubleToStr(percent. } //---.Digits) + sGridStep + "\n". k<=iHalfInterval.0 *( maxPrice . st = st + "** " + sIndicatorName + " ** " + "\n".i*gridStep). st = st + "GridBegin: " + TimeToStr(firstTime.i*gridStep). //---.iHalfInterval) == 0) Write_PriceValue(maxPrice . string sMinPriceTime = " (" + TimeToStr(minPriceTime) + ")".minPrice) / minPrice. string sGridStep = " (" + iHalfInterval + " GridSteps)".

double price1 = maxPrice. price1.price2).i * iHalfInterval. else dTime = Time[0].minPrice.PAMA GannGrid_indv4.draw vertical lines -----------------------------------------if (Show_GridMatrix == true) for (i=0. } //+------------------------------------------------------------------+ //___________________________________________________________________ void Draw_TradingLines() { //int xStep=0. //datetime testTime2=TimeCurrent().draw trading lines ------------------------------------------Draw_TradingLines().maxPrice). datetime time2 = Time[nBarsBack-iHalfInterval-1]. i++) { if (Draw_AllGrids == true) int j = i. Draw_VerticalLine(dTime. return(0). if (j>0) datetime dTime = Time[j]. // xStep++. else j = (nBarsBack-1) . double lineValue. } } //---bGridOK = true.//minPrice-gridStep for 35 } //---. Page 8 . } //---. //==== draw GannGrid lines (angle 45°) ============================== if (Show_GannGrid) { datetime time1 = Time[nBarsBack-1]. int iTrend. double price2 = maxPrice .3 Draw_HorizontalLine(minPrice-k*gridStep).testTime1.iHalfInterval*gridStep. Draw_GannGrid(time1.TimeToStr(testTime2 .time2.TIME_MINUTES|TIME_SECONDS)). i<nBarsBack. //if (Symbol() == "EURUSD" && Period() == PERIOD_M5) // Print("### ".

i>=0. lineValue = firstPriceValue + iGannGrid_Interval*gridStep. lineValue). else lineValue = lineValue + gridStep.main loop //================================================================ for (int i=nBarsBack-2.iGannGrid_Interval*gridStep > lineValue + gridStep) lineValue = price[i] .down trend (red line) ---------------------------------Page 9 . Set_DnLineValue(iFirstBar. lineValue).3 int iFirstBar = nBarsBack-1.first value ----------------------------------------------//---. } //---.iGannGrid_Interval*gridStep. if (Show_PriceArrows) dnArrow[i] = price[i]. } else //---. Set_UpLineValue(i.reverse from up-trend / down-trend if (price[i] < lineValue) { iTrend = -1. lineValue). double firstPriceValue = price[iFirstBar]. //---. } } else //---.iGannGrid_Interval*gridStep. lineValue). i--) { //---. double diffBegin = price[iFirstBar] . Set_UpLineValue(iFirstBar. //---. iTrend).translate up linie if (price[i] . if (Show_HiloArrows) Show_SignalArrows(i. Set_DnLineValue(i.low at begin { iTrend = -1.PAMA GannGrid_indv4. lineValue = firstPriceValue .up trend (blue line) ----------------------------------if (iTrend == 1) { //---. lineValue = price[i] + iGannGrid_Interval*gridStep.high at begin if (diffBegin >= 0) { iTrend = 1.price[iFirstBar+1].

if (Show_PriceArrows) upArrow[i] = price[i]. double dValue) { if (dValue >= MinPriceLine[iBar]-gridStep && dValue <= MaxPriceLine[iBar]+gridStep) { upLine[iBar] = dValue. } //___________________________________________________________________ void Set_DnLineValue(int iBar.PAMA GannGrid_indv4. return. lineValue). } //___________________________________________________________________ void Set_UpLineValue(int iBar. } } } return. } Page 10 . //---.gridStep.3 if (iTrend == -1) { //---. return. } else dnLine[iBar] = EMPTY_VALUE. lineValue). double dValue) { if (dValue >= MinPriceLine[iBar]-gridStep && dValue <= MaxPriceLine[iBar]+gridStep) { dnLine[iBar] = dValue. Set_UpLineValue(i. } else upLine[iBar] = EMPTY_VALUE.reverse from down-trend / up-trend if (price[i] > lineValue) { iTrend = 1.gridStep) lineValue = price[i] + iGannGrid_Interval*gridStep. Set_DnLineValue(i.translate down linie if (price[i] + iGannGrid_Interval*gridStep < lineValue . else lineValue = lineValue . if (Show_HiloArrows) Show_SignalArrows(i. lineValue = price[i] . iTrend).iGannGrid_Interval*gridStep.

short signal if (iTrend == -1) { iArrow = 234.PAMA GannGrid_indv4.WindowPriceMin(0).Digits).40. ObjectCreate(sName..i). } else //---.long signal if (iTrend == 1) { iArrow = 233.OBJPROP_COLOR.dPrice). double dHiloOffset = dATR * dFactorOffset.OBJ_ARROW.3 //___________________________________________________________________ void Show_SignalArrows(int i. Page 11 . dATR = iATR(Symbol(). ObjectSet(sName. } dPrice = NormalizeDouble(dPrice.Time[i]. int iTrend) { int iArrow. dPrice = High[i] + dHighOffset.OBJPROP_ARROWCODE. dPrice.dColor). int i) { double dPrice. } //___________________________________________________________________ double CurrentPrice(int priceCode. dLowOffset = dHeightWindow / 100. dColor = CadetBlue. ObjectSet(sName. return.iArrow). double dFactorOffset = 0.34. double dATR.? double dHeightWindow = WindowPriceMax(0) . dPrice = Low[i] . //I use a value based on the current height of the window.. //---. int iHeight = 2. dHighOffset. string sName = "Signal_" + TimeToStr(Time[i]).dLowOffset. color dColor. dHighOffset = dLowOffset + 2*dHiloOffset. dLowOffset.Period().0. dColor = Teal.

break. } case PRICE_MEDIAN: { dPrice = (High[i] + Low[i]) / 2. break. firstTime. Time[0]. //drawn in foreground return. } //___________________________________________________________________ void Draw_VerticalLine(datetime dTime. break.Digits).iWindow. ObjectSet(sName. } //___________________________________________________________________ void Draw_HorizontalLine(double dValue) { dValue = NormalizeDouble(dValue. ObjectSet(sName.MainGrid_Color).OBJPROP_WIDTH. ObjectSet(sName.OBJPROP_COLOR.OBJ_TREND.minVal. dPrice = NormalizeDouble(dPrice. } case PRICE_OPEN: { dPrice = Open[i]. double minVal.dValue). } case PRICE_TYPICAL: { dPrice = (High[i] + Low[i] + Close[i]) / 3.OBJPROP_COLOR.3 switch (priceCode) { case PRICE_CLOSE: { dPrice = Close[i]. dTime. ObjectSet(sName. break.Digits). string sName = "HLine_" + DoubleToStr(dValue.0.OBJPROP_BACK.false). ObjectSet(sName.0.OBJPROP_STYLE. } } return(dPrice). ObjectSet(sName. Page 12 . ObjectCreate(sName.MainGrid_Style). dTime.MainGrid_Width).dValue.Digits).MainGrid_Color).OBJPROP_RAY. double maxVal) { string sName = "VLine_" + TimeToStr(dTime). ObjectCreate(sName.maxVal).iWindow.false).Digits).PAMA GannGrid_indv4.OBJ_TREND. dPrice = NormalizeDouble(dPrice.

OBJPROP_SCALE.iWindow.Digits). double dValue2) { string sName = "Gann_" + dValue1.OBJPROP_BACK.Digits).iWindow.OBJPROP_RAY. Delete_ObjectNames("Price_").true). Delete_ObjectNames("VLine_").PAMA GannGrid_indv4.dScale).OBJPROP_COLOR. string sValue = DoubleToStr(dValue.OBJPROP_RAY. datetime time2. sValue = sTextShift + sValue. time2.OBJPROP_WIDTH. } //____________________________________________________________________ void Delete_ObjectNames(string sName) Page 13 . //drawn in foreground return. ObjectSet(sName. //drawn in background return. ObjectCreate(sName.MainGrid_Width).dValue2). return. ObjectCreate(sName. ObjectSet(sName. ObjectSet(sName. double dScale = -gridStep * MathPow(10. ObjectSetText(sName.MainGrid_Style). Time[0]. Delete_ObjectNames("HLine_"). i++) sTextShift = sTextShift + " ".false).GannGrid_Color).fontSize).GannGrid_Style). Delete_ObjectNames("Signal_").3 ObjectSet(sName.OBJPROP_WIDTH.OBJ_TEXT.OBJPROP_STYLE. for (int i=1. } //___________________________________________________________________ void Write_PriceValue(double dValue) { string sTextShift. ObjectSet(sName.OBJ_GANNGRID.sValue. i<= Text_Shift.OBJPROP_STYLE. ObjectSet(sName.dValue).OBJPROP_BACK.false).dValue1. } //#################################################################### //____________________________________________________________________ void Delete_GannObjects() { Delete_ObjectNames("Gann_"). ObjectSet(sName. ObjectSet(sName. time1. } //___________________________________________________________________ void Draw_GannGrid(datetime time1.true). string sName = "Price_" + sValue.GannGrid_Width). ObjectSet(sName. ObjectSet(sName. double dValue1.

PAMA GannGrid_indv4. i>=0. if (StringFind(sObjectName. } } } Page 14 . sName. 0) != -1) { ObjectDelete(sObjectName).3 { int nObjects = ObjectsTotal(). for (int i=nObjects. i--) { string sObjectName = ObjectName(i).

Sign up to vote on this title
UsefulNot useful