编码帮助 - 页 176 1...169170171172173174175176177178179180181182183...786 新评论 k3rn3l 2013.10.22 08:16 #1751 默认参数,3.0和10 Mladen Rakic 2013.10.22 08:26 #1752 k3rn3l: 默认参数,3.0和10 在这种情况下,只需替换以下一行。 ExtMapBuffer1 = Close * Beta1 - iClose(Symbol2, NULL, iShift2) * Beta2;[/PHP] with this [PHP]ExtMapBuffer1 = iCustom(Symbol2,0,"Supertrend",3,10,0,iShift2); 我假设该指标的名称是 "Supertrend"。 k3rn3l 2013.10.22 08:34 #1753 我不想替换,我想把超级趋势代码整合到这个指标中,而超级趋势整合是在指标ExtMapBuffer1上计算的。 Mladen Rakic 2013.10.22 08:41 #1754 k3rn3l: 我不想替换,我想把超级趋势代码整合到这个指标中,而超级趋势整合是在指标ExtMapBuffer1上计算的。 k3rn3l 我恐怕不明白 "整合 "是什么意思 你能不能多解释一下? k3rn3l 2013.10.22 09:52 #1755 我的意思是像这样的事情。 #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 DodgerBlue #property indicator_color2 Lime #property indicator_color3 Red double TrendUp[], TrendDown[], ExtMapBuffer1[]; int changeOfTrend; extern int Nbr_Periods = 10; extern double Multiplier = 3.0; extern double Beta1 = 1.0; extern string Symbol2 = "GER30"; extern double Beta2 = 1.0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); SetIndexBuffer(1, TrendUp); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(2, TrendDown); SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2); IndicatorShortName(Symbol() + " " + Beta1 + " " + Symbol2 + " " + Beta2); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, flag, flagh, trend[5000]; double up[5000], dn[5000], medianPrice, atr; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //Print(limit); //---- if(Bars<1) return(0); int j = Bars-counted_bars -1; while(j >=0) { int iShift2 = iBarShift(Symbol2, 0, Time[j], false); ExtMapBuffer1[j] = Close[j] * Beta1 - iClose(Symbol2, NULL, iShift2) * Beta2; for (i = Bars; i >= 0; i--) { TrendUp = EMPTY_VALUE; TrendDown = EMPTY_VALUE; atr = iATR(NULL, 0, Nbr_Periods, i); //Print("atr: "+atr); medianPrice = ExtMapBuffer1[j]/2; //Print("medianPrice: "+medianPrice); up=medianPrice+(Multiplier*atr); //Print("up: "+up); dn=medianPrice-(Multiplier*atr); //Print("dn: "+dn); trend=1; if (Close>up) { trend=1; if (trend == -1) changeOfTrend = 1; //Print("trend: "+trend); } else if (Close<dn) { trend=-1; if (trend == 1) changeOfTrend = 1; //Print("trend: "+trend); } else if (trend==1) { trend=1; changeOfTrend = 0; } else if (trend==-1) { trend=-1; changeOfTrend = 0; } if (trend0) { flag=1; //Print("flag: "+flag); } else { flag=0; //Print("flagh: "+flag); } if (trend>0 && trend<0) { flagh=1; //Print("flagh: "+flagh); } else { flagh=0; //Print("flagh: "+flagh); } if (trend>0 && dn<dn) dn=dn; if (trendup) up=up; if (flag==1) up=medianPrice+(Multiplier*atr); if (flagh==1) dn=medianPrice-(Multiplier*atr); //-- Draw the indicator if (trend==1) { TrendUp=dn; if (changeOfTrend == 1) { TrendUp = TrendDown; changeOfTrend = 0; } } else if (trend==-1) { TrendDown=up; if (changeOfTrend == 1) { TrendDown = TrendUp; changeOfTrend = 0; } } } WindowRedraw(); } //---- return(0); } //+------------------------------------------------------------------+ Coding help I want to use Indicators: Non Repainting Supertrend Mladen Rakic 2013.10.22 09:56 #1756 k3rn3l: 我的意思是像这样。 #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 DodgerBlue #property indicator_color2 Lime #property indicator_color3 Red double TrendUp[], TrendDown[], ExtMapBuffer1[]; int changeOfTrend; extern int Nbr_Periods = 10; extern double Multiplier = 3.0; extern double Beta1 = 1.0; extern string Symbol2 = "GER30"; extern double Beta2 = 1.0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); SetIndexBuffer(1, TrendUp); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(2, TrendDown); SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2); IndicatorShortName(Symbol() + " " + Beta1 + " " + Symbol2 + " " + Beta2); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, flag, flagh, trend[5000]; double up[5000], dn[5000], medianPrice, atr; int counted_bars = IndicatorCounted(); //---- check for possible errors if(counted_bars < 0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; //Print(limit); //---- if(Bars<1) return(0); int j = Bars-counted_bars -1; while(j >=0) { int iShift2 = iBarShift(Symbol2, 0, Time[j], false); ExtMapBuffer1[j] = Close[j] * Beta1 - iClose(Symbol2, NULL, iShift2) * Beta2; for (i = Bars; i >= 0; i--) { TrendUp = EMPTY_VALUE; TrendDown = EMPTY_VALUE; atr = iATR(NULL, 0, Nbr_Periods, i); //Print("atr: "+atr); medianPrice = ExtMapBuffer1[j]/2; //Print("medianPrice: "+medianPrice); up=medianPrice+(Multiplier*atr); //Print("up: "+up); dn=medianPrice-(Multiplier*atr); //Print("dn: "+dn); trend=1; if (Close>up) { trend=1; if (trend == -1) changeOfTrend = 1; //Print("trend: "+trend); } else if (Close<dn) { trend=-1; if (trend == 1) changeOfTrend = 1; //Print("trend: "+trend); } else if (trend==1) { trend=1; changeOfTrend = 0; } else if (trend==-1) { trend=-1; changeOfTrend = 0; } if (trend0) { flag=1; //Print("flag: "+flag); } else { flag=0; //Print("flagh: "+flag); } if (trend>0 && trend<0) { flagh=1; //Print("flagh: "+flagh); } else { flagh=0; //Print("flagh: "+flagh); } if (trend>0 && dn<dn) dn=dn; if (trendup) up=up; if (flag==1) up=medianPrice+(Multiplier*atr); if (flagh==1) dn=medianPrice-(Multiplier*atr); //-- Draw the indicator if (trend==1) { TrendUp=dn; if (changeOfTrend == 1) { TrendUp = TrendDown; changeOfTrend = 0; } } else if (trend==-1) { TrendDown=up; if (changeOfTrend == 1) { TrendDown = TrendUp; changeOfTrend = 0; } } } WindowRedraw(); } //---- return(0); } //+------------------------------------------------------------------+ 然后声明另一个缓冲区(例如ExtMapBuffer2),并使用iCustom() 检索超级趋势的值到这个新的缓冲区(像这样: ExtMapBuffer2[i] =iCustom(Symbol2,0,"Supertrend",3,10,0,iShift2)。 k3rn3l 2013.10.22 10:55 #1757 谢谢 现在,我有了这个。.你能帮我纠正错误吗? #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 FireBrick #property indicator_color3 Green #property indicator_color4 Blue #property indicator_width1 1 #property indicator_width2 2 #property indicator_width3 2 #property indicator_style1 STYLE_DOT // Indicator parameters extern int SuperTrend.Period=10; extern double SuperTrend.Multiplier=3.0; extern string Symbol2 = "GBPUSD"; // Global module varables double gadUpBuf[]; double gadDnBuf[]; double gadSuperTrend[]; double Spread[]; //----------------------------------------------------------------------------- // function: init() // Description: Custom indicator initialization function. //----------------------------------------------------------------------------- int init() { SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, Spread); SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1, gadSuperTrend); SetIndexLabel(1, "SuperTrend"); SetIndexStyle(2, DRAW_LINE); SetIndexBuffer(2, gadDnBuf); SetIndexLabel(2, "SuperTrend Down"); SetIndexStyle(3, DRAW_LINE); SetIndexBuffer(3, gadUpBuf); SetIndexLabel(3, "SuperTrend Up"); IndicatorShortName(INDICATOR_NAME+"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]"); return(0); } //----------------------------------------------------------------------------- // function: deinit() // Description: Custom indicator deinitialization function. //----------------------------------------------------------------------------- int deinit() { return (0); } ///----------------------------------------------------------------------------- // function: start() // Description: Custom indicator iteration function. //----------------------------------------------------------------------------- int start() { int iNewBars, iCountedBars, i; double dAtr,dUpperLevel, dLowerLevel; // Get unprocessed ticks iCountedBars=IndicatorCounted(); if(iCountedBars < 0) return (-1); if(iCountedBars>0) iCountedBars--; iNewBars=Bars-iCountedBars; Spread = Close / iClose(Symbol2, NULL, i) ; for(i=iNewBars; i>=0; i--) { // Calc SuperTrend dAtr = iATR(NULL, 0, SuperTrend.Period, i); dUpperLevel=Spread/2+SuperTrend.Multiplier*dAtr; dLowerLevel=Spread/2-SuperTrend.Multiplier*dAtr; // Set supertrend levels if (Close>gadSuperTrend && Close<=gadSuperTrend) { gadSuperTrend=dLowerLevel; } else if (Close=gadSuperTrend) { gadSuperTrend=dUpperLevel; } else if (gadSuperTrend<dLowerLevel) gadSuperTrend=dLowerLevel; else if (gadSuperTrend>dUpperLevel) gadSuperTrend=dUpperLevel; else gadSuperTrend=gadSuperTrend; // Draw SuperTrend lines gadUpBuf=EMPTY_VALUE; gadDnBuf=EMPTY_VALUE; if (Close>gadSuperTrend || (Close==gadSuperTrend && Close>gadSuperTrend)) gadUpBuf=gadSuperTrend; else if (Close<gadSuperTrend || (Close==gadSuperTrend && Close<gadSuperTrend)) gadDnBuf=gadSuperTrend; } return(0); } //+------------------------------------------------------------------+ Coding help Please fix this indicator 请各位老大或者高手帮帮忙,改一下 Mladen Rakic 2013.10.22 12:36 #1758 k3rn3l: 谢谢 现在,我有了这个。你能帮我纠正错误吗? #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 FireBrick #property indicator_color3 Green #property indicator_color4 Blue #property indicator_width1 1 #property indicator_width2 2 #property indicator_width3 2 #property indicator_style1 STYLE_DOT // Indicator parameters extern int SuperTrend.Period=10; extern double SuperTrend.Multiplier=3.0; extern string Symbol2 = "GBPUSD"; // Global module varables double gadUpBuf[]; double gadDnBuf[]; double gadSuperTrend[]; double Spread[]; //----------------------------------------------------------------------------- // function: init() // Description: Custom indicator initialization function. //----------------------------------------------------------------------------- int init() { SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, Spread); SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1, gadSuperTrend); SetIndexLabel(1, "SuperTrend"); SetIndexStyle(2, DRAW_LINE); SetIndexBuffer(2, gadDnBuf); SetIndexLabel(2, "SuperTrend Down"); SetIndexStyle(3, DRAW_LINE); SetIndexBuffer(3, gadUpBuf); SetIndexLabel(3, "SuperTrend Up"); IndicatorShortName(INDICATOR_NAME+"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]"); return(0); } //----------------------------------------------------------------------------- // function: deinit() // Description: Custom indicator deinitialization function. //----------------------------------------------------------------------------- int deinit() { return (0); } ///----------------------------------------------------------------------------- // function: start() // Description: Custom indicator iteration function. //----------------------------------------------------------------------------- int start() { int iNewBars, iCountedBars, i; double dAtr,dUpperLevel, dLowerLevel; // Get unprocessed ticks iCountedBars=IndicatorCounted(); if(iCountedBars < 0) return (-1); if(iCountedBars>0) iCountedBars--; iNewBars=Bars-iCountedBars; Spread = Close / iClose(Symbol2, NULL, i) ; for(i=iNewBars; i>=0; i--) { // Calc SuperTrend dAtr = iATR(NULL, 0, SuperTrend.Period, i); dUpperLevel=Spread/2+SuperTrend.Multiplier*dAtr; dLowerLevel=Spread/2-SuperTrend.Multiplier*dAtr; // Set supertrend levels if (Close>gadSuperTrend && Close<=gadSuperTrend) { gadSuperTrend=dLowerLevel; } else if (Close=gadSuperTrend) { gadSuperTrend=dUpperLevel; } else if (gadSuperTrend<dLowerLevel) gadSuperTrend=dLowerLevel; else if (gadSuperTrend>dUpperLevel) gadSuperTrend=dUpperLevel; else gadSuperTrend=gadSuperTrend; // Draw SuperTrend lines gadUpBuf=EMPTY_VALUE; gadDnBuf=EMPTY_VALUE; if (Close>gadSuperTrend || (Close==gadSuperTrend && Close>gadSuperTrend)) gadUpBuf=gadSuperTrend; else if (Close<gadSuperTrend || (Close==gadSuperTrend && Close<gadSuperTrend)) gadDnBuf=gadSuperTrend; } return(0); } //+------------------------------------------------------------------+ 对不起,但我真的看不出你想做什么(似乎你想计算某种价差的超级趋势,但我无法从代码中看出)。 你为什么不从超级趋势指标本身开始(因为你似乎想改变它)? k3rn3l 2013.10.22 12:50 #1759 是的,这是我想做的。 1) 创建一个2种资产之间的价差指标 2)在价差上计算超级趋势 我不能使用iCustom的Supertrend,因为它是在主图上加载的,而不是在我创建的价差上。 因此,我试图按照这种方式(在一个指标中实现所有价差和超级趋势的代码)。 Mladen Rakic 2013.10.22 12:58 #1760 k3rn3l: 是的,这就是我所要做的。1) 创建一个2种资产之间的价差指标 2)在价差上计算超级趋势 我不能使用iCustom的Supertrend,因为它是在主图上加载的,而不是在我创建的价差上。 所以,我试图按照这种方式(在一个指标中实现点差和超级趋势的所有代码)。 k3rn3l 你不能这样做(因为超级趋势取决于像ATR这样的东西--你也需要计算该价差的ATR,这是不可能的)。另外,你将当前收盘价与该价差值 进行比较,这是不符合逻辑的。这是使用ATR的结果,但正如我所说的,它并不像在原来的超级趋势中那样有意义,而且你不能比较完全不同的价值尺度(例如,收盘价与价差相比)。 附加的文件: _test.gif 29 kb _test.mq4 4 kb 1...169170171172173174175176177178179180181182183...786 新评论 原因: 取消 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
默认参数,3.0和10
默认参数,3.0和10
在这种情况下,只需替换以下一行。
with this
[PHP]ExtMapBuffer1 = iCustom(Symbol2,0,"Supertrend",3,10,0,iShift2);我假设该指标的名称是 "Supertrend"。
我不想替换,我想把超级趋势代码整合到这个指标中,而超级趋势整合是在指标ExtMapBuffer1上计算的。
我不想替换,我想把超级趋势代码整合到这个指标中,而超级趋势整合是在指标ExtMapBuffer1上计算的。
k3rn3l
我恐怕不明白 "整合 "是什么意思
你能不能多解释一下?
我的意思是像这样的事情。
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Lime
#property indicator_color3 Red
double TrendUp[], TrendDown[], ExtMapBuffer1[];
int changeOfTrend;
extern int Nbr_Periods = 10;
extern double Multiplier = 3.0;
extern double Beta1 = 1.0;
extern string Symbol2 = "GER30";
extern double Beta2 = 1.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1, TrendUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(2, TrendDown);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
IndicatorShortName(Symbol() + " " + Beta1 + " " + Symbol2 + " " + Beta2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, flag, flagh, trend[5000];
double up[5000], dn[5000], medianPrice, atr;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0) counted_bars--;
limit=Bars-counted_bars;
//Print(limit);
//----
if(Bars<1) return(0);
int j = Bars-counted_bars -1;
while(j >=0) {
int iShift2 = iBarShift(Symbol2, 0, Time[j], false);
ExtMapBuffer1[j] = Close[j] * Beta1 - iClose(Symbol2, NULL, iShift2) * Beta2;
for (i = Bars; i >= 0; i--) {
TrendUp = EMPTY_VALUE;
TrendDown = EMPTY_VALUE;
atr = iATR(NULL, 0, Nbr_Periods, i);
//Print("atr: "+atr);
medianPrice = ExtMapBuffer1[j]/2;
//Print("medianPrice: "+medianPrice);
up=medianPrice+(Multiplier*atr);
//Print("up: "+up);
dn=medianPrice-(Multiplier*atr);
//Print("dn: "+dn);
trend=1;
if (Close>up) {
trend=1;
if (trend == -1) changeOfTrend = 1;
//Print("trend: "+trend);
}
else if (Close<dn) {
trend=-1;
if (trend == 1) changeOfTrend = 1;
//Print("trend: "+trend);
}
else if (trend==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend0) {
flag=1;
//Print("flag: "+flag);
}
else {
flag=0;
//Print("flagh: "+flag);
}
if (trend>0 && trend<0) {
flagh=1;
//Print("flagh: "+flagh);
}
else {
flagh=0;
//Print("flagh: "+flagh);
}
if (trend>0 && dn<dn)
dn=dn;
if (trendup)
up=up;
if (flag==1)
up=medianPrice+(Multiplier*atr);
if (flagh==1)
dn=medianPrice-(Multiplier*atr);
//-- Draw the indicator
if (trend==1) {
TrendUp=dn;
if (changeOfTrend == 1) {
TrendUp = TrendDown;
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=up;
if (changeOfTrend == 1) {
TrendDown = TrendUp;
changeOfTrend = 0;
}
}
}
WindowRedraw();
}
//----
return(0);
}
//+------------------------------------------------------------------+
我的意思是像这样。
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Lime
#property indicator_color3 Red
double TrendUp[], TrendDown[], ExtMapBuffer1[];
int changeOfTrend;
extern int Nbr_Periods = 10;
extern double Multiplier = 3.0;
extern double Beta1 = 1.0;
extern string Symbol2 = "GER30";
extern double Beta2 = 1.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1, TrendUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(2, TrendDown);
SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
IndicatorShortName(Symbol() + " " + Beta1 + " " + Symbol2 + " " + Beta2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, flag, flagh, trend[5000];
double up[5000], dn[5000], medianPrice, atr;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0) counted_bars--;
limit=Bars-counted_bars;
//Print(limit);
//----
if(Bars<1) return(0);
int j = Bars-counted_bars -1;
while(j >=0) {
int iShift2 = iBarShift(Symbol2, 0, Time[j], false);
ExtMapBuffer1[j] = Close[j] * Beta1 - iClose(Symbol2, NULL, iShift2) * Beta2;
for (i = Bars; i >= 0; i--) {
TrendUp = EMPTY_VALUE;
TrendDown = EMPTY_VALUE;
atr = iATR(NULL, 0, Nbr_Periods, i);
//Print("atr: "+atr);
medianPrice = ExtMapBuffer1[j]/2;
//Print("medianPrice: "+medianPrice);
up=medianPrice+(Multiplier*atr);
//Print("up: "+up);
dn=medianPrice-(Multiplier*atr);
//Print("dn: "+dn);
trend=1;
if (Close>up) {
trend=1;
if (trend == -1) changeOfTrend = 1;
//Print("trend: "+trend);
}
else if (Close<dn) {
trend=-1;
if (trend == 1) changeOfTrend = 1;
//Print("trend: "+trend);
}
else if (trend==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend==-1) {
trend=-1;
changeOfTrend = 0;
}
if (trend0) {
flag=1;
//Print("flag: "+flag);
}
else {
flag=0;
//Print("flagh: "+flag);
}
if (trend>0 && trend<0) {
flagh=1;
//Print("flagh: "+flagh);
}
else {
flagh=0;
//Print("flagh: "+flagh);
}
if (trend>0 && dn<dn)
dn=dn;
if (trendup)
up=up;
if (flag==1)
up=medianPrice+(Multiplier*atr);
if (flagh==1)
dn=medianPrice-(Multiplier*atr);
//-- Draw the indicator
if (trend==1) {
TrendUp=dn;
if (changeOfTrend == 1) {
TrendUp = TrendDown;
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=up;
if (changeOfTrend == 1) {
TrendDown = TrendUp;
changeOfTrend = 0;
}
}
}
WindowRedraw();
}
//----
return(0);
}
//+------------------------------------------------------------------+
然后声明另一个缓冲区(例如ExtMapBuffer2),并使用iCustom() 检索超级趋势的值到这个新的缓冲区(像这样:
ExtMapBuffer2[i] =iCustom(Symbol2,0,"Supertrend",3,10,0,iShift2)。
谢谢 现在,我有了这个。.你能帮我纠正错误吗?
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 FireBrick
#property indicator_color3 Green
#property indicator_color4 Blue
#property indicator_width1 1
#property indicator_width2 2
#property indicator_width3 2
#property indicator_style1 STYLE_DOT
// Indicator parameters
extern int SuperTrend.Period=10;
extern double SuperTrend.Multiplier=3.0;
extern string Symbol2 = "GBPUSD";
// Global module varables
double gadUpBuf[];
double gadDnBuf[];
double gadSuperTrend[];
double Spread[];
//-----------------------------------------------------------------------------
// function: init()
// Description: Custom indicator initialization function.
//-----------------------------------------------------------------------------
int init() {
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, Spread);
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, gadSuperTrend);
SetIndexLabel(1, "SuperTrend");
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2, gadDnBuf);
SetIndexLabel(2, "SuperTrend Down");
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(3, gadUpBuf);
SetIndexLabel(3, "SuperTrend Up");
IndicatorShortName(INDICATOR_NAME+"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]");
return(0);
}
//-----------------------------------------------------------------------------
// function: deinit()
// Description: Custom indicator deinitialization function.
//-----------------------------------------------------------------------------
int deinit() {
return (0);
}
///-----------------------------------------------------------------------------
// function: start()
// Description: Custom indicator iteration function.
//-----------------------------------------------------------------------------
int start() {
int iNewBars, iCountedBars, i;
double dAtr,dUpperLevel, dLowerLevel;
// Get unprocessed ticks
iCountedBars=IndicatorCounted();
if(iCountedBars < 0) return (-1);
if(iCountedBars>0) iCountedBars--;
iNewBars=Bars-iCountedBars;
Spread = Close / iClose(Symbol2, NULL, i) ;
for(i=iNewBars; i>=0; i--) {
// Calc SuperTrend
dAtr = iATR(NULL, 0, SuperTrend.Period, i);
dUpperLevel=Spread/2+SuperTrend.Multiplier*dAtr;
dLowerLevel=Spread/2-SuperTrend.Multiplier*dAtr;
// Set supertrend levels
if (Close>gadSuperTrend && Close<=gadSuperTrend) {
gadSuperTrend=dLowerLevel;
}
else if (Close=gadSuperTrend) {
gadSuperTrend=dUpperLevel;
}
else if (gadSuperTrend<dLowerLevel)
gadSuperTrend=dLowerLevel;
else if (gadSuperTrend>dUpperLevel)
gadSuperTrend=dUpperLevel;
else
gadSuperTrend=gadSuperTrend;
// Draw SuperTrend lines
gadUpBuf=EMPTY_VALUE;
gadDnBuf=EMPTY_VALUE;
if (Close>gadSuperTrend || (Close==gadSuperTrend && Close>gadSuperTrend))
gadUpBuf=gadSuperTrend;
else if (Close<gadSuperTrend || (Close==gadSuperTrend && Close<gadSuperTrend))
gadDnBuf=gadSuperTrend;
}
return(0);
}
//+------------------------------------------------------------------+
谢谢 现在,我有了这个。你能帮我纠正错误吗?
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 FireBrick
#property indicator_color3 Green
#property indicator_color4 Blue
#property indicator_width1 1
#property indicator_width2 2
#property indicator_width3 2
#property indicator_style1 STYLE_DOT
// Indicator parameters
extern int SuperTrend.Period=10;
extern double SuperTrend.Multiplier=3.0;
extern string Symbol2 = "GBPUSD";
// Global module varables
double gadUpBuf[];
double gadDnBuf[];
double gadSuperTrend[];
double Spread[];
//-----------------------------------------------------------------------------
// function: init()
// Description: Custom indicator initialization function.
//-----------------------------------------------------------------------------
int init() {
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, Spread);
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, gadSuperTrend);
SetIndexLabel(1, "SuperTrend");
SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2, gadDnBuf);
SetIndexLabel(2, "SuperTrend Down");
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(3, gadUpBuf);
SetIndexLabel(3, "SuperTrend Up");
IndicatorShortName(INDICATOR_NAME+"["+SuperTrend.Period+";"+DoubleToStr(SuperTrend.Multiplier,1)+"]");
return(0);
}
//-----------------------------------------------------------------------------
// function: deinit()
// Description: Custom indicator deinitialization function.
//-----------------------------------------------------------------------------
int deinit() {
return (0);
}
///-----------------------------------------------------------------------------
// function: start()
// Description: Custom indicator iteration function.
//-----------------------------------------------------------------------------
int start() {
int iNewBars, iCountedBars, i;
double dAtr,dUpperLevel, dLowerLevel;
// Get unprocessed ticks
iCountedBars=IndicatorCounted();
if(iCountedBars < 0) return (-1);
if(iCountedBars>0) iCountedBars--;
iNewBars=Bars-iCountedBars;
Spread = Close / iClose(Symbol2, NULL, i) ;
for(i=iNewBars; i>=0; i--) {
// Calc SuperTrend
dAtr = iATR(NULL, 0, SuperTrend.Period, i);
dUpperLevel=Spread/2+SuperTrend.Multiplier*dAtr;
dLowerLevel=Spread/2-SuperTrend.Multiplier*dAtr;
// Set supertrend levels
if (Close>gadSuperTrend && Close<=gadSuperTrend) {
gadSuperTrend=dLowerLevel;
}
else if (Close=gadSuperTrend) {
gadSuperTrend=dUpperLevel;
}
else if (gadSuperTrend<dLowerLevel)
gadSuperTrend=dLowerLevel;
else if (gadSuperTrend>dUpperLevel)
gadSuperTrend=dUpperLevel;
else
gadSuperTrend=gadSuperTrend;
// Draw SuperTrend lines
gadUpBuf=EMPTY_VALUE;
gadDnBuf=EMPTY_VALUE;
if (Close>gadSuperTrend || (Close==gadSuperTrend && Close>gadSuperTrend))
gadUpBuf=gadSuperTrend;
else if (Close<gadSuperTrend || (Close==gadSuperTrend && Close<gadSuperTrend))
gadDnBuf=gadSuperTrend;
}
return(0);
}
//+------------------------------------------------------------------+
对不起,但我真的看不出你想做什么(似乎你想计算某种价差的超级趋势,但我无法从代码中看出)。
你为什么不从超级趋势指标本身开始(因为你似乎想改变它)?
是的,这是我想做的。
1) 创建一个2种资产之间的价差指标
2)在价差上计算超级趋势
我不能使用iCustom的Supertrend,因为它是在主图上加载的,而不是在我创建的价差上。
因此,我试图按照这种方式(在一个指标中实现所有价差和超级趋势的代码)。
是的,这就是我所要做的。
1) 创建一个2种资产之间的价差指标
2)在价差上计算超级趋势
我不能使用iCustom的Supertrend,因为它是在主图上加载的,而不是在我创建的价差上。
所以,我试图按照这种方式(在一个指标中实现点差和超级趋势的所有代码)。k3rn3l
你不能这样做(因为超级趋势取决于像ATR这样的东西--你也需要计算该价差的ATR,这是不可能的)。另外,你将当前收盘价与该价差值 进行比较,这是不符合逻辑的。这是使用ATR的结果,但正如我所说的,它并不像在原来的超级趋势中那样有意义,而且你不能比较完全不同的价值尺度(例如,收盘价与价差相比)。