ZigZag broken

Back to topics list To post a new topic, please log in or register
avatar
86
fly7680 2016.07.28 11:40
 
Hello everyone!

I would take 3 points of the Zig Zag and breakage have a signal. This is my code but unfortunately it does not work .... a little help, please?

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0x0000FF
#property indicator_label1 "Sell"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0x00FF00
#property indicator_label2 "Buy"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | ZigZag5 @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 242);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 241);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| 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 = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation  
 
      //Indicator Buffer 1 Condition SELL
      if(iCustom(NULL, PERIOD_CURRENT, "ZIG ZAG NRP", 480, 4, 0, 3+i) > Close[1+i] //ZIG ZAG NRP > Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "ZIG ZAG NRP", 480, 4, 0, 1+i) > Close[1+i] //ZIG ZAG NRP > Candlestick Close
      )
        {
         Buffer1[i] = High[i]; Arrow Sell
        }
      
      //Indicator Buffer 2 Condition BUY
      if(iCustom(NULL, PERIOD_CURRENT, "ZIG ZAG NRP", 480, 4, 0, 3+i) < Close[1+i] //ZIG ZAG NRP < Candlestick Close
      && iCustom(NULL, PERIOD_CURRENT, "ZIG ZAG NRP", 480, 4, 0, 1+i) < Close[1+i] //ZIG ZAG NRP < Candlestick Close
      )
        {
         Buffer2[i] = Low[i]; Arrow Buy
        }      
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Attached files:
  ziggzagonrp.mq4  (2.12 KB)
avatar
211
Subgenius 2016.08.03 10:09 #
 
fly7680:
Hello everyone!

I would take 3 points of the Zig Zag and breakage have a signal. This is my code but unfortunately it does not work .... a little help, please?


so you are going to put arrows after a new zigzag line?

just add two index arrays to the indicator attachment .. drop your price into them with an atr/2 distance(default settings).

i dont understand what your doing on the src but the indi attachment i would work from.

to set your alert just call your bar 0 index array versus close price but count ++ from 0 to get the last price of your zigzag.

Back to topics list  

To add comments, please log in or register