Hi
I am using the following indicator which works well on its own printing the arrows etc. Code sample below.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 1
#property indicator_color2 Yellow
#property indicator_width2 1
extern bool UseAlert = true;
extern int BarsToCount = 1000;
double SarUpSig[];
double SarDownSig[];
datetime TT;
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexBuffer(0,SarUpSig);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(1,SarDownSig);
TT=iTime(Symbol(),0,0);
//----
return(0);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
if(Period()!=PERIOD_H1)
{
return(0);
}
if (BarsToCount < limit)
limit = BarsToCount;
for(int i=limit; i>=0; i--)
{
datetime time = iTime(Symbol(),0,i);
int shiftD1 = iBarShift(Symbol(), PERIOD_D1, time, false);
int shiftH4 = iBarShift(Symbol(), PERIOD_H4, time, false);
int shiftH1 = iBarShift(Symbol(),PERIOD_H1,time,false);
double OsMa1 = iCustom(Symbol(),PERIOD_H1,"OsMA",30,200,5,0,shiftH1);
double OsMa2 = iCustom(Symbol(),PERIOD_H1,"OsMA",5,35,35,0,shiftH1);
double POsMa1 = iCustom(Symbol(),PERIOD_H1,"OsMA",30,200,5,0,shiftH1+1);
double POsMa2 = iCustom(Symbol(),PERIOD_H1,"OsMA",5,35,35,0,shiftH1+1);
//double Up_ST = iCustom(Symbol(),0,"4xRider STRONG-TREND Signal v2",14,2,i);
//double Dn_ST = iCustom(Symbol(),0,"4xRider STRONG-TREND Signal v2",14,1,i);
double SARD1 = iSAR(Symbol(),PERIOD_D1,0.22,0.2,shiftD1);
double SARH4 = iSAR(Symbol(),PERIOD_H4,0.05,0.2,shiftH4);
double SARH1 = iSAR(Symbol(),PERIOD_H1,0.01,0.2,shiftH1);
//double SARlast = iSAR(Symbol(),0,0.02,0.2,i+1);
double CLOSED1 = iClose(Symbol(),PERIOD_D1,shiftD1);
double CLOSEH4 = iClose(Symbol(),PERIOD_H4,shiftH4);
double CLOSEH1 = iClose(Symbol(),PERIOD_H1,shiftH1);
double PSARD1 = iSAR(Symbol(),PERIOD_D1,0.22,0.2,shiftD1+1);
double PSARH4 = iSAR(Symbol(),PERIOD_H4,0.05,0.2,shiftH4+1);
double PSARH1 = iSAR(Symbol(),PERIOD_H1,0.01,0.2,shiftH1+1);
//double SARlast = iSAR(Symbol(),0,0.02,0.2,i+1);
double PCLOSED1 = iClose(Symbol(),PERIOD_D1,shiftD1+1);
double PCLOSEH4 = iClose(Symbol(),PERIOD_H4,shiftH4+1);
double PCLOSEH1 = iClose(Symbol(),PERIOD_H1,shiftH1+1);
SarUpSig[i]=EMPTY_VALUE;
SarDownSig[i]=EMPTY_VALUE;
string buy;
//BUY
//if(Up_ST!=EMPTY_VALUE)
//{
//SarUpSig[1] = 1.6094;
if(SarUpSig[i+1] != EMPTY_VALUE && SARH1<CLOSEH1 && OsMa2>0 &&SARH4<CLOSEH4)
{
SarUpSig[i] = SARH1;
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider(BUY) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
if((PSARH4>PCLOSEH4&&POsMa1<0&&PSARH1>PCLOSEH1)&&
(SARH4<CLOSEH4&&OsMa1>0&&SARH1<CLOSEH1&&SARD1<CLOSED1)&& OsMa2>0)
{
SarUpSig[i] = SARH1;
buy = "trading";
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider (BUY) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
//}
string sell;
//SELL
//if(Dn_ST!=EMPTY_VALUE)
//{
if(SarDownSig[i+1] != EMPTY_VALUE && SARH1>CLOSEH1 && OsMa2<0 && SARH4>CLOSEH4)
{
SarDownSig[i] = SARH1;
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider (SELL) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
if((PSARH4<PCLOSEH4&&POsMa1>0&&PSARH1<PCLOSEH1)&&
(SARH4>CLOSEH4&&OsMa1<0&&SARH1>CLOSEH1&&SARD1>CLOSED1)&& OsMa2<0)
{
SarDownSig[i] = SARH1;
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider (SELL) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
//}
//SELL
}
//----
//Comment("From indicator: ", DoubleToStr(SarUpSig[1], Digits));
return(0);
}
I'm using an EA to read the values as follows.
#define INDI "MyIndicator"
double IndiUpVal = iCustom(NULL, 0, INDI, false, 5, 0, 1);
double IndiDownVal = iCustom(NULL, 0, INDI, false, 5, 1, 1);
Comment("IndiUpVal: "+ D2S(IndiUpVal)+ ". IndiUpVal: "+ D2S(IndiDownVal));
D2S = DoubleToString with digit
No matter what I do the iCustom returns EMPTY_VAL.
If I Print the value from within the indicator at the right time SarUpSig[1]
will return the correct values. But the iCustom always gives EMPTY_VAL.
Why?
Any help is greatly appreciated.
I am using the following indicator which works well on its own printing the arrows etc. Code sample below.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 1
#property indicator_color2 Yellow
#property indicator_width2 1
extern bool UseAlert = true;
extern int BarsToCount = 1000;
double SarUpSig[];
double SarDownSig[];
datetime TT;
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexBuffer(0,SarUpSig);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexBuffer(1,SarDownSig);
TT=iTime(Symbol(),0,0);
//----
return(0);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
if(Period()!=PERIOD_H1)
{
return(0);
}
if (BarsToCount < limit)
limit = BarsToCount;
for(int i=limit; i>=0; i--)
{
datetime time = iTime(Symbol(),0,i);
int shiftD1 = iBarShift(Symbol(), PERIOD_D1, time, false);
int shiftH4 = iBarShift(Symbol(), PERIOD_H4, time, false);
int shiftH1 = iBarShift(Symbol(),PERIOD_H1,time,false);
double OsMa1 = iCustom(Symbol(),PERIOD_H1,"OsMA",30,200,5,0,shiftH1);
double OsMa2 = iCustom(Symbol(),PERIOD_H1,"OsMA",5,35,35,0,shiftH1);
double POsMa1 = iCustom(Symbol(),PERIOD_H1,"OsMA",30,200,5,0,shiftH1+1);
double POsMa2 = iCustom(Symbol(),PERIOD_H1,"OsMA",5,35,35,0,shiftH1+1);
//double Up_ST = iCustom(Symbol(),0,"4xRider STRONG-TREND Signal v2",14,2,i);
//double Dn_ST = iCustom(Symbol(),0,"4xRider STRONG-TREND Signal v2",14,1,i);
double SARD1 = iSAR(Symbol(),PERIOD_D1,0.22,0.2,shiftD1);
double SARH4 = iSAR(Symbol(),PERIOD_H4,0.05,0.2,shiftH4);
double SARH1 = iSAR(Symbol(),PERIOD_H1,0.01,0.2,shiftH1);
//double SARlast = iSAR(Symbol(),0,0.02,0.2,i+1);
double CLOSED1 = iClose(Symbol(),PERIOD_D1,shiftD1);
double CLOSEH4 = iClose(Symbol(),PERIOD_H4,shiftH4);
double CLOSEH1 = iClose(Symbol(),PERIOD_H1,shiftH1);
double PSARD1 = iSAR(Symbol(),PERIOD_D1,0.22,0.2,shiftD1+1);
double PSARH4 = iSAR(Symbol(),PERIOD_H4,0.05,0.2,shiftH4+1);
double PSARH1 = iSAR(Symbol(),PERIOD_H1,0.01,0.2,shiftH1+1);
//double SARlast = iSAR(Symbol(),0,0.02,0.2,i+1);
double PCLOSED1 = iClose(Symbol(),PERIOD_D1,shiftD1+1);
double PCLOSEH4 = iClose(Symbol(),PERIOD_H4,shiftH4+1);
double PCLOSEH1 = iClose(Symbol(),PERIOD_H1,shiftH1+1);
SarUpSig[i]=EMPTY_VALUE;
SarDownSig[i]=EMPTY_VALUE;
string buy;
//BUY
//if(Up_ST!=EMPTY_VALUE)
//{
//SarUpSig[1] = 1.6094;
if(SarUpSig[i+1] != EMPTY_VALUE && SARH1<CLOSEH1 && OsMa2>0 &&SARH4<CLOSEH4)
{
SarUpSig[i] = SARH1;
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider(BUY) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
if((PSARH4>PCLOSEH4&&POsMa1<0&&PSARH1>PCLOSEH1)&&
(SARH4<CLOSEH4&&OsMa1>0&&SARH1<CLOSEH1&&SARD1<CLOSED1)&& OsMa2>0)
{
SarUpSig[i] = SARH1;
buy = "trading";
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider (BUY) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
//}
string sell;
//SELL
//if(Dn_ST!=EMPTY_VALUE)
//{
if(SarDownSig[i+1] != EMPTY_VALUE && SARH1>CLOSEH1 && OsMa2<0 && SARH4>CLOSEH4)
{
SarDownSig[i] = SARH1;
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider (SELL) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
if((PSARH4<PCLOSEH4&&POsMa1>0&&PSARH1<PCLOSEH1)&&
(SARH4>CLOSEH4&&OsMa1<0&&SARH1>CLOSEH1&&SARD1>CLOSED1)&& OsMa2<0)
{
SarDownSig[i] = SARH1;
if(TT!=iTime(Symbol(),0,0)&&UseAlert)
{
//string time = TimeToStr(TimeCurrent());
Alert("4xRider (SELL) "+Symbol());
PlaySound("alert.wav");
TT=iTime(Symbol(),0,0);
}
}
//}
//SELL
}
//----
//Comment("From indicator: ", DoubleToStr(SarUpSig[1], Digits));
return(0);
}
I'm using an EA to read the values as follows.
#define INDI "MyIndicator"
double IndiUpVal = iCustom(NULL, 0, INDI, false, 5, 0, 1);
double IndiDownVal = iCustom(NULL, 0, INDI, false, 5, 1, 1);
Comment("IndiUpVal: "+ D2S(IndiUpVal)+ ". IndiUpVal: "+ D2S(IndiDownVal));
D2S = DoubleToString with digit
No matter what I do the iCustom returns EMPTY_VAL.
If I Print the value from within the indicator at the right time SarUpSig[1]
will return the correct values. But the iCustom always gives EMPTY_VAL.
Why?
Any help is greatly appreciated.