Hi,
I'm trying to code a stochastic for M1 which take the data of M15. Somehow it doesn't works. been trying to figure out. Any senior could help me. thank you!!
Here is the M15 (IMG 1_4). as you can see on the chart that the arrow appear here in M15. Stoch is at OB and MACD is below 0.
Here at M1(IMG 2_4), Stoch is at OB, but there isn't any arrow.
So i will put the indicator in M1 chart.
The indicator work this way, when M15 Stoch is at OB and MACD is Below 0 and M1 Stoch is at OB, arrow will appear on the chart(M1)
Here's my whole code
I'm trying to code a stochastic for M1 which take the data of M15. Somehow it doesn't works. been trying to figure out. Any senior could help me. thank you!!
Here is the M15 (IMG 1_4). as you can see on the chart that the arrow appear here in M15. Stoch is at OB and MACD is below 0.
Here at M1(IMG 2_4), Stoch is at OB, but there isn't any arrow.
So i will put the indicator in M1 chart.
The indicator work this way, when M15 Stoch is at OB and MACD is Below 0 and M1 Stoch is at OB, arrow will appear on the chart(M1)
Here's my whole code
Inserted Code
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
//--- Arrow
#property indicator_label1 "ArrUp"
#property indicator_label2 "ArrDn"
//--- input parameters
enum eprice
{
s0 = 0,//LOW/HIGH
s1 = 1 //CLOSE/CLOSE
};
//----------------------------------------------------------------------------------------
input string __________1__________="xxxxxxxxxxxxxxxxxxxxx";
input string __________2__________="=ALERT=";//ALERT ARROW AND NOTIFICATIONS,
input string __________3__________="xxxxxxxxxxxxxxxxxxxxx";
input bool ARROW = true;//SHOW ARROW
input string __________4__________="xxxxxxxxxxxxxxxxxxxxx";
input string __________5__________="=ARROW CODE=";//ARROW DETAILS
input string __________6__________="xxxxxxxxxxxxxxxxxxxxx";
input int ARROWUP =217;//ARROW CODE
input int ARROWDN =218;//ARROW CODE
input color ARROWUPc=clrWhite;//Arrow Up Color
input color ARROWDNc=clrWhite;//Arrow Dn Color
input string __________10__________="xxxxxxxxxxxxxxxxxxxxx";
input string __________11__________="=M15 OB OS=";//OB OS,
input string __________12__________="xxxxxxxxxxxxxxxxxxxxx";
input double sto_dn_level = 20.0;//LEVEL Down
input double sto_up_level = 80.0;//LEVEL Up
input eprice sto_price=1;//PRICE FIELD
//----------------------------------------------------------------------------------------
//--- indicator buffers
double ArrUpBuffer[];
double ArrDnBuffer[];
//---
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
IndicatorBuffers(2);
SetIndexBuffer(0,ArrUpBuffer);SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1,ARROWUPc);SetIndexArrow(0,ARROWUP);
SetIndexBuffer(1,ArrDnBuffer);SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1,ARROWDNc);SetIndexArrow(1,ARROWDN);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
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 i,limit;
limit=rates_total-prev_calculated;
if(prev_calculated>0)limit=limit+2;
for(i=limit-2;i>=0;i--)
{
if(ARROW &&
iMA(_Symbol,PERIOD_M15,50,0,MODE_EMA,PRICE_CLOSE,i)>iMA(_Symbol,PERIOD_M15,100,0,MODE_EMA,PRICE_CLOSE,i) &&
iMA(_Symbol,PERIOD_M15,100,0,MODE_EMA,PRICE_CLOSE,i)>iMA(_Symbol,PERIOD_M15,200,0,MODE_EMA,PRICE_CLOSE,i) &&
iMACD(_Symbol,PERIOD_M15,12,26,1,PRICE_CLOSE,MODE_MAIN,i)>0.0 &&
iStochastic(_Symbol,PERIOD_M15,3,1,3,MODE_EMA,(int)sto_price,MODE_MAIN,i)<=sto_dn_level &&
iStochastic(_Symbol,PERIOD_M15,3,1,3,MODE_EMA,(int)sto_price,MODE_SIGNAL,i)<=sto_dn_level &&
iStochastic(_Symbol,PERIOD_M1,3,1,3,MODE_EMA,(int)sto_price,MODE_MAIN,i)<=sto_dn_level &&
iStochastic(_Symbol,PERIOD_M1,3,1,3,MODE_EMA,(int)sto_price,MODE_SIGNAL,i)<=sto_dn_level
)
{ArrUpBuffer[i]=iLow(_Symbol,PERIOD_M1,i)-10*pix_y();}
if(ARROW &&
iMA(_Symbol,PERIOD_M15,50,0,MODE_EMA,PRICE_CLOSE,i)<iMA(_Symbol,PERIOD_M15,100,0,MODE_EMA,PRICE_CLOSE,i) &&
iMA(_Symbol,PERIOD_M15,100,0,MODE_EMA,PRICE_CLOSE,i)<iMA(_Symbol,PERIOD_M15,200,0,MODE_EMA,PRICE_CLOSE,i) &&
iMACD(_Symbol,PERIOD_M15,12,26,1,PRICE_CLOSE,MODE_MAIN,i)<0.0 &&
iStochastic(_Symbol,PERIOD_M15,3,1,3,MODE_EMA,(int)sto_price,MODE_MAIN,i)>=sto_up_level &&
iStochastic(_Symbol,PERIOD_M15,3,1,3,MODE_EMA,(int)sto_price,MODE_SIGNAL,i)>=sto_up_level &&
iStochastic(_Symbol,PERIOD_M1,3,1,3,MODE_EMA,(int)sto_price,MODE_MAIN,i)>=sto_up_level &&
iStochastic(_Symbol,PERIOD_M1,3,1,3,MODE_EMA,(int)sto_price,MODE_SIGNAL,i)>=sto_up_level
)
{ArrDnBuffer[i]=iHigh(_Symbol,PERIOD_M1,i)+10*pix_y();}
}
return(rates_total);
}
//+------------------------------------------------------------------+
double pix_y()
{
return((ChartGetDouble(0,CHART_PRICE_MAX,0)-ChartGetDouble(0,CHART_PRICE_MIN,0))/ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0));
}
//+------------------------------------------------------------------+
[color=#666666][font=trebuchet ms][/font][/color]