Navigation:Home > Content >

Wiseman_Horizon.mq4

Time: 2015-12-02 | Download file:Wiseman_Horizon.mq4

//+------------------------------------------------------------------+
//|                                              Wiseman Horizon.mq4 |
//|                             Bill Williams Wiseman Divergent bars |
//|                                  Copyright © 2007, GwadaTradeBoy |
//|                                           gwadatradeboy@yahoo.fr |
//+------------------------------------------------------------------+
//|                                             Author: David Thomas |
//|                                      MQ4 Conversion: Pavel Kulko |
//|                                                  polk@alba.dp.ua |
//+------------------------------------------------------------------+
//|                                     Shape Drawing: GwadaTradeBoy |
//|                                           gwadatradeboy@yahoo.fr |
//+------------------------------------------------------------------+

/*[[
	Name := Wiseman 1
	Author := David Thomas, Basileus@Moneytec
	Notes := Bill Williams Wiseman 1 Divergent bars.  ver. 3.
	Notes := the changes of Basileus@Moneytec have been corrected and simplified.
	Separate Window := No
	First Color := LimeGreen
	First Draw Type := Histogram
	First Symbol := 217
	Use Second Data := Yes
	Second Color := Red
	Second Draw Type := Histogram
	Second Symbol := 218
]]*/
#property copyright "Copyright © 2007, GwadaTradeBoy"
#property link      "gwadatradeboy@yahoo.fr"
#property copyright "David Thomas"
#property link      "Basileus@Moneytec"
#property copyright "Copyright © 2005, Pavel Kulko"
#property link      "polk@alba.dp.ua"

#define Buy "Buy"
#define Sell "Sell"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 GreenYellow
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red

//---- Variables Externes
extern int     Method         = 1;
extern bool    Debug = True;

//---- Variables
//--- Methode 1
int            LastTradeTime;
double         PriceHighSell,PriceHighBuy,PriceLowSell,PriceLowBuy;
int            shift = 0;
double         prevbars = 0;
bool           first = True;
double         lips = 0;
double         teeth = 0;
double         loopbegin = 0;
double         median = 0;
double         jaws = 0;
//--- Methode 2
int            result, counted_bars, limit, i;
int            nShift;

//---- Shapes
extern int     NumberOfDays = 50; //Ammener а disparaitre counted_bars
extern color   BuyColor     = MediumAquamarine;       
extern color   SellColor    = Tomato;       
datetime       DateTrade;
datetime       TimeBeginObject, TimeEndObject;
datetime       TimeBeginBuySignal, TimeBeginSellSignal, TimeEndBuySignal, TimeEndSellSignal;
datetime       TimeBeginBuyShape, TimeBeginSellShape, TimeEndBuyShape, TimeEndSellShape;
double         PriceHighObject, PriceLowObject;
double         ShapePriceHighSell,ShapePriceHighBuy,ShapePriceLowSell,ShapePriceLowBuy;
double         SignalPriceHighSell,SignalPriceHighBuy,SignalPriceLowSell,SignalPriceLowBuy;
int            BarBegin, BarEnd;
      
//---- Buffers
double         ExtHistoBuffer[];
double         ExtHistoBuffer2[];
double         ExtMapBuffer3[];
double         ExtMapBuffer4[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
   {
//---- indicators
      SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID);
      SetIndexBuffer(0, ExtHistoBuffer);
      SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID);
      SetIndexBuffer(1, ExtHistoBuffer2);
//---- Styles et couleur des Fleches      
      SetIndexStyle(2, DRAW_ARROW, 0, 1);    // Fleche vers le haut
      SetIndexArrow(2, 233);
      SetIndexBuffer(2, ExtMapBuffer3);
      SetIndexStyle(3, DRAW_ARROW, 0, 1);    // Fleche vers le bas
      SetIndexArrow(3, 234);
      SetIndexBuffer(3, ExtMapBuffer4);
//---  Shapes
/* Before Drawing Object, you have to Create It */
      //DeleteObjects();
      //for (int i=0; i= 0 ; shift--)
         {
            //CreateObjects("Buy"+shift, BuyColor);
            //CreateObjects("Sell"+shift, SellColor);
            ObjectDelete("Buy"+shift);
            ObjectDelete("Sell"+shift);
         }  
//----       
      switch(Period())
         {
            case     1: nShift = 1;   break;
            case     5: nShift = 3;   break;
            case    15: nShift = 5;   break;
            case    30: nShift = 10;  break;
            case    60: nShift = 15;  break;
            case   240: nShift = 20;  break;
            case  1440: nShift = 80;  break;
            case 10080: nShift = 100; break;
            case 43200: nShift = 200; break;
         }
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
   {
//----
      for (i = Bars - 5 ;shift >= 0 ; shift--)
         {
            ObjectDelete("Buy"+shift);
            ObjectDelete("Sell"+shift);
         }
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
   {
      DateTrade = TimeCurrent();
//--- Methode 1
      if (Method ==1)
         {
//            SetLoopCount(0);
// check conditions are ok.
            if( Bars < 3 || Bars == prevbars ) 
               return(0);
// check for additional bars loading or total reloading
            if( Bars < prevbars || Bars-prevbars>1 ) 
               first = True;
            prevbars = Bars;
            if( first ) 
               { 
// loopbegin prevent counting of counted bars exclude current
	              loopbegin = Bars-2;
	              first = False;
               } 
// loop from first bar to current bar (with shift=0)
            for(shift=Bars-5;shift>=0 ;shift--)
               { 
                  result = 0;
                  median = (High[shift]+Low[shift])/2;
                  lips = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORLIPS, shift);
                  teeth = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORTEETH, shift);
                  jaws = iAlligator(NULL, 0, 13, 8, 8, 5, 5, 3, MODE_SMMA, PRICE_MEDIAN, MODE_GATORJAW, shift);
//---- Test for BUY Signal Bar : test for bullish divergent bar : 
                  if( ((Close[shift] >= median)                                     // close is in lower half of bar
                  && (High[shift] < MathMin(MathMin(lips,teeth),jaws))              // bar is completely below alligator
                  && (Low[shift] < Low[shift+1]) && (Low[shift] < Low[shift+2])     // low is moving down
                  && (Low[shift] < Low[shift+3]) && (Low[shift] < Low[shift+4])     // ...
                  && (iAO(NULL, 0, shift) < iAO(NULL, 0, shift+1))                  // checking if it's right AO signal
                  ) ) 
                     {
                        result = 1;
                        PriceHighBuy = High[shift];
                        PriceLowBuy = Low[shift];
                        
                     }
//---- Test for SELL Signal Bar : test for bearish divergent bar :
                  if( ((Close[shift] <= median)                                     // close is upper half of bar
                  && (Low[shift] > MathMax(MathMax(lips,teeth),jaws))               // bar is completely above alligator
                  && (High[shift] > High[shift+1]) && (High[shift] > High[shift+2]) // high is moving up
                  && (High[shift] > High[shift+3]) && (High[shift] > High[shift+4]) // ...
                  && (iAO(NULL, 0, shift) > iAO(NULL, 0, shift+1))                  // checking if it's right AO signal
                  ) ) 
                     {
                        result = -1;
                        PriceHighSell = High[shift];
                        PriceLowSell = Low[shift];
                        TimeBeginSellSignal = Time[shift];
                     }
//---- 
// Portion de code ou il faudra chercher la validitй du signal
                  if(( result == 0 )
                  &&(High[shift]>PriceHighSell))
                     {
                        PriceHighSell=0;
                        PriceLowSell=0;
                        //TimeEndSellSignal = TimeCurrent();
                     }
                  if(( result == 0 )
                  &&(Low[shift]>PriceHighBuy))
                     {
                        PriceHighBuy=0;
                        PriceLowBuy=0;
                        //TimeEndBuySignal = TimeCurrent();
                     }
//---- BUY : GREEN bar.
                  if(result > 0)
                     {
                        ExtHistoBuffer[shift] = PriceHighBuy;
                        ExtHistoBuffer2[shift] = PriceLowBuy;
                        ExtMapBuffer3[shift] = Low[shift] - nShift*Point;
//---- First Parameters for the BUY Shape (TimeBeginBuyShape, ShapePriceHighBuy, ShapePriceLowBuy)
                        TimeBeginBuyShape = TimeBeginBuySignal;
                        ShapePriceHighBuy = PriceHighBuy;
                        ShapePriceLowBuy = PriceLowBuy;
                     }
//---- SELL : RED bar.
                  if(result < 0)
                     {
                        ExtHistoBuffer[shift] = PriceLowSell;
                        ExtHistoBuffer2[shift] = PriceHighSell;
                        ExtMapBuffer4[shift] = High[shift] + nShift*Point;
//---- First Parameters for the SELL Shape (TimeBeginSellShape, ShapePriceHighSell, ShapePriceLowSell)
                        TimeBeginSellShape = TimeBeginSellSignal;
                        ShapePriceHighSell = PriceHighSell;
                        ShapePriceLowSell = PriceLowSell;
                     }
//---- Test des conditions de validitй du signal
//---  Buy
                  if (
                  (TimeCurrent() != TimeBeginBuySignal)
                  //&& ( Ask < PriceHighBuy)
                  )
                     //{
                        //if ( Ask < PriceHighBuy) //|| (
                           TimeEndBuyShape = Time[0];
                        else
                           TimeEndBuyShape = Time[1];
                     //}
//---  Sell
                  if ( Bid < PriceLowSell)
                     TimeEndSellShape = Time[0];
                  else
                     TimeEndSellShape = Time[1];   

//---- Dessin du rectangle
//---  Buy
                  
                  //TimeEndBuyShape = TimeEndBuySignal;
                  if (Debug)
                     {
                        Print("TimeBeginBuyShape ", TimeToStr(TimeBeginBuyShape,TIME_DATE|TIME_SECONDS));
                        Print("ShapePriceHighBuy ", ShapePriceHighBuy);
                        Print("TimeEndBuyShape ", TimeToStr(TimeEndBuyShape,TIME_DATE|TIME_SECONDS));
                        Print("ShapePriceLowBuy ", ShapePriceLowBuy);
                     }  
                  //DrawObjects(DateTrade, "Buy"+i, TimeBeginBuyShape, TimeEndBuyShape);
                  //ObjectCreate("Buy"+shift, OBJ_RECTANGLE, 0, TimeBeginBuyShape, ShapePriceHighBuy, Time[0], ShapePriceLowBuy);
                  ObjectCreate("Buy"+shift, OBJ_RECTANGLE, 0, TimeBeginBuyShape, ShapePriceHighBuy, TimeEndBuyShape, ShapePriceLowBuy);
                  ObjectSet("Buy"+shift, OBJPROP_COLOR, BuyColor);
//---  Sell
                  
                  TimeEndSellShape = TimeEndSellSignal;
/*                  if (Debug)
                     {
                        Print("TimeBeginBuyShape ", TimeToStr(TimeBeginBuyShape,TIME_DATE|TIME_SECONDS));
                        Print("ShapePriceHighBuy ", ShapePriceHighBuy);
                        Print("TimeEndBuyShape ", TimeToStr(TimeEndBuyShape,TIME_DATE|TIME_SECONDS));
                        Print("ShapePriceLowBuy ", ShapePriceLowBuy);
                     } 
                  //DrawObjects(DateTrade, "Sell"+i, TimeBeginSellShape, TimeEndSellShape);
                  ObjectCreate("Sell"+shift, OBJ_RECTANGLE, 0, TimeBeginSellShape, ShapePriceHighSell, TimeEndSellShape, ShapePriceLowSell);
                  ObjectSet("Sell"+shift, OBJPROP_COLOR, SellColor);
//---- 
/*                  DateTrade=decDateTradeDay(DateTrade);
                  while (TimeDayOfWeek(DateTrade)>5) 
                     DateTrade=decDateTradeDay(DateTrade); */
               }
         }
//--- Methode 2
      if (Method ==2)
         {
            counted_bars=IndicatorCounted();
            limit = Bars-counted_bars-1;
            for(i=limit; i>=0; i--) 
               {
                  result = 0;
                  median = (High[i]+Low[i])/2;
                  if((Low[i] < Low[i+1]) 
                  && (Close[i] > median)) 
                     result = -1;
                  if((High[i] > High[i+1]) 
                  && (Close[i] < median)) 
                     result = 1;
//---- BUY : GREEN bar.
                  if(result > 0) 
                     {
                        ExtHistoBuffer[i] = Low[i];
                        ExtHistoBuffer2[i] = High[i];
                        TimeBeginBuyShape = TimeCurrent();
                     }
//---- SELL : RED bar.
                  if(result < 0) 
                     {
                        ExtHistoBuffer[i] = High[i];
                        ExtHistoBuffer2[i] = Low[i];
                        TimeBeginSellShape = TimeCurrent();
                     }
//---- Test des conditions de validitй du signal
/*
//---  Buy
                  if ( Ask < PriceHighBuy)
                     TimeEndBuyShape = Time[0];
                  else
                     TimeEndBuyShape = Time[1];

//---  Sell
                  if ( Bid > PriceLowSell)
                     TimeEndSellShape = Time[0];
                  else
                     TimeEndSellShape = Time[1];   
*/
//---- Dessin du rectangle
//---  Buy
                  TimeBeginBuyShape = TimeBeginBuySignal;
                  TimeEndBuyShape = TimeEndBuySignal;
                  if (Debug)
                     {
                        Print("TimeBeginBuyShape ", TimeToStr(TimeBeginBuyShape,TIME_DATE|TIME_SECONDS));
                        Print("ShapePriceHighBuy ", ShapePriceHighBuy);
                        Print("TimeEndBuyShape ", TimeToStr(TimeEndBuyShape,TIME_DATE|TIME_SECONDS));
                        Print("ShapePriceLowBuy ", ShapePriceLowBuy);
                     }  
                  //DrawObjects(DateTrade, "Buy"+i, TimeBeginBuyShape, TimeEndBuyShape);
                  ObjectCreate("Buy"+i, OBJ_RECTANGLE, 0, TimeBeginBuyShape, ShapePriceHighBuy, TimeEndBuyShape, ShapePriceLowBuy);
                  ObjectSet("Buy"+i, OBJPROP_COLOR, BuyColor);
//---  Sell
                  TimeBeginSellShape = TimeBeginSellSignal;
                  TimeEndSellShape = TimeEndSellSignal;
/*                  if (Debug)
                     {
                        Print("TimeBeginBuyShape ", TimeBeginBuyShape);
                        Print("ShapePriceHighBuy ", ShapePriceHighBuy);
                        Print("TimeEndBuyShape ", TimeEndBuyShape);
                        Print("ShapePriceLowBuy ", ShapePriceLowBuy);
                     } 
                  //DrawObjects(DateTrade, "Sell"+i, TimeBeginSellShape, TimeEndSellShape);
                  ObjectCreate("Sell"+i, OBJ_RECTANGLE, 0, TimeBeginSellShape, ShapePriceHighSell, Time[0], ShapePriceLowSell);
                  ObjectSet("Sell"+i, OBJPROP_COLOR, SellColor);
//---- 
/*                  DateTrade=decDateTradeDay(DateTrade);
                  while (TimeDayOfWeek(DateTrade)>5) 
                     DateTrade=decDateTradeDay(DateTrade); */
               }
         }
//----
      return(0);
   }
//+------------------------------------------------------------------+
/*
//---- IsNewBar
bool NewBar()
   {
      dt = 0;
      if (dt != Time[0])
         {
            dt = Time[0];
            return(true);
         }
      return(false);
   }
   
//---- CreateObjects
void CreateObjects(string NameObject, color cl) 
   {
      ObjectCreate(NameObject, OBJ_RECTANGLE, 0, 0, 0, 0, 0);
      ObjectSet(NameObject, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(NameObject, OBJPROP_COLOR, cl);
      ObjectSet(NameObject, OBJPROP_BACK, True);
   }

//---- DeleteObjects
void DeleteObjects() 
   {
      for (int i=0; i        

Recommend