[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 323

 

This is what happens:

//+-------------------------------------------------------------------------------------+
//| Расчитываем количество идущих один за одним баров одного признака                   |
//+-------------------------------------------------------------------------------------+
int LastCandlesType(int directionMA)
{
   int cntUp,                                                                           // Счётчик идущих друг за другом свечей с..
       cntDn,                                                                           // .. требуемыми признаками
       t;                                                                               // Счётчик всех просчитанных баров
       
   for (int i=i_AnyBarsToHistory; i>=1; i--, t++)
   {
      if (directionMA == CROSS_UP)                                                      // Если машки направлены вверх
      {
         if ((Open[i] - Close[i]) >= i_sizeOfSequentialCorrectionBar * pt)              // Если бар соответствует требуемым признакам..
             cntDn++;                                                                   // .. прибавим 1 к счётчику
         if ((Close[i] - Open[i]) >= i_sizeOfTrandBar * pt)                             // Если бар, не соответствует основному признаку..
             cntDn = 0;                                                                 // .. счётчик обнуляем
                                                                                        
         if (i == 1)
            Print(" directionMA ", directionMA, "; i = ", i, "; Open[i] - Close[i] = ", Open[i] - Close[i], "; cntDn = ", cntDn);

         if (t == i_AnyBarsToHistory)
         {
             if (cntDn == i_sequentBarsСount)                                                // Если cnt баров в подряд медвежьи..
                 return (REQUIRED_SEQUENTIAL_BEARS_GOT);                                     // .. Выходим из функции
         }
      }

      if (directionMA == CROSS_DN)                                                      // Если машки направлены вниз
      {
         if ((Close[i] - Open[i]) >= i_sizeOfSequentialCorrectionBar * pt)              // Если бар соответствует требуемым признакам..
             cntUp++;                                                                   // .. прибавим 1 к счётчику
         if ((Open[i] - Close[i]) >= i_sizeOfTrandBar * pt)                             // Если бар, не соответствует основному признаку..
             cntUp = 0;                                                                 // .. счётчик обнуляем
         if (i == 1)
            Print(" directionMA ", directionMA, "; i = ", i, "; Close[i] - Open[i] = ", Close[i] - Open[i], "; cntUp = ", cntUp);

         if (t == i_AnyBarsToHistory)
         {
             if (cntUp == i_sequentBarsСount)                                                // Если cnt баров в подряд бычьи..
                 return (REQUIRED_SEQUENTIAL_BULLS_GOT);                                     // .. Выходим из функции
         }
      }
      return (REQUIRED_SEQUENTIAL_MISS);
   }
}

In fact, not even a line is printed:

Print(" directionMA ", directionMA, "; i = ", i, "; Close[i] - Open[i] = ", Close[i] - Open[i], "; cntUp = ", cntUp);

So there's probably some kind of bug in the above.

The most interesting thing is that once I added a default return here, it somehow works all the time. I mean the string:

return (REQUIRED_SEQUENTIAL_MISS);

Although it's obvious that the code is elementary, and there can't be any errors there.

 

Greetings all! Dear gurus, could you tell me why v_s increases and decreases when profit increases and decreases in the deposit currency?

value_profit() is a profit calculation in the deposit currency.

double value_stop,value_step;
value_stop=((AccountBalance()/100)*1);
value_step=((AccountBalance()/100)*4);
double v_s;
if (value_profit()>=(value_step+value_stop))
for (int v=1;v<=100;v++)
{
if (value_profit()>=(value_step+(value_stop*v))
{
v_s=value_stop*v;
}
else
{
if (value_profit()<=v_s)
close_all();
}
}
 
hoz:

In fact, not even a line is printed:

1. Why do modularity exactly at once? Of course, everyone has their own style, but I would first polish the compact version, and then, when it works like clockwork, move it to modularity. Compact variant (without inserted functions Trade, LastCandlesType, GetStateOfMA, GetGeneralSignal) was shown as a variant of start() internals on the previous page. How does it work for you? If it works, then split it into modules.

2. The code seems to me to be absolutely identical to the previous one, since the t counter changes absolutely parallel to the i counter. Why then compare with t if you can compare with i? And, going by logic further, then why compare with i if we have code that didn't work?

3. Sorry to intrude, but how would this variant work with taking the output out of the loop?

int LastCandlesType(int directionMA){
        int cntUp, cntDn;
        for (int i=i_AnyBarsToHistory; i>=1; i--){
                if (directionMA == CROSS_UP){
                        if ((Open[i] - Close[i]) >= i_sizeOfSequentialCorrectionBar * pt) cntDn++; else cntDn=0;
                        if (i == 1) Print(" directionMA ", directionMA, "; i = ", i, "; Open[i] - Close[i] = ", Open[i] - Close[i], "; cntDn = ", cntDn);
                }
                if (directionMA == CROSS_DN){
                        if ((Close[i] - Open[i]) >= i_sizeOfSequentialCorrectionBar * pt) cntUp++; else cntUp=0;
                        if (i == 1) Print(" directionMA ", directionMA, "; i = ", i, "; Close[i] - Open[i] = ", Close[i] - Open[i], "; cntUp = ", cntUp);
                }
        }
        if ((directionMA==CROSS_UP)&&(cntUp>=i_sequentBarsСount)) return(REQUIRED_SEQUENTIAL_BEARS_GOT);
        if ((directionMA==CROSS_DN)&&(cntDn>=i_sequentBarsСount)) return(REQUIRED_SEQUENTIAL_BULLS_GOT);
        return(REQUIRED_SEQUENTIAL_MISS);
}

I understand that it may not work either, whatever, but I need to be sure about it to figure it out further.

4. Purely my personal adaptation: type code not in meta editor, but in any other editor with numbered lines, and print on every change of any variable and on every if or switch check, in the same line (after last semicolon). Print in line number - value(s) to be checked. Print it after if(tracing) {Print(StringConcatenate("line_number: variable_name=", variable_name));} and declare a variable in the header, like: bool tracing=false;//enable tracing. In this case you'll have a full-fledged tracing and therefore full-fledged debugging. But you have to clean up the logs more often, of course. If you are going to use the meta editor directly, you may first make an empty template like

/*001*/

...

/*999*/

at the beginning of lines (and it works), and then in a copy of this template to type code. But this is just what I think, in practice I tried it that way, but I tried it inconsistently.

 
rajak:

Greetings all! Dear gurus, could you tell me why v_s increases and decreases when profit increases and decreases in the deposit currency?

value_profit() is a profit calculation in the deposit currency.

double value_stop,value_step;
value_stop=((AccountBalance()/100)*1);
value_step=((AccountBalance()/100)*4);
double v_s;
if (value_profit()>=(value_step+value_stop))
for (int v=1;v<=100;v++)
{
if (value_profit()>=(value_step+(value_stop*v))
{
v_s=value_stop*v;
}
else
{
if (value_profit()<=v_s)
close_all();
}
}
After a quick look, I immediately saw a bug with inverted commas. Teach how to use the if statement.
 
gyfto:

3. Sorry to pry, but how would it work for you to take the output out of the loop after all?

int LastCandlesType(int directionMA){
        int cntUp, cntDn;
        for (int i=i_AnyBarsToHistory; i>=1; i--){
                if (directionMA == CROSS_UP){
                        if ((Open[i] - Close[i]) >= i_sizeOfSequentialCorrectionBar * pt) cntDn++; else cntDn=0;
                        if (i == 1) Print(" directionMA ", directionMA, "; i = ", i, "; Open[i] - Close[i] = ", Open[i] - Close[i], "; cntDn = ", cntDn);
                }
                if (directionMA == CROSS_DN){
                        if ((Close[i] - Open[i]) >= i_sizeOfSequentialCorrectionBar * pt) cntUp++; else cntUp=0;
                        if (i == 1) Print(" directionMA ", directionMA, "; i = ", i, "; Close[i] - Open[i] = ", Close[i] - Open[i], "; cntUp = ", cntUp);
                }
        }
        if ((directionMA==CROSS_UP)&&(cntUp>=i_sequentBarsСount)) return(REQUIRED_SEQUENTIAL_BEARS_GOT);
        if ((directionMA==CROSS_DN)&&(cntDn>=i_sequentBarsСount)) return(REQUIRED_SEQUENTIAL_BULLS_GOT);
        return(REQUIRED_SEQUENTIAL_MISS);
}

Hm. It worked. I ran several "screens" in the visual, everything is clear at this interval. I still need to understand why it didn't work last time. It will be useful to avoid tripping over it in the future.
 
hoz:

Hmm, it's working.


Glad))))

hoz:

Still need to figure out why it didn't work last time. It will be useful to avoid tripping over it in the future.

Because in the future, don't quit for before you get to Close[0] or whatever the window boundary is in any other algorithm. It's not while.

 
gyfto:

1. Why do modularity all at once? Of course, everyone has his own style, but I would first polish the compact version, and then, when it works like clockwork, switch it to modularity. Compact variant (without inserted functions Trade, LastCandlesType, GetStateOfMA, GetGeneralSignal) was shown as a variant of start() internals on the previous page. How does it work for you? If it works, then split it into modules.

Actually, I'm used to writing it that way. And it's easier to look for errors. Because I knew at once that the error was in functionLastCandlesType(). But I haven't found out the reason yet, though your way worked.

gyfto:

2. The code seems to me to be absolutely identical to the previous one, since the t counter changes absolutely parallel to the i counter. Why then compare with t if you can compare with i? And, going by logic further, then why compare with i if we have code that didn't work?

Too late to write, ... moral overload, I guess.

gyfto:

I understand that it may not work either, whatever, but I need to make sure it does in order to understand it further.

It works! What remains to be understood is why that code didn't work. The first thing that caught my eye was the exit from the function when the counter reaches the value i_seqqtBarstCounter. But, again, I printed and the counter value only showed 1 all the time, when I placed the default exit from functionreturn(REQUIRED_SEQUENTIAL_MISS);

Before I placed it, everything was calculated correctly, but the owl wasn't trading correctly. There was nothing at all going on. Although, in theory, if none of the conditions above the default output worked, it means that none of the conditions has triggered and even if we place the default output in the condition it should not work. Conversely, if the condition holds, it should hold.


gyfto:

4. Purely my personal adaptation: type the code not in meta-editor, but in any other editor with line numbering, and print on every change of any variable and on every if or switch check, on the same line (after the last semicolon). Print in line number - value(s) to be checked. Print it after if(tracing) {Print(StringConcatenate("line_number: variable_name=", variable_name));} and declare a variable in the header, like: bool tracing=false;//enable tracing. In this case you'll have a full-fledged tracing and therefore full-fledged debugging. But you have to clear the logs more often, of course. If you are going to use the meta editor directly, you may first make an empty template like

/*001*/

...

/*999*/

at the beginning of lines (and it works), and then in a copy of this template to type code. But this is just what I think, in practice I tried it that way, but tried it inconsistently.


Well, we print on the basis of Expert Advisor data, not line numbers. Why do you need line numbers? I personally use it for code analysis since there are really handy moments there. But to write and debug the code relying on line numbers is nonsense to me.
 
hoz:

It remains to be seen why that code didn't work.


The way I figured it out myself. We read the crossings of the flaps. More precisely, three bullish or bearish candlesticks after crossing at any moment. When the condition is fulfilled, we enter the market. But judging by the verbal description, these three or more candlesticks coming in a row belong to the right border of the window. According to your code, they can refer to the middle of the window. Therefore, the Expert Advisor has entered the market when the condition (three candlesticks) has been reached, while the last candlestick can be not the last one.
 
gyfto:

As I figured it out myself. We read the intersection of the bears. To be more exact, three bullish or bearish candlesticks after crossing at any moment. When the condition is fulfilled, we enter the market. But judging by the verbal description, these three or more candlesticks coming in a row belong to the right border of the window. According to your code, they can refer to the middle of the window. Therefore, the EA will enter the market when the condition (three candles) is reached, but the last candle may be not the last one.


The conclusion is as follows: knowing the syntax, we must also watch the logic. This is very important. I had just a logical error there.

It seems simple, but I got hung up on something and didn't get it right away. Yikes. It happens... :(

 

Good afternoon!

My question will be a little off-topic.

Can you please tell me if it is possible to find somewhere the slicing of TA shapes as CSV files? I can use txt, xls or any other formats that can be processed programmatically.

There are examples of TA figures in various TA articles, textbooks, but of course as ordinary pictures. Has anybody got more or less big sets of TA symbols saved as a slice of history of some currency pair on the periods H1-H4, say?

I googled, did not find any. Of course, we can manually go through the history, mark the shapes, export this piece of history as .csv; repeat the required number of times, collect the shape base in the end. But if someone has already done this, would like to save time.

Thanks in advance :)

Reason: