Description
//+------------------------------------------------------------------+ //| ZigAndZagScalpel.mq4 | //| Bookkeeper, 2006, yuzefovich@gmail.com | //+------------------------------------------------------------------+ #property copyright "" #property link "" //---- #property indicator_chart_window #property indicator_buffers 7 // Èëè 8 - äëÿ testBuffer #property indicator_color1 Aqua #property indicator_color2 Black #property indicator_color3 Black #property indicator_color4 Black #property indicator_color5 White #property indicator_color6 Red #property indicator_color7 Red //#property indicator_color8 White // Äëÿ ïîäáîðà ÷åãî-íèáóäü extern int KeelOver=55; // Äëÿ M15 extern int Slalom=17; // Äëÿ M15 double KeelOverZigAndZagSECTION[]; double KeelOverZagBuffer[]; double SlalomZigBuffer[]; double SlalomZagBuffer[]; double LimitOrdersBuffer[]; double BuyOrdersBuffer[]; double SellOrdersBuffer[]; //double testBuffer[]; int shift,back,CountBar,Backstep=3; int LastSlalomZagPos,LastSlalomZigPos,LastKeelOverZagPos,LastKeelOverZigPos; double Something,LimitPoints,Navel; double CurKeelOverZig,CurKeelOverZag,CurSlalomZig,CurSlalomZag; double LastSlalomZag,LastSlalomZig,LastKeelOverZag,LastKeelOverZig; bool TrendUp,SetBuyOrder,SetLimitOrder,SetSellOrder,Second=false; string LastZigOrZag="None"; //---- int init() { SetIndexBuffer(0,KeelOverZigAndZagSECTION); SetIndexStyle(0,DRAW_SECTION,STYLE_DOT);//DRAW_SECTION èëè DRAW_NONE SetIndexEmptyValue(0,0.0); SetIndexBuffer(1,KeelOverZagBuffer); SetIndexStyle(1,DRAW_NONE); SetIndexEmptyValue(1,0.0); SetIndexBuffer(2,SlalomZigBuffer); SetIndexStyle(2,DRAW_NONE); SetIndexEmptyValue(2,0.0); SetIndexBuffer(3,SlalomZagBuffer); SetIndexStyle(3,DRAW_NONE); SetIndexEmptyValue(3,0.0); SetIndexBuffer(4,LimitOrdersBuffer); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,108); SetIndexEmptyValue(4,0.0); SetIndexBuffer(5,BuyOrdersBuffer); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,233); SetIndexEmptyValue(5,0.0); SetIndexBuffer(6,SellOrdersBuffer); SetIndexStyle(6,DRAW_ARROW); SetIndexArrow(6,234); SetIndexEmptyValue(6,0.0); // SetIndexStyle(7,DRAW_SECTION); // SetIndexBuffer(7,testBuffer); // SetIndexEmptyValue(7,0.0); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { CountBar=Bars-KeelOver; LimitPoints=Ask-Bid; if(CountBar<=3*KeelOver) return(-1); // Ìàëîâàòî áóäåò if(KeelOver<=2*Slalom) return(-1); // Òùàòåëüíåå íàäî // Çà÷èñòêà íåïðàâèëüíîé èñòîðèè for(shift=Bars-1; shift>Bars-KeelOver; shift--) { SlalomZagBuffer[shift]=0.0; SlalomZigBuffer[shift]=0.0; KeelOverZagBuffer[shift]=0.0; KeelOverZigAndZagSECTION[shift]=0.0; LimitOrdersBuffer[shift]=0.0; BuyOrdersBuffer[shift]=0.0; SellOrdersBuffer[shift]=0.0; // testBuffer[shift]=0.0; } //+---Ïåðâûé ïîõîä ïî èñòîðèè----------------------------------------+ The_First_Crusade(); //+---Âòîðîé ïðîõîä ïî èñòîðè÷åñêèì ìåñòàì---------------------------+ //+---ñ öåëüþ ïîä÷èñòêè íåâåðíî ïîíÿòûõ ñîáûòèé----------------------+ LastSlalomZag=-1; LastSlalomZagPos=-1; LastSlalomZig=-1; LastSlalomZigPos=-1; LastKeelOverZag=-1; LastKeelOverZagPos=-1; LastKeelOverZig=-1; LastKeelOverZigPos=-1; The_Second_Crusade(); //+---Òðåòèé èñòîðè÷åñêèé ýêñêóðñ - ïîñòðîåíèå "òðåíäà"--------------+ //+---è ðàññòàíîâêà "òîðãîâûõ ñèãíàëîâ"------------------------------+ LastSlalomZag=-1; LastSlalomZagPos=-1; LastSlalomZig=-1; LastSlalomZigPos=-1; LastZigOrZag="None"; The_Third_Crusade(); //+---À ÷åãî ìû òåïåðü áóäåì èìåòü çäåñü è ñåé÷àñ?-------------------+ Shift_Zerro(); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void The_First_Crusade() { for(shift=CountBar; shift>0; shift--) { // Ïîèñê òî÷åê "âñòàë â ïîçó" - "óøåë ñ ðûíêà" CurSlalomZig=Low[Lowest(NULL,0,MODE_LOW,Slalom,shift)]; CurSlalomZag=High[Highest(NULL,0,MODE_HIGH,Slalom,shift)]; // Ïðîâåðÿåì shift íà íàëè÷èå î÷åðåäíîãî ÑëàëîìÇèãà äëÿ âõîäà // â ïîêóïêó èëè äëÿ âûõîäà èç ïðîäàæè if(CurSlalomZig==LastSlalomZig) CurSlalomZig=0.0; else { LastSlalomZig=CurSlalomZig; if((Low[shift]-CurSlalomZig)>LimitPoints) CurSlalomZig=0.0; else { // Íà èíòåðâàëå Backstep ìîæåò áûòü òîëüêî îäèí Çèã, // îñòàâëÿåì òîëüêî ïîñëåäíèé, áîëåå ðàííèå óáèðàåì for(back=1; back<=Backstep; back++) { Something=SlalomZigBuffer[shift+back]; if((Something!=0)&&(Something>CurSlalomZig)) SlalomZigBuffer[shift+back]=0.0; } } } // Ïðîâåðÿåì shift íà íàëè÷èå î÷åðåäíîãî ÑëàëîìÇàãà äëÿ âõîäà âíèç // èëè äëÿ âûõîäà èç ïîêóïêè if(CurSlalomZag==LastSlalomZag) CurSlalomZag=0.0; else { LastSlalomZag=CurSlalomZag; if((CurSlalomZag-High[shift])>LimitPoints) CurSlalomZag=0.0; else { // Íà èíòåðâàëå Backstep ìîæåò áûòü òîëüêî îäèí Çàã, // îñòàâëÿåì òîëüêî ïîñëåäíèé, áîëåå ðàííèå óáèðàåì for(back=1; back<=Backstep; back++) { Something=SlalomZagBuffer[shift+back]; if((Something!=0)&&(SomethingLimitPoints) CurKeelOverZig=0.0; else { // Íà èíòåðâàëå Backstep ìîæåò áûòü òîëüêî îäèí Çèã, // îñòàâëÿåì òîëüêî ïîñëåäíèé, áîëåå ðàííèå óáèðàåì for(back=1; back<=Backstep; back++) { Something=KeelOverZigAndZagSECTION[shift+back]; if((Something!=0)&&(Something>CurKeelOverZig)) KeelOverZigAndZagSECTION[shift+back]=0.0; } } } // Ïðîâåðÿåì shift íà íàëè÷èå î÷åðåäíîãî ÎâåðêèëüÇàãà if(CurKeelOverZag==LastKeelOverZag) CurKeelOverZag=0.0; else { LastKeelOverZag=CurKeelOverZag; if((CurKeelOverZag-High[shift])>LimitPoints) CurKeelOverZag=0.0; else { // Íà èíòåðâàëå Backstep ìîæåò áûòü òîëüêî îäèí Çàã, // áîëåå ðàííèå óáèðàåì for(back=1; back<=Backstep; back++) { Something=KeelOverZagBuffer[shift+back]; if((Something!=0)&&(Something0; shift--) { CurSlalomZig=SlalomZigBuffer[shift]; CurSlalomZag=SlalomZagBuffer[shift]; if((CurSlalomZig==0)&&(CurSlalomZag==0)) continue; if(CurSlalomZag!=0) { if(LastSlalomZag>0) { if(LastSlalomZag0) { if(LastSlalomZig>CurSlalomZig) SlalomZigBuffer[LastSlalomZigPos]=0; else SlalomZigBuffer[shift]=0; } if((CurSlalomZig0) { if(LastKeelOverZag0) { if(LastKeelOverZig>CurSlalomZig) KeelOverZigAndZagSECTION[LastKeelOverZigPos]=0; else KeelOverZigAndZagSECTION[shift]=0; } if((CurKeelOverZig0; shift--) { // Íèçâåãàåì ïðåæíèõ ïðîðîêîâ LimitOrdersBuffer[shift]=0.0; BuyOrdersBuffer[shift]=0.0; SellOrdersBuffer[shift]=0.0; // Çàäàåì öåíòð ìèðîçäàíüÿ èíòåðâàëà shift (ïî ëþáîìó - // ñïîñîá áîëüøîãî ïîëèòè÷åñêîãî âåñà íå èìååò) Navel=(5*Close[shift]+2*Open[shift]+High[shift]+Low[shift])/9; // Åñëè îâåðêèëü - ñìîòðèì, // êóäà (ìîæåò áûòü) äàëüøå ñåéìîìåíòíî ïîéäåì: ââåðõ èëè âíèç if(KeelOverZigAndZagSECTION[shift]!=0.0) { TrendUp=true; first=false; } if(KeelOverZagBuffer[shift]!=0.0) { TrendUp=false; first=false; } // Ñîáèðàåì â KeelOverZigAndZagSECTION è ÎâåðêèëüÇèãè, è ÎâåðêèëüÇàãè, // è ïóñòûøêè - âñå â îäíó êó÷êó, òàêèì îáðàçîì ïîëó÷àåì äîëãîèãðàþùèé // ZigAndZag, íàòÿãèâàÿ íèòü "òðåíäà" íà ïóïêè ðàçâîðîòíûõ ñâå÷åê if(KeelOverZagBuffer[shift]!=0.0 || KeelOverZigAndZagSECTION[shift]!=0.0) { KeelOverZigAndZagSECTION[shift]=Navel; } else KeelOverZigAndZagSECTION[shift]=0.0; // Ïðîâåðÿåì shift íà íàëè÷èå ÑëàëîìÇèãà èëè ÑëàëîìÇàãà if(SlalomZigBuffer[shift]!=0.0) { LastZigOrZag="Zig"; LastSlalomZig=Navel; SetBuyOrder=false; SetLimitOrder=false; SetSellOrder=false; } if(SlalomZagBuffer[shift]!=0.0) { LastZigOrZag="Zag"; LastSlalomZag=Navel; SetBuyOrder=false; SetLimitOrder=false; SetSellOrder=false; } // è, åñëè íè ÑëàëîìÇèãà, íè ÑëàëîìÇàãà óæå íåò, // à îâåðêèëü óæå áûë - ñìîòðèì, à ÷òî åñòü ïî âõîäó-âûõîäó if(SlalomZigBuffer[shift]==0.0 && SlalomZagBuffer[shift]==0.0 && first==false) Slalom_With_A_Scalpel(); } return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Shift_Zerro() { shift=0; Navel=(5*Close[0]+2*Open[0]+High[0]+Low[0])/9; Slalom_With_A_Scalpel(); KeelOverZigAndZagSECTION[0]=Navel; return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Slalom_With_A_Scalpel() { // Ïðîâåðÿåì ñóùåñòâóþùèé ñèãíàë íà èìååò ïðàâî áûòü // èëè íà åñëè íå ñòîèò, à õîòåëîñü áû: // åñëè õîä ÷èñòî êîíêðåòíî ïî æèçíè - çàáèâàåì Ñòðåëêó íà äåíüãè, // åñëè ïðîòèâ - ñòàâèì íà øóõåð Øàðèêà Äåëàé-Íîãè if(LastZigOrZag=="Zig") { if(TrendUp==true) { if((Navel-LastSlalomZig)>=LimitPoints && SetBuyOrder==false) { SetBuyOrder=true; BuyOrdersBuffer[shift]=Low[shift+1]; LastSlalomZigPos=shift; } if(Navel<=LastSlalomZig && SetBuyOrder==true) { SetBuyOrder=false; BuyOrdersBuffer[LastSlalomZigPos]=0.0; LastSlalomZigPos=-1; } } if(TrendUp==false) { if(Navel>LastSlalomZig && SetLimitOrder==false) { SetLimitOrder=true; LimitOrdersBuffer[shift]=Navel; // LimitOrdersBuffer[shift]=Close[shift]; LastSlalomZigPos=shift; } if(Navel<=LastSlalomZig && SetLimitOrder==true) { SetLimitOrder=false; LimitOrdersBuffer[LastSlalomZigPos]=0.0; LastSlalomZigPos=-1; } } } if(LastZigOrZag=="Zag") { if(TrendUp==false) { if((LastSlalomZag-Navel)>=LimitPoints && SetSellOrder==false) { SetSellOrder=true; SellOrdersBuffer[shift]=High[shift+1]; LastSlalomZagPos=shift; } if(Navel>=LastSlalomZag && SetSellOrder==true) { SetSellOrder=false; SellOrdersBuffer[LastSlalomZagPos]=0.0; LastSlalomZagPos=-1; } } if(TrendUp==true) { if(LastSlalomZag>Navel && SetLimitOrder==false) { SetLimitOrder=true; LimitOrdersBuffer[shift]=Navel; // LimitOrdersBuffer[shift]=Close[shift]; LastSlalomZagPos=shift; } if(Navel>=LastSlalomZag && SetLimitOrder==true) { SetLimitOrder=false; LimitOrdersBuffer[LastSlalomZagPos]=0.0; LastSlalomZagPos=-1; } } } return; } //+--Ñîáñòâåííî, ÿ âñå ñêàçàë. Çàáàâíî, åñëè âñå ýòî ðàáîòàòü áóäåò--+ //+------------------------------------------------------------------+
using System;
using cAlgo.API;
using cAlgo.API.Internals;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class ZigZag : Indicator
{
[Parameter(DefaultValue = 12)]
public int Depth { get; set; }
[Parameter(DefaultValue = 5)]
public int Deviation { get; set; }
[Parameter(DefaultValue = 3)]
public int BackStep { get; set; }
[Output("ZigZag", Color = Colors.OrangeRed)]
public IndicatorDataSeries Result { get; set; }
#region Private fields
private double _lastLow;
private double _lastHigh;
private double _low;
private double _high;
private int _lastHighIndex;
private int _lastLowIndex;
private int _type;
private double _point;
private double _currentLow;
private double _currentHigh;
private IndicatorDataSeries _highZigZags;
private IndicatorDataSeries _lowZigZags;
#endregion
protected override void Initialize()
{
_highZigZags = CreateDataSeries();
_lowZigZags = CreateDataSeries();
_point = Symbol.PointSize;
}
public override void Calculate(int index)
{
if (index < Depth)
{
Result[index] = 0;
_highZigZags[index] = 0;
_lowZigZags[index] = 0;
return;
}
_currentLow = Functions.Minimum(MarketSeries.Low, Depth);
if (Math.Abs(_currentLow - _lastLow) < double.Epsilon)
_currentLow = 0.0;
else
{
_lastLow = _currentLow;
if ((MarketSeries.Low[index] - _currentLow) > (Deviation * _point))
_currentLow = 0.0;
else
{
for (int i = 1; i <= BackStep; i++)
{
if (Math.Abs(_lowZigZags[index - i]) > double.Epsilon && _lowZigZags[index - i] > _currentLow)
_lowZigZags[index - i] = 0.0;
}
}
}
if (Math.Abs(MarketSeries.Low[index] - _currentLow) < double.Epsilon)
_lowZigZags[index] = _currentLow;
else
_lowZigZags[index] = 0.0;
_currentHigh = MarketSeries.High.Maximum(Depth);
if (Math.Abs(_currentHigh - _lastHigh) < double.Epsilon)
_currentHigh = 0.0;
else
{
_lastHigh = _currentHigh;
if ((_currentHigh - MarketSeries.High[index]) > (Deviation * _point))
_currentHigh = 0.0;
else
{
for (int i = 1; i <= BackStep; i++)
{
if (Math.Abs(_highZigZags[index - i]) > double.Epsilon && _highZigZags[index - i] < _currentHigh)
_highZigZags[index - i] = 0.0;
}
}
}
if (Math.Abs(MarketSeries.High[index] - _currentHigh) < double.Epsilon)
_highZigZags[index] = _currentHigh;
else
_highZigZags[index] = 0.0;
switch (_type)
{
case 0:
if (Math.Abs(_low - 0) < double.Epsilon && Math.Abs(_high - 0) < double.Epsilon)
{
if (Math.Abs(_highZigZags[index]) > double.Epsilon)
{
_high = MarketSeries.High[index];
_lastHighIndex = index;
_type = -1;
Result[index] = _high;
}
if (Math.Abs(_lowZigZags[index]) > double.Epsilon)
{
_low = MarketSeries.Low[index];
_lastLowIndex = index;
_type = 1;
Result[index] = _low;
}
}
break;
case 1:
if (Math.Abs(_lowZigZags[index]) > double.Epsilon && _lowZigZags[index] < _low && Math.Abs(_highZigZags[index] - 0.0) < double.Epsilon)
{
Result[_lastLowIndex] = double.NaN;
_lastLowIndex = index;
_low = _lowZigZags[index];
Result[index] = _low;
}
if (Math.Abs(_highZigZags[index] - 0.0) > double.Epsilon && Math.Abs(_lowZigZags[index] - 0.0) < double.Epsilon)
{
_high = _highZigZags[index];
_lastHighIndex = index;
Result[index] = _high;
_type = -1;
}
break;
case -1:
if (Math.Abs(_highZigZags[index]) > double.Epsilon && _highZigZags[index] > _high && Math.Abs(_lowZigZags[index] - 0.0) < double.Epsilon)
{
Result[_lastHighIndex] = double.NaN;
_lastHighIndex = index;
_high = _highZigZags[index];
Result[index] = _high;
}
if (Math.Abs(_lowZigZags[index]) > double.Epsilon && Math.Abs(_highZigZags[index]) <= double.Epsilon)
{
_low = _lowZigZags[index];
_lastLowIndex = index;
Result[index] = _low;
_type = 1;
}
break;
default:
return;
}
}
}
}
AL
aleandroiacovelli
Joined 08.01.2015
- Type: Free
- Language: C#
- Trading Platform: cTrader Automate
- Filename: ZigZag.algo
- Rating: 0
- Downloads: 6291
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Comments
Only logged in users can post a comment
Comments not found