[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 104

 
Can we create an EA which closes all orders when the take-profit of the last opened order triggers?
 

Dear programmers!

Help, please. The indicator draws values on a bullish latent divergence, and does not draw a bearish latent.... It writes, that error 4002 - array index - out of range.

I seem to have fixed everything... It took me a whole evening... And it's a shame - the code is the simplest... But it's drawing bulls with arrows, but not bears... PLEASE! What's the error in?????????????????????

//+------------------------------------------------------------------+
//| div zz 5.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
#property indicator_color3 BlueViolet
#property indicator_color4 Red
#define arrowsDisplacement 0.0001
double cci[];
double cci1[];
double bullishDivergence[];
double bullishDivergence[];

//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators

SetIndexStyle(0, DRAW_NONE);
SetIndexStyle(1, DRAW_NONE);
SetIndexStyle(2, DRAW_ARROW);
SetIndexStyle(3, DRAW_ARROW);

SetIndexBuffer(0, cci);
SetIndexBuffer(1, cci1);
SetIndexBuffer(2, bullishDivergence);
SetIndexBuffer(3, bullishDivergence);

SetIndexArrow(2, 233);
SetIndexArrow(3, 234);

return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//int limit=Bars-counted_bars;
double vpadcci[];
double v[];
double hh[];
double ss[];



for (int i=500; i>=0; i--)
{
cci[i] = iCustom(NULL, 0, "CCI-OnArray_", 9, 3, 5, 25, 1, i);
if (
(cci[i]<cci[i-1])&&
(cci[i]<cci[i-2])&&
(cci[i]<cci[i+1])&&
(cci[i]<cci[i+2])
)
{
vpadcci[i]=cci[i];
ss[i]=Low[i];
}
}



for(int j=500; j>0; j--)
{
cci[j] = iCustom(NULL, 0, "CCI-OnArray_", 9, 3, 5, 25, 1, j);
if (
((cci[j+1]>vpadcci[10])&&
(cci[j]<vpadcci[10])&&
(low[j]>ss[10])) ||
((cci[j+1]>vpadcci[9])&&
(cci[j]<vpadcci[9])&&
(low[j]>ss[9])) ||
((cci[j+1]>vpadcci[8])&&
(cci[j]<vpadcci[8])&&
(low[j]>ss[8])) ||
((cci[j+1]>vpadcci[7])&&
(cci[j]<vpadcci[7])&&
(low[j]>ss[7])) ||
((cci[j+1]>vpadcci[6])&&
(cci[j]<vpadcci[6])&&
(low[j]>ss[6])) ||
((cci[j+1]>vpadcci[5])&&
(cci[j]<vpadcci[5])&&
(low[j]>ss[5])) ||
((cci[j+1]>vpadcci[4])&&
(cci[j]<vpadcci[4])&&
(low[j]>ss[4])) ||
((cci[j+1]>vpadcci[3])&&
(cci[j]<vpadcci[3])&&
(low[j]>ss[3])) ||
((cci[j+1]>vpadcci[2])&&
(cci[j]<vpadcci[2])&&
(low[j]>ss[2])) ||
((cci[j+1]>vpadcci[1])&&
(cci[j]<vpadcci[1])&&
(low[j]>ss[1])) ||
((cci[j+1]>vpadcci[0])&&
(cci[j]<vpadcci[0])&&
(low[j]>ss[0])
)

{ bullishDivergence[j] = Low[j] - arrowsDisplacement;
}
}


for (i=1; i<500; i++)
{
cci1[i] = iCustom(NULL, 0, "CCI-OnArray_", 9, 3, 5, 25, 1, i);
if
(
(cci1[i]>cci1[i-1])&&
(cci1[i]>cci1[i-2])&&
(cci1[i]>cci1[i+1])&&
(cci1[i]>cci1[i+2])
)
{
v[i]=cci1[i];
hh[i]=High[i];
}
}



for(j=1; j<500; j++)
{
cci1[j] = iCustom(NULL, 0, "CCI-OnArray_", 9, 3, 5, 25, 1, j);
if (
((cci1[j+1]<v[10])&&
(cci1[j]>v[10])&&
(high[j]<hh[10])) ||
((cci1[j+1]<v[9])&&
(cci1[j]>v[9])&&
(high[j]<hh[9])) ||
((cci1[j+1]<v[8])&&
(cci1[j]>v[8])&&
(high[j]<hh[8])) ||
((cci1[j+1]<v[7])&&
(cci1[j]>v[7])&&
(high[j]<hh[7])) ||
((cci1[j+1]<v[6])&&
(cci1[j]>v[6])&&
(high[j]<hh[6])) ||
((cci1[j+1]<v[5])&&
(cci1[j]>v[5])&&
(high[j]<hh[5])
)

{ { cci1[j]= High[j] + arrowsDisplacement;

}
}


return(0);
}



Files:
divfzzg5.mq4  5 kb
 
Transferred from a separate thread. Simple questions are recommended to be asked here. The code should be posted via the SRC button, as it is much easier to read.
<br / translate="no">.
KoDim 14.02.2011 09:29
Hello.

While programming the Expert Advisor, I was perplexed by ma_shift parameter - shift of the middle line in bars. If the shift is positive, the line shifts to the right. And vice versa, if the shift is negative, the line is shifted to the left.
If a positive value is used, an order is opened at crossing of averages.
However, if we set the parameter to negative, the order is not opened.
What has this got to do with it?

Here is an extract from the code

SMFast0=iMA( NULL, Tmfrm_work, PeriodSMFast, -3, ModeSMFast, PriceSMFast, 0 ); // МА быстрая на текущем баре
SMFast1=iMA( NULL, Tmfrm_work, PeriodSMFast, -3, ModeSMFast, PriceSMFast, 1 ); // МА быстрая на первом баре

SMSlow0=iMA( NULL, Tmfrm_work, PeriodSMSlow, 0, ModeSMSlow, PriceSMSlow, 0 ); // МА медленная на текущем баре
SMSlow1=iMA( NULL, Tmfrm_work, PeriodSMSlow, 0, ModeSMSlow, PriceSMSlow, 1 ); // МА медленная на первом баре

if(SMFast0>SMSlow0 && SMFast1<SMSlow1)

{
Opn_B=true; // Критерий откр. Buy
Cls_S=true; // Критерий закр. Sell
}

if(SMFast0<SMSlow0 && SMFast1>SMSlow1)
{
Opn_S=true; // Критерий откр. Sell
Cls_B=true; // Критерий закр. Buy
} 
 

Hello, I've been trying to learn how to write EAs for a while now, so here's a question. How can I prescribe the EA to put a stop loss after I put a stop buy or a stop loss? That is, after the stop-buy and stop sat for 5 points (roughly speaking), the EA immediately put itself a stop loss.

 
Poseidon:
Is it possible to create an EA that would close all orders when take-profit of the last opened order triggers?

You can.

Pupersa ,find this order and change the "stop loss" parameter.

KoDim, maybe because the values are shifted to the left, on the bars on the right (crossing on which you may check) they don't exist at all?

 

question to programmers: how do you make the number after the decimal point an integer?)

for example, number 1,128 needs 128, number 1,12 needs 12, number 1,2 needs 2)

The number is an external variable.

 
Question on MT5. How can I tell if the tester has completed its work? Except visually :)
 
eddy:

question to programmers: how do you make the number after the decimal point an integer?)

For example, the number 1,128 needs 128, the number 1,12 needs 12, the number 1,2 needs 2)

The number is an external variable.


see here: https://docs.mql4.com/ru/basis/operations/math
 
nemo811:


If money and volumes (and not Elliott waves) are at work in the market, and the price movement is not chaotic, but driven by volumes, then two signals on 2 pairs (out of the three considered) will give a stronger signal on the third pair. Look for order accumulation levels, analyze the VSA and you will find the required X and Y)))

In addition (see figure) a clear flat of one currency pair (formed by 2 currencies) does not prevent a third currency pair (the remaining 2 pairs) from trending. If a trend of more than 1 currency is going on, this creates a kind of "market chaos". Because intraday trends are less stable than medium- and long-term trends, this chaos is most pronounced on small TF.

Studying the market in this light, I tend to think that the trend of the currencies themselves (and not the currency pairs) is more stable, otherwise we would get an oscillator graph that cannot be analyzed at all.

That is what this picture tells me. ))))

Testing the dollar index on M1 and M5 yielded worse results than GBP/USD. Large TFs cannot be tested due to very small history archive. Fibogroup does not give much of it for Nedex, and many brokerage companies do not give it at all. That's why it's problematic to study currency trends and work with small lots (0.01) .....
 
eddy:

question to programmers: how do you make the number after the decimal point an integer?)

for example, number 1,128 needs 128, number 1,12 needs 12, number 1,2 needs 2)

The number is an external variable.

double a = 1.123345;
int b = a;
This is also possible.
Reason: