Supertrend는 내가 만든 스프레드가 아닌 메인 차트에 로드되기 때문에 iCustom과 함께 사용할 수 없습니다.
그래서 저는 이 방법을 시도해 보았습니다. (스프레드의 모든 코드와 슈퍼트렌드를 하나의 지표로 구현)
k3rn3l
당신은 그렇게 할 수 없습니다(슈퍼 추세는 atr과 같은 것들에 의존하기 때문에 - 당신은 그 스프레드의 atr도 계산해야 할 것이고 그것은 불가능합니다). 또한 현재 종가를 논리적이지 않은 스프레드 값 과 비교하고 있습니다. 이것은 그 atr을 사용한 결과이지만 내가 말했듯이 원래의 슈퍼 트렌드에서와 같이 의미가 없으며 완전히 다른 척도의 값을 비교할 수 없습니다 (예를 들어 스프레드에 비해 근접 )
기본 매개변수 , 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) 스프레드에 대한 슈퍼트렌드 계산
Supertrend는 내가 만든 스프레드가 아닌 메인 차트에 로드되기 때문에 iCustom과 함께 사용할 수 없습니다.
그래서 저는 이 방법을 시도해 보았습니다. (스프레드의 모든 코드와 슈퍼트렌드를 하나의 지표로 구현)
네, 제가 하려고 하는 것은 다음과 같습니다.
1) 두 자산 간의 스프레드 지표를 만듭니다.
2) 스프레드에 대한 슈퍼트렌드 계산
Supertrend는 내가 만든 스프레드가 아닌 메인 차트에 로드되기 때문에 iCustom과 함께 사용할 수 없습니다.
그래서 저는 이 방법을 시도해 보았습니다. (스프레드의 모든 코드와 슈퍼트렌드를 하나의 지표로 구현)k3rn3l
당신은 그렇게 할 수 없습니다(슈퍼 추세는 atr과 같은 것들에 의존하기 때문에 - 당신은 그 스프레드의 atr도 계산해야 할 것이고 그것은 불가능합니다). 또한 현재 종가를 논리적이지 않은 스프레드 값 과 비교하고 있습니다. 이것은 그 atr을 사용한 결과이지만 내가 말했듯이 원래의 슈퍼 트렌드에서와 같이 의미가 없으며 완전히 다른 척도의 값을 비교할 수 없습니다 (예를 들어 스프레드에 비해 근접 )