老王吧 发表于 2016-5-19 16:01:07

3 Bar Swing



//+------------------------------------------------------------------+
//|                                                3_bar_swing.mq4 |
//|                                                         Zen_Leow |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Zen_Leow"
#property link      ""

#property indicator_chart_window

// The number of buffers for calculation, up to 8
#property indicator_buffers 2

// The color for displaying arrows
#property indicator_color1 Green       // Long signal
#property indicator_color2 Red         // Short signal

// Width of the arrows
#property indicator_width1 1// Long signal arrow
#property indicator_width2 1// Short signal arrow

extern int ArrowDistance = 3;

// Buffers for the calculations
double Up_Arrow_Buffer[];    // Long buffer for display
double Down_Arrow_Buffer[];   // Short buffer for display
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   // SetIndexStyle- sets the new type, style, width and color for a given indicator line
   // SetIndexBuffer - binds the array variable declared at a global level to the custom indicator pre-defined buffer
   // SetIndexArrow- sets an arrow symbol for indicators line of the DRAW_ARROW type.
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexBuffer(0, Up_Arrow_Buffer);
   SetIndexArrow(0, 233); // Up arrow
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexBuffer(1, Down_Arrow_Buffer);
   SetIndexArrow(1, 234); // Down arrow
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                     |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i;                           // Bar index      
   int Counted_bars;                // Number of counted bars
   //--------------------------------------------------------------------   
   Counted_bars=IndicatorCounted(); // Number of counted bars   
   i=Bars-Counted_bars-1;         // Index of the first uncounted   
   if (i == 0)
   {
      i = 2;// the newest signal bar is suppose to be at index 2
   }
   while(i>1)                      // Loop for uncounted bars   
   {      
      if (isUpSwingBar(i))
      {
         Up_Arrow_Buffer = Low - (ArrowDistance * Point);
         Down_Arrow_Buffer = EMPTY_VALUE;
      }
      else if (isDownSwingBar(i))
      {
         Down_Arrow_Buffer = High + (ArrowDistance * Point);
         Up_Arrow_Buffer = EMPTY_VALUE;
      }
      else
      {
         Up_Arrow_Buffer = EMPTY_VALUE;
         Down_Arrow_Buffer = EMPTY_VALUE;
      }
      i--;
   }
//----
   return(0);
}

bool isUpSwingBar(int i)
{
   if (Low < Low && Low < Low && High < High && High < High)
   {
      return (true);
   }
   return (false);
}

bool isDownSwingBar(int i)
{
   if (Low > Low && Low > Low && High > High && High > High)
   {
      return (true);
   }
   return (false);
}
//+------------------------------------------------------------------+


WZjh394B 发表于 2020-6-4 19:05:44

我是个凑数的。。。

李姐 发表于 2020-6-27 19:42:07

好好 学习了 确实不错

离孩农高会 发表于 2020-9-9 18:24:29

谢谢楼主分享

zg807 发表于 2020-11-3 09:51:31

谢谢楼主分享

jacky1216 发表于 2021-7-14 22:52:26

{:1_179:}

稳准快狠 发表于 2021-7-23 10:00:57

顶下

fzhogzyj 发表于 2021-7-29 13:15:05

谢谢

徒迁 发表于 2023-11-3 16:01:12

{:1_189:}

scbxiaoqiang 发表于 2024-7-27 08:34:55

可否加个报警{:1_174:}
页: [1]
查看完整版本: 3 Bar Swing