Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 135

 
ALXIMIKS:

Good day, if it's not too difficult, please advise a newbie:

1) How to declare an array of size equal to the value of some variable? (If i=7 declare array double Muss[7] and so on);

...

1) ArrayResize()

int i=7;
double Muss[]; // объявление динамического массива
//---
int init() 
{
  ArrayResize(Muss,i); // устанавливает новый размер массива
  return(0);
}
 

such a thing:

if you call MarketInfo(Symbol(),MODE_TRADEALLOWED), it returns - 1=trade allowed.

But if you hover over symbol in market overview, tooltip with text - Trade: Close will pop up.

what's the trick here?

it really does not let me trade, but why does MODE_TRADEALLOWED return wrong value?

 
chief2000:

How many times did you run the indicator? It looks like several times (cyclicality is noticeable in your results).
Add one more print to deinit with some "separator", set input condition or redo it in the script so that it is run no more than once, then it will be clearer.


Great idea))

I made it simpler, like this:

//+------------------------------------------------------------------+
//|                                            massive_fffffffff.mq4 |
//|                                                              hoz |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""

int start()
{ 

   int Array[4] = {1, 2, 3, 4};
   int x1, x2, x3, x4;
   int Array_Size = ArrayRange(Array, 0);
   
   for(int i=0; i<11; i++)
   {
      i++;
      Print("_i = ", i);
   }

   for(x1=0; x1<Array_Size; x1++)
   {
      Print("Combination = ", Array[x1]);

      for(x2=x1+1; x2<Array_Size; x2++)
      {
         Print("Combination = ", Array[x1] + "   " + Array[x2]);

         for(x3=x2+1; x3<Array_Size; x3++)
         {
            Print("Combination = ", Array[x1] + "   " + Array[x2] + "   " + Array[x3]);

            for(x4=x3+1; x4<Array_Size; x4++)
            {
               Print("Combination = ", Array[x1] + "   " + Array[x2] + "   " + Array[x3] + "   " + Array[x4]);
            }
         }
      }
   }
  for(int h=0; h<11; i++)
   {
      h++;
      Print("h = ", h);
   }


   return(0);
}

The beginning in the logbook is like this:

2013.09.10 17:09:08     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: h = 9
2013.09.10 17:09:08     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 9
2013.09.10 17:09:08     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 7
2013.09.10 17:09:08     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 5
2013.09.10 17:09:08     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 3
2013.09.10 17:09:08     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 1
2013.09.10 17:09:07     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: h = 11
2013.09.10 17:09:07     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: h = 10
2013.09.10 17:09:07     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: h = 9
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 9
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 7
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 5
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 3
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 1
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: h = 11
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: h = 10
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: h = 9
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: Combination = 1
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 11
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 9
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 7
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 5
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 3
2013.09.10 17:09:06     2013.08.15 00:00  massive_fffffffff EURUSD.GI,M5: _i = 1
2013.09.10 17:09:06     massive_fffffffff test started
2013.09.10 17:09:04     TestGenerator: spread set to 2
2013.09.10 17:09:04     massive_fffffffff EURUSD.GI,M5: loaded successfully

There's not even any cycles at all. There is no order. The output is not consistent at all.

 
hoz:


Great idea))

I made it simpler, like this:

The beginning in the logbook is like this:

There's not even any cycles at all. There is no order. The output is not consistent at all.


You have made things a bit more complicated, at the test stage everything can be done in 1-2 lines, depending on the variant. It is possible to do everything in the Inite. The order of output has not been stipulated.


bool Status_Run = true;


start() {

   if(Status_Run==true) {
      Status_Run  = false;

      Print("---START ---");
      ......

   }
}
 
chief2000:

You made things a bit more complicated, at the check stage everything can be done in 1-2 lines, depending on variant. It is possible to do everything in the Inite. The order of output was not stipulated.





Do you mean to introduce a flag so that the loops are executed once and that's it? I don't stop executing... That's the way it works:

//+------------------------------------------------------------------+
//|                                            massive_fffffffff.mq4 |
//|                                                              hoz |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "hoz"
#property link      ""

int start()
{ 

   bool Status_run = true;
   int Array[4] = {1, 2, 3, 4};
   int x1, x2, x3, x4;
   int Array_Size = ArrayRange(Array, 0);
   
   if (Status_run == true)
   {
      Status_run = false;

      for(x1=0; x1<Array_Size; x1++)
      {
         Print("Combination = ", Array[x1]);

         for(x2=x1+1; x2<Array_Size; x2++)
         {
            Print("Combination = ", Array[x1] + "   " + Array[x2]);

            for(x3=x2+1; x3<Array_Size; x3++)
            {
               Print("Combination = ", Array[x1] + "   " + Array[x2] + "   " + Array[x3]);

               for(x4=x3+1; x4<Array_Size; x4++)
               {
                  Print("Combination = ", Array[x1] + "   " + Array[x2] + "   " + Array[x3] + "   " + Array[x4]);
               }
            }
         }
      }
   }

   return(0);
}

In essence, though, the code should work as in INITA, once and for all. Then the Boolean variable Status_run will immediately set to false and the if condition won't execute again... But my log doesn't run out of output for some reason.

 
hoz:


Do you mean to introduce a flag so that the loops execute once and that's it? I don't stop running... That's the way it works:

Although in essence, the code should work as in INITE, once and that's it. Then the Boolean variable Status_run will immediately set to false and the if condition won't execute again... But I don't run out of output in the log for some reason.


You asserted that the loops gave wrong results and I offered you a way to test it. If it works as you need then you should follow your algorithm, and if not, you should change it during check.

PS "Status_run" must be created before start(), it is a global variable.
 

Gurus, a word of advice. I set bool variable Flag=true; to start,

I open a deal

if ( condition)

{

Opn_S = true;

Flag=false;

}

There is a question about the flag, if the flag returnsfalse when opened and there is this flag in the open condition. How long is the truth or false passed to the flag kept, is it reset to zero the next day?

 
Forexman77:

Gurus, a word of advice. I set variable bool=true; to start,

I open a deal

if ( condition)

{

Opn_S = true;

Flag=false;

}

There is a question about the flag, if the flag returnsfalse when opened and there is this flag in the open condition. How long is the truth or false passed to the flag kept, will it be reset to zero the next day?


No it won't, with every new tick the value of Flag will be true . https://book.mql4.com/ru/variables/types

Either declare the variable globally - for example at the beginning of a program, outside all functions.

Or make the variable static - static bool flag=true; .

 
ALXIMIKS:

No it won't, with every new tick the value of Flag will be true . https://book.mql4.com/ru/variables/types

Either declare the variable globally - at the beginning of the program, outside all functions.

Or make the variable static - static bool flag=true; .

Thank you!
 
paladin80:
Perhaps what I understood from your question is different from what you meant. My example compares the opening prices between 3 and 2 bars, and 2 and 1. Bars 3 and 1 are not compared. In case the compared values are equal - nothing happens, just passes to the next comparison.
Why x>1 (not >=). The first iteration compares Open[3]==Open[3-1], i.e. Open[3]==Open[2]. OK. At the second (x=2), Open[2]==Open[1]. OK. There is no third iteration. At x>=1 there will be comparison Open[1]==Open[0], it is not OK, because there will be comparison with 0 bar.

Thank you very much! And if we compare the open and close prices of each of the three bars, would that change the code?
extern int n=4;
//-----------------------------------------------+
for (x=n;x>1;x--)
   {
    if(Close[x]==Open[x]) continue;
      if(Close[x]<Open[x])
     {
      action
     }
     else{
      if(Close[x]>Open[x])
     {
      action
      }
    }
   }