A question for MQL experts - page 3

 
Thank you, granit77
 
granit77:

Yes, sort of like this, if you consider that the indicator name is hilo.mq4:

extern int iR=3;
extern int SignalBar=1;
//.......
//---получение значения  HighBuffer 
double buy =  iCustom( NULL,0, "hilo",
                      iR,
                      0, // № буффера
                      SignalBar ); // № бара    
 
//---получение значения  LowBuffer
double sell =  iCustom( NULL,0, "hilo",
                      iR,
                      1, // № буффера
                      SignalBar ); // № бара

Small problem. The adviser on the indicator works. But.... Only with implementation of short trades!

i.e. at buffer number=1 and values on zero and first bar

if  (   (sell_0>Bid)  &&   (sell_1<=Bid))

the condition to sell works flawlessly.

But the Expert Advisor does not want to buy! I do not understand what is wrong! I think I have set the condition correctly. Buffer number = 0.

(  (buy0>=Ask)  &&      (buy1<Ask)  )

Not buying! Or it buys very rarely and from "the light"!

Although the lines of the indicator on the visual mode chart seems to be built correctly!


What can be the problem here?

 
rid:
granit77:

Yes, sort of like this, if you consider that the indicator name is hilo.mq4:

extern int iR=3;
extern int SignalBar=1;
//.......
//---получение значения  HighBuffer 
double buy =  iCustom( NULL,0, "hilo",
                      iR,
                      0, // № буффера
                      SignalBar ); // № бара    
 
//---получение значения  LowBuffer
double sell =  iCustom( NULL,0, "hilo",
                      iR,
                      1, // № буффера
                      SignalBar ); // № бара

Small problem. The adviser on the indicator works. But.... Only with implementation of short trades!

i.e. at buffer number=1 and values on zero and first bar

if  (   (sell_0>Bid)  &&   (sell_1<=Bid))

the condition to sell works flawlessly.

But the Expert Advisor does not want to buy! I do not understand what is wrong! I think I have set the condition correctly. Buffer number = 0.

(  (buy0>=Ask)  &&      (buy1<Ask)  )

Does not buy! Or it buys very rarely and from "the light"!

Although the lines of the indicator on the visual mode chart seems to be built correctly!


What may be the problem here?

I'm interested in this question too)).

 

Working with the custom indicator I noticed that:


// так РАБОТАЕТ !!!
int FATLsB=iCustom(NULL,0,"FATLs",0,0);
int FATLsS=iCustom(NULL,0,"FATLs",1,0);

// а вот так НЕТ ...
double FATLsB=iCustom(NULL,0,"FATLs",0,0);
double FATLsS=iCustom(NULL,0,"FATLs",1,0);


// если потом в коде есть сранвнение с 0 или 1, например
if (FATLsB==1) {CloseSell(); SetBuy(); }
 
kombat:

Working with the custom indicator I noticed that:


// так РАБОТАЕТ !!!
int FATLsB=iCustom(NULL,0,"FATLs",0,0);
int FATLsS=iCustom(NULL,0,"FATLs",1,0);

// а вот так НЕТ ...
double FATLsB=iCustom(NULL,0,"FATLs",0,0);
double FATLsS=iCustom(NULL,0,"FATLs",1,0);


// если потом в коде есть сранвнение с 0 или 1, например
if (FATLsB==1) {CloseSell(); SetBuy(); }

In the first case, there is a conversion to the target int type before the assignment operation. Therefore, the comparison condition works correctly.

For the second case we need to round floating point numbers to a specified accuracy before comparison using the

NormalizeDouble(double value, int digits)



 

Sorry...

My above example is based on a mistake.

Which was that the assignment was on the retracement price by the FATLs indicator.

I did not notice it on EURUSD and mistook "arrows appearing" for bulls 0 and 1


However, this variant corrected the situation:


bool FATLsB=iCustom(NULL,0,"FATLs",0,0)>0;
bool FATLsS=iCustom(NULL,0,"FATLs",1,0)>0;
//--- открытие БАЙ закрытие СЕЛЛ ------------------
   if (FATLsB==1 && TotalBuy()==0) {CloseSell(); SetBuy(); }
 

Good afternoon, everyone!

Please advise.

Suppose I have a slow MA and a fast MA crossed on the chart. On the first bar.

Let it then passed a few more bars.

How can I determine on what bar the last МА were crossed?

-----------------------------

I cannot even think - how should I approach the problem?

 
Rita:

Suppose I have a slow MA and a fast MA crossing on the chart. On the first bar.

Let then some more bars have passed.

How can I determine on which bar in the past the last crossing of the given MA occurred?

What is the fundamental difference for you? The crossover on the first bar can be viewed/searched the same way as on any other bar. You create a loop (e.g. from zero bar to Bars) where you look through the values of the bars and analyse them. I can't understand the point of the question....
 

I need to know on the current bar.

How many bars have passed since the last crossing of the two bars - MA_1 and MA_2.

How to arrange a loop like this?

if (MA_1>MA_2) {

 
Rita:

I need to know on the current bar.

How many bars have passed since the last crossing of the two MA_1 MA_2.

How do I do this cycle?

go from the current bar to the moment the MA changes places. and count.
Reason: