15M trade

property indicator_chart_window
property indicator_buffers 3
property indicator_color1 RosyBrown
property indicator_color2 LimeGreen//SteelBlue//SkyBlue
property indicator_color3 Red//Tan
//#property indicator_color4 OliveDrab
//#property indicator_color5 Tan
//#property indicator_color6 Red
//#property indicator_color7 LimeGreen
//--------------------------------------------------------------------------------------------------------------------
static bool lastSignal=false; //false means short, ture means long
static int last = 99999;
//---- buffers
extern int bk1 = 1;
extern int bk2 = 3;
extern int line = 2;
double Buf_2[];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double MA_0, MA_11, MA_12, MA_13, MA_14;
double Polzun_1[21],Line[21];
double KK=1.2;
double K=5;
//--------------------------------------------------------------------------------------------------------------------
int i,n,k, counted_bars, K2, K3;
int Period_MA_0 = 8;
int Period_MA_1 = 21;
int Kol_Line=20;
int init()
{
switch(Period())
{
case 1: K2=5; K3=15; break;
case 5: K2=3; K3= 6; break;
case 15: K2=2; K3= 4; break;
case 30: K2=2; K3= 8; break;
case 60: K2=4; K3=24; break;
case 240: K2=6; K3=42; break;
case 1440: K2=7; K3=30; break;
case 10080: K2=4; K3= 0; break;
case 43200: K2=0; K3= 0; break;
}
Polzun_1[1]=20;
//--------------------------------------------------------------------------------------------------------------------
SetIndexStyle (0,DRAW_LINE);
SetIndexBuffer(0,Buf_2);
SetIndexStyle(1,DRAW_ARROW,EMPTY);
SetIndexArrow(1,233);
SetIndexBuffer(1, ExtMapBuffer1);
SetIndexStyle(2,DRAW_ARROW,EMPTY);
SetIndexArrow(2,234);
SetIndexBuffer(2, ExtMapBuffer2);
//--------------------------------------------------------------------------------------------------------------------
return(0);
}
/*
//+------------------------------------------------------------------+
//| 基于昨天高低开收价的菲波纳切线 计有中心,阻力123,支持123 |
//+------------------------------------------------------------------+
int FiboPiv_v1()
{
//----
double rates[1][6],yesterday_close,yesterday_high,yesterday_low;
ArrayCopyRates(rates, Symbol(), PERIOD_D1);
if(DayOfWeek() == 1)
{
if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,1)) == 5)
{
yesterday_close = rates[1][4];
yesterday_high = rates[1][3];
yesterday_low = rates[1][2];
}
else
{
for(int d = 5;d>=0;d--)
{
if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,d)) == 5)
{
yesterday_close = rates[d][4];
yesterday_high = rates[d][3];
yesterday_low = rates[d][2];
}
}
}
}
else
{
yesterday_close = rates[1][4];
yesterday_high = rates[1][3];
yesterday_low = rates[1][2];
}
//---- Calculate Pivots
double R = yesterday_high - yesterday_low;//range
double p = (yesterday_high + yesterday_low + yesterday_close)/3;// Standard Pivot
double r3 = p + (R * 1.000);
double r2 = p + (R * 0.618);
double r1 = p + (R * 0.382);
double s1 = p - (R * 0.382);
double s2 = p - (R * 0.618);
double s3 = p - (R * 1.000);
Comment("Yesday: H=",yesterday_high," L=",yesterday_low, " C=",yesterday_close," P=",p," R=",R/Point," RSI14-30=", iRSI( Symbol(),PERIOD_M30,14,PRICE_TYPICAL, 0),"\n Today: H=",iHigh(Symbol(),PERIOD_D1,0)," L=",iLow(Symbol(),PERIOD_D1,0)," P=",(iHigh(Symbol(),PERIOD_D1,0)+iLow(Symbol(),PERIOD_D1,0))/2," R=",(iHigh(Symbol(),PERIOD_D1,0)-iLow(Symbol(),PERIOD_D1,0))/Point," RSI14-1H=",iRSI( Symbol(),PERIOD_H1,14,PRICE_TYPICAL, 0));
drawLine(r3,"R3", Lime,0);
drawLabel("R 3",r3,Lime);
drawLine(r2,"R2", Green,0);
drawLabel("R 2",r2,Sienna);
drawLine(r1,"R1", DarkGreen,0);
drawLabel("R 1",r1,Sienna);
drawLine(p,"Center",Tan,1);
drawLabel("Cent",p,LightSlateGray);
drawLine(s1,"S1",Maroon,0);
drawLabel("S 1",s1,Maroon);
drawLine(s2,"S2",Crimson,0);
drawLabel("S 2",s2,Crimson);
drawLine(s3,"S3",Red,0);
drawLabel("S 3",s3,Red);
//----
return(0);
}
//+------------------------------------------------------------------+
void drawLabel(string name,double lvl,color Color)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_TEXT, 0, Time[BarsPerWindow()7/10], lvl); ObjectSetText(name, name, 8, "Arial", EMPTY); ObjectSet(name, OBJPROP_COLOR, Color); } else { ObjectMove(name, 0, Time[BarsPerWindow()7/10], lvl);
}
}
void drawLine(double lvl,string name, color Col,int type)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
if(type == 1) ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID); else ObjectSet(name, OBJPROP_STYLE, STYLE_DOT); ObjectSet(name, OBJPROP_COLOR, Col); ObjectSet(name,OBJPROP_WIDTH,1); } else { ObjectDelete(name); ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl); if(type == 1) ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID); else ObjectSet(name, OBJPROP_STYLE, STYLE_DOT); ObjectSet(name, OBJPROP_COLOR, Col); ObjectSet(name,OBJPROP_WIDTH,1); }
}
*/
void PriLiv()
{
counted_bars=IndicatorCounted();
i=Bars-counted_bars-1;
//--------------------------------------------------------------------------------------------------------------------
for (n=2;n<=Kol_Line;n++)
{
k=n-1;
Polzun_1[n]=Polzun_1[k]/KK;
}
//====================================================================================================================
while(i>=0)
{
//--------------------------------------------------------------------------------------------------------------------
/* MA_0 = iMA( NULL, 0, Period_MA_0K3, 0, MODE_LWMA, PRICE_TYPICAL, i ); //-------------------------------------------------------------------------------------------------------------------- Buf_2[i]= 0; MA_11 = iMA( NULL, 0, Period_MA_1, 0, MODE_LWMA, PRICE_TYPICAL, i ); for (n=1;n<=Kol_Line;n++) { MA_12 = iMA( NULL, 0, Period_MA_1, 0, MODE_LWMA, PRICE_TYPICAL, i +Polzun_1[n]); Line[n] = MA_11-MA_12; Buf_2[i] = Buf_2[i]+Line[n]; } Buf_2[i]= MA_0 + KBuf_2[i]/Kol_Line/2;
/ MA_0 = iMA( NULL, 0, Period_MA_0K3, 0, MODE_LWMA, PRICE_TYPICAL, i );
//--------------------------------------------------------------------------------------------------------------------
Buf_2[i]= 0;
MA_11 = iMA( NULL, 0, Period_MA_1, 0, MODE_LWMA, PRICE_TYPICAL, i );
for (n=1;n<=Kol_Line;n++)
{
MA_12 = iMA( NULL, 0, Period_MA_1, 0, MODE_LWMA, PRICE_TYPICAL, i +Polzun_1[n]);
Line[n] = MA_11-MA_12;
Buf_2[i] = Buf_2[i]+Line[n];
}
Buf_2[i]= MA_0 + K*Buf_2[i]/Kol_Line/2;
//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------
i--;
}
i=Bars-counted_bars-2;
while(i>=0)
{
if (line==0){
if((Buf_2[i] > Buf_2[i+bk1]) && (Buf_2[i+bk1] < Buf_2[i+bk2])&&(lastSignal==false)) setBuy(i); if((Buf_2[i] < Buf_2[i+bk1]) && (Buf_2[i+bk1] > Buf_2[i+bk2])&&(lastSignal==true))
setSell(i);
}
if (line==1){
if((((Buf_2[i] - Buf_2[i+bk1])10/Point)>3) && (((Buf_2[i+bk1] - Buf_2[i+bk2])10/Point )<-3)&&(lastSignal==false)) setBuy(i); if((((Buf_2[i] - Buf_2[i+bk1])10/Point)<-3) && (((Buf_2[i+bk1] - Buf_2[i+bk2])10/Point)>3)&&(lastSignal==true))
setSell(i);
}
if (line==2){
if((Buf_2[i] > Buf_2[i+bk1]) && (((Buf_2[i+bk1] - Buf_2[i+bk2])10/Point )<-5)&&(lastSignal==false)) setBuy(i); if((Buf_2[i] < Buf_2[i+bk1]) && (((Buf_2[i+bk1] - Buf_2[i+bk2])10/Point)>5)&&(lastSignal==true))
setSell(i);
}
i--;
}
//====================================================================================================================
}
void setBuy(int CB)
{
if (MathAbs(last-CB) < 3) return ;
ExtMapBuffer1[CB]=Low[CB]-8*Point;
lastSignal=true;
last = CB ;
}
//+------------------------------------------------------------------+
//| set sell order |
//+------------------------------------------------------------------+
void setSell(int CB)
{
if (MathAbs(last-CB) < 3) return ;
ExtMapBuffer2[CB]=High[CB]+8*Point;
lastSignal=false;
last = CB ;
}
int start()
{
PriLiv();
//FiboPiv_v1();
return(0);
}
int deinit()
{
return(0);
}
/*