Hilfe bei der Codierung - Seite 176

 

Standardparameter, 3.0 und 10

 
k3rn3l:
Standardparameter, 3.0 und 10

In diesem Fall ersetzen Sie einfach die folgende Zeile:

ExtMapBuffer1 = Close * Beta1 - iClose(Symbol2, NULL, iShift2) * Beta2;[/PHP]

with this

[PHP]ExtMapBuffer1 = iCustom(Symbol2,0,"Supertrend",3,10,0,iShift2);

Ich gehe davon aus, dass der Name des Indikators "Supertrend" ist

 

Ich don ' t wollen zu ersetzen, ich möchte die supertrend Code in diesem indicatore zu integrieren, und supertrend integriert wird auf den Indikator ExtMapBuffer1 berechnet...

 
k3rn3l:
Ich will nicht ersetzen, ich will die supertrend Code in diesem Indikator zu integrieren, und supertrend integriert wird auf den Indikator ExtMapBuffer1 berechnet...

k3rn3l

Ich fürchte, ich verstehe nicht, was "integrieren" bedeutet.

Könnten Sie mir das genauer erklären?

 

Ich meine so etwas wie das hier:

#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);

}

//+------------------------------------------------------------------+

 
k3rn3l:
Ich meine etwas wie dies:

#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);

}

//+------------------------------------------------------------------+

Dann deklarieren Sie einen weiteren Puffer (z. B. ExtMapBuffer2) und verwenden iCustom(), um die Werte des Supertrends in diesen neuen Puffer zu übertragen (etwa so:

ExtMapBuffer2[i] =iCustom(Symbol2,0,"Supertrend",3,10,0,iShift2);

 

Vielen Dank Jetzt habe ich das... Können Sie mir helfen, die Fehler zu korrigieren?

#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:
Vielen Dank Jetzt habe ich das... Können Sie mir helfen, die Fehler zu korrigieren?

#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);

}

//+------------------------------------------------------------------+

Sorry, aber ich kann wirklich nicht sehen, was Sie versuchen, zu machen (es scheint, als ob Sie versuchen, Super-Trend einer Art von einer Ausbreitung zu berechnen, aber ich kann ot aus dem Code sagen)

Warum fangen Sie nicht mit dem Super-Trend-Indikator selbst an (da es scheint, dass Sie versuchen, ihn zu ändern)?

 

Ja, das ist es, was ich zu tun versuche:

1) Erstellen eines Indikators für den Spread zwischen 2 Vermögenswerten

2) Berechne den Supertrend für den Spread

Ich kann den Supertrend nicht mit iCustom verwenden, weil er auf dem Hauptchart geladen wird und nicht auf dem von mir erstellten Spread.

Also habe ich versucht, diesen Weg zu gehen (den gesamten Code des Spreads und des Supertrends in einem Indikator zu implementieren)

 
k3rn3l:
Ja, genau das versuche ich zu tun:

1) Erstellen eines Indikators für den Spread zwischen 2 Vermögenswerten

2) Berechnen Sie den Supertrend auf dem Spread

Ich kann den Supertrend mit iCustom nicht verwenden, da er auf das Hauptdiagramm geladen wird und nicht auf den von mir erstellten Spread.

Ich habe also versucht, diesen Weg zu gehen (den gesamten Code des Spreads und des Supertrends in einem Indikator zu implementieren)

k3rn3l

Das ist nicht möglich (da der Supertrend von Dingen wie der Atr abhängt - Sie müssten auch die Atr des Spreads berechnen und das ist nicht möglich). Außerdem vergleichen Sie den aktuellen Schlusskurs mit diesem Spread-Wert, was nicht logisch ist. Das ist das Ergebnis, wenn man den atr-Wert verwendet, aber wie ich schon sagte, hat er keine Bedeutung wie im ursprünglichen Supertrend, und man kann keine Werte aus einer völlig anderen Werteskala vergleichen (Close im Vergleich zum Spread, zum Beispiel)

Dateien:
_test.gif  29 kb
_test.mq4  4 kb
Grund der Beschwerde: