[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 27

 
Code:


OK, let's try another way of looking at it.

vteor12 can be written as (dVolume+vback1)/k1 (factor 1)

vrealUP12 can be written as (dVolume+vback1)/k2 (coefficient 2)

As I tried to describe the indicator ideology, it consists in comparison of some theoretical and actual levels. To obtain these levels I compare (i.e. divide) the same value (dVolume+vback1) with some theoretical value (k1) and actual value (k2). It's clear that k1 I'm just making it up, to put things in their proper names. Or, if you like, making an assumption. Now this has to be compared to something. Nothing is more objective and true than the graph itself in this case. So I take the opening and closing differences, taking them as the bottom line of a given time period. And the only task here is to bring it to the same digit, which is why it is multiplied by 1000.

Try to calculate several different variants of neighbour candlesticks on a calculator and you may be surprised by the variety of results according to this very simple formula.

And in terms of school logic you are right. I add Volume + Volume/Price, you can't do that at school. :))

I'll pass... :)))

Didn't you initially have a problem with the display? Did you solve it?

 
MaxZ:

I'll pass... :)))

Didn't you initially have some problem with the display? Did you solve it?


Yes, I did, by the way. I didn't take into account that it was a line, not a histogram. The line should have 2 points. Since the code does not describe all variants, but only 2 candles rising in a row, in the case when after the second rising candle was a down candle, the indicator did not draw anything. And it was right. When I figured it out, I modified it to a histogram.

By the way, do not take my reasoning about the rules of addition and subtraction to heart. :)))

And I would be very grateful if you could help me to continue the code. It was the very beginning. After two candlesticks in a row I would like to count 3, 4 etc. candlesticks in a row by the same principle. Apparently, the code should be looped, with the search of candlesticks, right? I can't do it yet. But don't get hung up on what is divided by what. :)))

 

Ported from

VladimirR 29.07.2011 23:02 am Correction | delete

Hello. I finally wrote my first EA! I do not quite understand how it works. The EA sets 2 pending orders when certain conditions are met. Stop loss for both orders is equal to High[1] (Low[1]) for the pending sell(buy) order and take profit is always equal to pips for the stop loss. I have noticed in the strategy tester that the profit does not always equal the stop loss in pips. Please advise how this can happen. This is the code where stop orders are calculated (there is no other place in the program where stops are changed)

//-2-анализ на установку buystop---------------------------------------------------------------------------------+
  if(Close[1]>=MA_17 && MA_3<=MA_17)
   {
    deposit_order=true;
    type_order =4;
    open_price =High[1];
    stop_loss  =Low[1];
    take_profit=NormalizeDouble(MathAbs(2*open_price-stop_loss),Digits);
    if(Lot==0) Lot=MarketInfo(symb,MODE_MINLOT);
   }
 //-3-анализ на установку sellstop-------------------------------------------------------------------------------+  
  if(Close[1]<=MA_17 && MA_3>=MA_17)
    {
     deposit_order=true;
     type_order   =5;
     open_price   =Low[1];
     stop_loss    =High[1];
     take_profit  =NormalizeDouble(MathAbs(2*open_price-stop_loss),Digits);
     if(Lot==0)Lot=MarketInfo(symb,MODE_MINLOT);
    }

 
nadya:
Hi, could you please tell me, is it possible to assign values to multiple global variables within a function, and where do these variables need to be declared in that case?

You can.

Declare variables globally - before the start() function. Inside the EA functions, change their values as you want - after returning from the function, these variables will have the values you assigned them inside your functions until you change them again somewhere.

 
nadya:
good afternoon! could you please tell me if it's possible to assign a value to multiple global variables within a function, and where do these variables need to be declared in that case?

Example. Inside the myfunction, we assign a value to two global variables. You can also assign a value to three, four or n variables in this way.

int global1 = 1;
int global2 = 2;

void myfunction(int g1, int g2)
{
   global1 = g1;
   global2 = g2;
}

int start()
{
   // До выполнения функции:     global1=1, global2=2   <---  то что объявили в начале кода
   
   myfunction(3, 4);
   
   // После выполнения функции:  global1=3, global2=4   <---  то что присвоили в функции
}

But I think there's a catch in your question...

 
Code:


Yes, by the way, I have sorted it out myself. I didn't take into account that it's a line, not a histogram. And the line requires 2 points. Since the code does not describe all variants, but only 2 candles rising in a row, in the case when after the second rising candle was a down candle, the indicator did not draw anything. And it was right. When I figured it out, I converted it to a histogram.

You, by the way, don't take my reasoning about the rules of addition and subtraction to heart, think of it as an experiment. :)))

And I would be very grateful if you could help me to continue the code. It was the very beginning. After two candlesticks in a row I would like to count 3, 4 etc. candlesticks in a row by the same principle. Apparently, the code should be looped, with the search of candlesticks, right? I can't do it yet. But don't get hung up on what is divided by what. :)))

Yes. But the best way to solve this problem is to use a loop with post precondition "while" instead of a loop with counter "for". Because you do not know how many bullish or bearish candlesticks you will encounter in a row.

Start with a simpler problem, if you find it so difficult. For example, display the numbers from a to b in increments of s. Or find the factorial of n with a loop.

And to practice, solve these problems using both types of loops ("for" and "while"). Then you can start to improve your indicator.

 

There are no post-while loops in the language, MaxZ.

Your desire to help others is commendable, but you still need to know the language better yourself.

 
Mathemat:
There are no post-while loops in the language.

If you organise the loop as follows, you will get just the right postcondition:

int i = 0;
while (True)
{
   i++;
   if (i == 10) break;
}

But I accept your correction. Thank you. Since there are indeed two loop types in MQL4: "for" (with a counter) and "while" (with a precondition). The third type (with a postcondition) can be organized only intentionally.


Mathemat:

Your desire to help others is commendable, but you still need to know the language better yourself.

What I don't know, I do not go there.

And all the other mistakes were made inadvertently. I've been distracted lately... I just want to help people.

 

MaxZ: Единственная проблема состоит в том, что если советник с данным кодом запустить в тестере, а переменной PERIOD присвоить значение PERIOD_M1, то обе функции iBarShift возвращают -1, т.е. функции не удалось найти в истории бар на ТФ M1 с таким временем... Почему так происходит, не знаю.

Most likely, this function is not modelled in the tester (didn't check). Especially since exact (the fourth function parameter) is set to false by default.
 
Mathemat:
Most likely, this function is not modelled in the tester (didn't check). Especially as exact (the fourth function parameter) is set to false by default.
I've already figured it out... The problem was with the history. There was no history of M1 bars for the period being tested.
Reason: