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

 
Fox_RM:

I tried to open orders on a new bar there using the NewBar() function. If it is used for this purpose?

For example if (NewBar())i++; Something like this.

I didn't notice NewBar, sorry.

Then change the following: You don't need to calculate the whole indicator every tick, if you only open trades on a new bar.

So, move the entire indicator calculation before checking conditions for opening a deal and do not count as many bars as you need (20 if I am not mistaken)


So the strategy is as follows:

1) new bar? no - walk

2) yes - calculate everything we need (MA, indicator, everything else for the conditions)

3) Check the conditions - no - walk

4) Yes - open at the current price (Ask or Bid, respectively)

 
ilunga:

NewBar didn't notice, I apologise.

Then change the following: You don't need to count the whole indicator every tick if you only open trades on a new bar.

So, move the whole indicator calculation before checking conditions of trade opening and count not as many bars, but as many as you need (20 if I am not mistaken).

That's right 20. I understand roughly how to do it. Please explain me the difference between my calculation and the calculation of 20 bars for Expert Advisors.

I just want to understand the essence of the error.

 
Fox_RM:
Good day to all!
I decided to rewrite the code of my indicator for an Expert Advisor to track
I have decided to change the code of my indicator to track the operation of its signals.
I have no errors when compiling it and it works in the Strategy Tester without errors.

I do not know how to use it.

Z.U. I am sure there are many silly mistakes, please shoot blanks.

It's easier to rewrite the code as you see it than to sort out "what are you dancing around" here, for example:

  ArrayResize(MA1,Bars);ArrayResize(MA2,Bars);

I haven't encountered how the function used in the indicators in the EA will work out:

  int counted_bars=IndicatorCounted();  

But, if "whatever", the loop you organise:

   for(i=0; i<=limit; i++) 

Where limit = Bars - counted_bars, on the 2nd tick will take a value equal to 0, then by code it will be assigned a value... OPA - and this is a NEW WORLD in programming:

  if(limit>0) limit=0;

...try writing this condition like this, if it doesn't break the whole strategy:

  if(limit<=0) limit=1;
 
Fox_RM:

I.e. use this condition for recalculation of bars?

But in my indicator, at every tick the arrays TP_UP and TP_DN are calculated.Therefore, they must be calculated first.


Again, the opening price of OP_BUY==Ask, OP_SELL==Bid.

And you have Close[i].

 
Fox_RM:

That's right 20. I understand roughly how to do this. Please explain the difference between my calculation and the calculation of 20 bars for Expert Advisor ONLY.

I just want to understand the essence of the error.

There is no error as such in calculation of the entire indicator. Just think what is faster:

1) to count Bars (approximately 10000) bars every tick

2) to count 20 bars 1 time per minute (or even more)

 
Fox_RM:
Good day to all!
I decided to rewrite the code of my indicator for an Expert Advisor to track
I have decided to change the code of my indicator to trace the processing of its signals.
I have no errors when compiling it and it works in the Strategy Tester without errors.

I do not know how to use it.

Z.I. I'm sure there are a lot of mistakes and stupid, please shoot blanks.

NOT PRINCIPAL, but to simplify the code, this construct:

  ArrayResize(TP_UP,20);ArrayResize(TP_DN,20); 
  ArrayResize(TP_UPMin,20);ArrayResize(TP_DNPl,20);

should have been replaced with a simple array declaration with dimensionality:

double delta,price,old_price,col_bar,sum_tick,sum_pip,TP_UP[20],TP_DN[20],TP_UPMin[20],TP_DNPl[20];
 
Fox_RM:

That's right 20. I understand roughly how to do this. Please explain the difference between my calculation and the calculation of 20 bars for Expert Advisor ONLY.

I just want to understand the essence of the error.

These are PRINCIPAL {FUNDAMENTAL programming principles - do not do things that do not make sense! :)))
 
Fox_RM:
And another question related to the operation of the library.
I created the library file, compiled it, everything went without errors.
I imported the function into the indicator code, compiled it, everything is OK too.
When I start the indicator, the function to be imported is not executed, when I use

indicator code, everything works. Here is the library code.

This is a call in the indicator code:

//+------------------------------------------------------------------+
//|                                                         lib1.mq4 |
//|                                         Copyright © 2012, Fox.RM |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Fox.RM"
#property link      "http://www.metaquotes.net"
#property library
//+------------------------------------------------------------------+
//| My function                                                      |
//+------------------------------------------------------------------+
double Sredn(double & ArrSr[])
{
double a=1,c,step=1/20;
for (int i=0;i<=20;i++)
{if (ArrSr[i]==0){a*=1;}else{a*=MathAbs(ArrSr[i]);}}
c=MathPow(a, step);
  return(c);
}
//+------------------------------------------------------------------+
 
Zhunko:

Vadim, you put such a small (&) that you can't see it straight away!..! :)))

I wonder how the author (in the author's version) this function was performed in one place and not in another! ;)

 
Fox_RM:

That's right 20. I understand roughly how to do this. Please explain the difference between my calculation and the calculation of 20 bars for Expert Advisor ONLY.

I just want to understand the essence of the error.

By the way, I noticed that you declare working arrays of size 20:

  ArrayResize(TP_UP,20);ArrayResize(TP_DN,20); 
  ArrayResize(TP_UPMin,20);ArrayResize(TP_DNPl,20);

And your library calculates 21 elements:

for (int i=0;i<=20;i++)

I can assume that the loop should start from 1:

for (int i=1;i<=20;i++)