Wszystkie pytania dozwolone początkujących programistów
Mam taki mały problem, który jest dla mnie niepojęty. Tablice w EA mi nie działają tak jak uważam, że powinny. Pewna funkcja zapisuje w tablicy EA same zera...kiedy w indykatorze działa bez zarzutu.
Przykładowo powiedzmy że mam najprostszą z możliwych funkcji.
indyk wypluwa z siebie tak "i" jak i wartość a, kiedy expert wypluwa "i", natomiast a[] zawsze wynosi zero.
gdzieś jest haczyk? [/quote]
Przykładowo powiedzmy że mam najprostszą z możliwych funkcji.
Kod: Zaznacz cały
for(int i=30;i>=0;i--)
{
a[i]=5;
Print(i," ",a[i]);
}
gdzieś jest haczyk? [/quote]
- Pierz Andrzej
- Przyjaciel Forum
- Posty: 1200
- Rejestracja: 02 lip 2006, 14:17
Kod: Zaznacz cały
//+------------------------------------------------------------------+
//| !!!.mq4 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
int a[];
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
for(int i=30;i>=0;i--)
{
a[i]=5;
Print(i," ",ssb[i]);
}
//----
return(0);
}
//+------------------------------------------------------------------+
- Pierz Andrzej
- Przyjaciel Forum
- Posty: 1200
- Rejestracja: 02 lip 2006, 14:17
nie masz podanej wielkosci tablicy ..
wiec albo :
alb przed petelka for zadeklaruj jej wielkosc
pozdrawiam
Andrzej Pierz
wiec albo :
Kod: Zaznacz cały
int a[31];
Kod: Zaznacz cały
ArrayResize(a,31);
Andrzej Pierz
z poważaniem
Andrzej Pierz
FOREX-SERVICE
Andrzej Pierz
FOREX-SERVICE
- Pierz Andrzej
- Przyjaciel Forum
- Posty: 1200
- Rejestracja: 02 lip 2006, 14:17
W indyku jak nie zadeklarujesz ze jest to bufor wsakznika to tez nie zadziala 
pozdrawiam
Andrzej Pierz

Kod: Zaznacz cały
#property indicator_buffers 1
....................
SetIndexBuffer(0,ExtMapBuffer1);
Kod: Zaznacz cały
bool SetIndexBuffer( int index, double array[])
Binds the array variable declared at a global level to the custom indicator pre-defined buffer. The amount of buffers needed to calculate the indicator is set with the IndicatorBuffers() function and cannot exceed 8. If it succeeds, TRUE will be returned, otherwise, it will be FALSE. To get the extended information about the error, one has to call the GetLastError() function.
Parameters:
index - Line index. Must lie between 0 and 7.
array[] - Array that stores calculated indicator values.
Sample:
double ExtBufferSilver[];
int init()
{
SetIndexBuffer(0, ExtBufferSilver); // first line buffer
// ...
}
Andrzej Pierz
z poważaniem
Andrzej Pierz
FOREX-SERVICE
Andrzej Pierz
FOREX-SERVICE
Witam
Mam taki wskaźnik, który posiada dwa bufory (up, down). Wyświetlany jest tylko jeden z nich, tzn jeden z dwóch kolorów. W jaki sposób wykorzystać to w EA. Chodzi mi o to, żeby EA zawierała transakcje na podstawie tych kolorów, a nie wartości buforów.
Kod wskaźnika:
//+------------------------------------------------------------------------+
//| sa#MTEI_Supertrend.mq4 |
//|http://finance.groups.yahoo.com/group/M ... ndicators/|
//+------------------------------------------------------------------------+
#property copyright ""
#property link "http://finance.groups.yahoo.com/group/M ... ndicators/"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
double TrendUp[];
double TrendDown[];
int st = 0;
//extern int SlowerEMA = 6;
//+------------------------------------------------------------------+
//| Custom indicator initialization function|
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, TrendDown);
/*SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 159);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 159);
SetIndexBuffer(1, TrendDown);*/
/*for(int i = 0; i < Bars; i++) {
TrendUp = NULL;
TrendDown = NULL;
}*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function|
//+------------------------------------------------------------------+
int deinit()
{
//----
/*for(int i = 0; i < Bars; i++) {
TrendUp = NULL;
TrendDown = NULL;
}*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function|
//+------------------------------------------------------------------+
int start()
{
int limit, i, counter;
double Range, AvgRange, cciTrendNow, cciTrendPrevious, var;
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;
for(i = limit; i >= 0; i--) {
cciTrendNow = iCCI(NULL, 0, 50, PRICE_TYPICAL, i);
cciTrendPrevious = iCCI(NULL, 0, 50, PRICE_TYPICAL, i+1);
//st = st * 100;
counter = i;
Range = 0;
AvgRange = 0;
for (counter = i; counter >= i-9; counter--) {
AvgRange = AvgRange + MathAbs(High[counter]-Low[counter]);
}
Range = AvgRange/10;
if (cciTrendNow >= st && cciTrendPrevious < st) {
TrendUp[i+1] = TrendDown[i+1];
}
if (cciTrendNow <= st && cciTrendPrevious > st) {
TrendDown[i+1] = TrendUp[i+1];
}
if (cciTrendNow >= st) {
TrendUp = Low - iATR(NULL, 0, 5, i);
if (TrendUp < TrendUp[i+1]) {
TrendUp = TrendUp[i+1];
}
}
else if (cciTrendNow <= st) {
TrendDown = High + iATR(NULL, 0, 5, i);
if (TrendDown[i] > TrendDown[i+1]) {
TrendDown[i] = TrendDown[i+1];
}
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Pozdrawiam
Mam taki wskaźnik, który posiada dwa bufory (up, down). Wyświetlany jest tylko jeden z nich, tzn jeden z dwóch kolorów. W jaki sposób wykorzystać to w EA. Chodzi mi o to, żeby EA zawierała transakcje na podstawie tych kolorów, a nie wartości buforów.
Kod wskaźnika:
//+------------------------------------------------------------------------+
//| sa#MTEI_Supertrend.mq4 |
//|http://finance.groups.yahoo.com/group/M ... ndicators/|
//+------------------------------------------------------------------------+
#property copyright ""
#property link "http://finance.groups.yahoo.com/group/M ... ndicators/"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Red
double TrendUp[];
double TrendDown[];
int st = 0;
//extern int SlowerEMA = 6;
//+------------------------------------------------------------------+
//| Custom indicator initialization function|
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, TrendDown);
/*SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 159);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 159);
SetIndexBuffer(1, TrendDown);*/
/*for(int i = 0; i < Bars; i++) {
TrendUp = NULL;
TrendDown = NULL;
}*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function|
//+------------------------------------------------------------------+
int deinit()
{
//----
/*for(int i = 0; i < Bars; i++) {
TrendUp = NULL;
TrendDown = NULL;
}*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function|
//+------------------------------------------------------------------+
int start()
{
int limit, i, counter;
double Range, AvgRange, cciTrendNow, cciTrendPrevious, var;
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;
for(i = limit; i >= 0; i--) {
cciTrendNow = iCCI(NULL, 0, 50, PRICE_TYPICAL, i);
cciTrendPrevious = iCCI(NULL, 0, 50, PRICE_TYPICAL, i+1);
//st = st * 100;
counter = i;
Range = 0;
AvgRange = 0;
for (counter = i; counter >= i-9; counter--) {
AvgRange = AvgRange + MathAbs(High[counter]-Low[counter]);
}
Range = AvgRange/10;
if (cciTrendNow >= st && cciTrendPrevious < st) {
TrendUp[i+1] = TrendDown[i+1];
}
if (cciTrendNow <= st && cciTrendPrevious > st) {
TrendDown[i+1] = TrendUp[i+1];
}
if (cciTrendNow >= st) {
TrendUp = Low - iATR(NULL, 0, 5, i);
if (TrendUp < TrendUp[i+1]) {
TrendUp = TrendUp[i+1];
}
}
else if (cciTrendNow <= st) {
TrendDown = High + iATR(NULL, 0, 5, i);
if (TrendDown[i] > TrendDown[i+1]) {
TrendDown[i] = TrendDown[i+1];
}
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
Pozdrawiam