Price Data Components
Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
MagicOscillator2.00
//+------------------------------------------------------------------+
//| MagicOscillator2.00.mq4 |
//| zfs |
//| @ |
//+------------------------------------------------------------------+
#property copyright "zfs"
#property link "vasbsm@mail.ru"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_width2 5
#property indicator_width3 5
#property indicator_minimum 0
#property indicator_maximum 100
//----
#define SIGNAL_BAR 0
//----
extern bool Alerts=true;
extern int Period1=5;//îñíîâíîé ïåðèîä
extern int Period2=34;//ñãëàæèâàþùèé ïåðèîä
extern int TypeMA=MODE_SMA;//0-3
extern int TypePrice=PRICE_MEDIAN;//0-6
extern int delta1buy=0;//îòêëþ÷åíèå -1
extern int delta1sell=0;//îòêëþ÷åíèå -1
extern int delta2buy=0;//îòêëþ÷åíèå -1
extern int delta2sell=0;//îòêëþ÷åíèå -1
extern int delta3buy=-1;//îòêëþ÷åíèå -1
extern int delta3sell=-1;//îòêëþ÷åíèå -1
//---- indicator buffers
double TempBuffer[];
double OscBuyBuffer[];
double OscSellBuffer[];
int init()
{
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
IndicatorDigits(Digits);
SetIndexDrawBegin(0,Period2);
SetIndexDrawBegin(1,Period2);
SetIndexDrawBegin(2,Period2);
SetIndexBuffer(0,TempBuffer);
SetIndexBuffer(1,OscBuyBuffer);
SetIndexBuffer(2,OscSellBuffer);
IndicatorShortName("MAGIC OSCILLATOR 2.00");
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
return(0);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
double high3=iHigh(NULL,0,i+3);
double low3=iLow(NULL,0,i+3);
double close3=iClose(NULL,0,i+3);
double high2=iHigh(NULL,0,i+2);
double low2=iLow(NULL,0,i+2);
double close2=iClose(NULL,0,i+2);
double high1=iHigh(NULL,0,i+1);
double low1=iLow(NULL,0,i+1);
double close1=iClose(NULL,0,i+1);
double ao1=iMA(NULL,0,Period1,0,TypeMA,TypePrice,i+1)-iMA(NULL,0,Period2,0,TypeMA,TypePrice,i+1);
double ao0=iMA(NULL,0,Period1,0,TypeMA,TypePrice,i)-iMA(NULL,0,Period2,0,TypeMA,TypePrice,i);
double close0=iClose(NULL,0,i);//òåêóùàÿ öåíà
double high0=iHigh(NULL,0,i);
double low0=iLow(NULL,0,i);
double l10,h10,hmax10,lmin10,Repaint;
if (high1>high0)
{
h10=high0;
hmax10=high1;
}
else
{
h10=high1;
hmax10=high0;
}
if (low1<low0)
{
l10=low0;
lmin10=low1;
}
else
{
l10=low1;
lmin10=low0;
}
if (h10-l10<0)Repaint=0;else Repaint=100-((h10-l10)/(hmax10-lmin10)*100);
double deltab1=0;double deltas1=0;
double deltab2=0;double deltas2=0;
double deltab3=0;double deltas3=0;
if (close1>(high1+low1)/2.0)deltab1=close0-high1;
if (close1<(high1+low1)/2.0)deltas1=low1-close0;
if (close2>(high2+low2)/2.0)deltab2=close1-high2;
if (close2<(high2+low2)/2.0)deltas2=low2-close1;
if (close3>(high3+low3)/2.0)deltab3=close2-high3;
if (close3<(high3+low3)/2.0)deltas3=low3-close2;
if (delta1buy==-1)delta1buy=9999;
if (delta2buy==-1)delta2buy=9999;
if (delta3buy==-1)delta3buy=9999;
if (delta1sell==-1)delta1sell=9999;
if (delta2sell==-1)delta2sell=9999;
if (delta3sell==-1)delta3sell=9999;
int Break1=0;
int Break2=0;
int Break3=0;
if (deltas3>delta3sell*Point&&deltas3>=deltab3&&ao0>ao1)Break3=-1;
if (deltab3>delta3buy*Point&&deltab3>=deltas3&&ao0<ao1)Break3=1;
if (deltas2>delta2sell*Point&&deltas2>=deltab2&&ao0>ao1)Break2=-1;
if (deltab2>delta2buy*Point&&deltab2>=deltas2&&ao0<ao1)Break2=1;
if (deltas1>delta1sell*Point&&deltas1>=deltab1&&ao0>ao1)Break1=-1;
if (deltab1>delta1buy*Point&&deltab1>=deltas1&&ao0<ao1)Break1=1;
if (Break1==1)TempBuffer[i]=Repaint;
if (Break1==-1)TempBuffer[i]=-Repaint;
if (Break1==0)
{
if (Break2==1)TempBuffer[i]=Repaint;
if (Break2==-1)TempBuffer[i]=-Repaint;
if (Break2==0)
{
if (Break3==1)TempBuffer[i]=Repaint;
if (Break3==-1)TempBuffer[i]=-Repaint;
if (Break3==0)
{
if (ao0>ao1)TempBuffer[i]=Repaint;
else TempBuffer[i]=-Repaint;
}
}
}
}
for(i=0; i<limit; i++)
{
if (TempBuffer[i]>0)
{
OscBuyBuffer[i]=TempBuffer[i];
OscSellBuffer[i]=0;
}
if (TempBuffer[i]<0)
{
OscSellBuffer[i]=-TempBuffer[i];
OscBuyBuffer[i]=0;
}
}
if (Alerts)
{
//---- Ñòàòè÷åñêèå ïåðåìåííûå, â êîòîðûõ õðàíÿòñÿ
//---- âðåìÿ ïîñëåäíåãî áàðà è íàïðàâëåíèå ïîñëåäíåãî ñèãíàëà
static int PrevSignal = 0, PrevTime = 0;
//---- Åñëè áàðîì äëÿ àíàëèçà âûáðàí íå 0-é, íàì íåò ñìûñëà ïðîâåðÿòü ñèãíàë
//---- íåñêîëüêî ðàç. Åñëè íå íà÷àëñÿ íîâûé áàð, âûõîäèì.
if(SIGNAL_BAR > 0 && Time[0] <= PrevTime )
return(0);
//---- Îòìå÷àåì, ÷òî ýòîò áàð ïðîâåðåí
PrevTime = Time[0];
//---- Åñëè ïðåäûäóùèé ñèãíàë áûë ÑÅËË èëè ýòî ïåðâûé çàïóñê (PrevSignal=0)
if(PrevSignal <= 0)
{
if(OscBuyBuffer[SIGNAL_BAR]> 0 && OscSellBuffer[SIGNAL_BAR+1]> 0)
{
PrevSignal = 1;
Alert("MAGIC (", Symbol(), ", ", Period(), ") - BUY!!!");
}
}
if(PrevSignal >= 0)
{
if(OscSellBuffer[SIGNAL_BAR]> 0 && OscBuyBuffer[SIGNAL_BAR+1]> 0)
{
PrevSignal = -1;
Alert("MAGIC (", Symbol(), ", ", Period(), ") - SELL!!!");
}
}
}
//--
return(0);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---