I have never studied programming, but I want to write an EA - page 8

 

so what's up, fellow programmers?
i am the author of this thread and i keep asking for advice.


so in the header declared structure

and here's the interesting part: WHAT IS THIS?
I defined a condition in OnTick that if there are no open orders
then:
if a fast swing is greater than a slow swing,
then: open an order.



question. why does an order open on every tick?

 
Sergey Lobzankin:

So what's up, fellow programmers?
I am the author of this thread and I keep asking for advice.


So I declared the structure in the header

and here is the interesting thing, WHAT IS THIS?
I defined a condition in OnTick that if there are no open orders
then:
if a fast swing is greater than a slow swing,
then: open an order



question. why does an order open on every tick?

It means that on every tick the condition is met.

If the condition should be a MA crossing, then on the first bar it was < less and on the zero bar it became > more. But in your condition on the zero bar > more and on the first bar > more.

 

https://code.org/

https://scratch.mit.edu/

If you want to learn programming (it's really a style of thinking, not a language) in MQL - that's a real hassle for yourself and your surroundings.

Click on the links - everything is simple, school-level (even elementary in some places), but at least some introduction to algorithms and writing them down. Otherwise, every time you sneeze, you will contact the forum and wait for an answer, and that's a waste of time, and time is money.

PS/ and I advise everyone to read it, scratch is a masterpiece from the inside - the granddaddy of modern programming.

Code.org: Любой может научиться
Code.org: Любой может научиться
  • code.org
Каждый студент в каждой школе заслуживает возможность изучения компьютерных наук.
 
Sergey Lobzankin:

So what's up, fellow programmers?
I am the author of the topic and continue to ask for advice.


so in the header announced the structure

and here's the interesting thing, WHAT IS THIS?
I have defined a condition in OnTick that if there are no open orders
then:
if a fast swing is greater than a slow swing,
then: open an order.



question. why does an order open on every tick?

So, comrade author of the topic?

I advised you a month ago, but you are not even paying attention:

This is the forum for trading, automated trading systems and testing of trading strategies.

I've never studied programming, but I want to write an Expert Advisor.

Alexey Volchanskiy, 2018.04.10 17:47

There is a button "Code", to the left of the button with letters Aa. If you do not know how to use it, you may use it for example, for example, to post your own code.)


This is a forum for trading, automated trading systems and strategy testing.

I have never studied programming, but I want to write an Expert Advisor.

Konstantin Nikitin, 2018.04.10 21:18

Well, you don't have anything super natural there. So the best option. Post it here, but only through

Someone will suggest something useful.


And you still paste code with an image.

 
Hello, I have run into the following problem. The EA needs moving average data on zero and the first bar to analyze the situation and for further calculations.
The OnCalculate function was basically invented to write an indicator. I have made this function separate in my EA, but I can't figure out how to access it from OnTick.
 
Sergey Lobzankin:
Hello, I have encountered such a problem. The Expert Advisor needs moving average data on zero and the first bar to analyze the situation and for further calculations.
The OnCalculate function was basically invented to write an indicator. I put this function in an EA separately, but I can't give an idea how to access it from OnTick

You don't even need to try to take OnCalculate from an indicator into an EA! You just need to apply to the indicator in the EA (using the indicator handle) and get the data.

Example of working with iMA and iStdDev iniMA codeiStdDev- code extracted from OnTick, getting data from iMA indicators

   double ma_fast[],ma_normal[],stddev[];
   MqlRates rates[];
   ArraySetAsSeries(ma_fast,true);
   ArraySetAsSeries(ma_normal,true);
   ArraySetAsSeries(stddev,true);
   ArraySetAsSeries(rates,true);
   int buffer=0,start_pos=0,count=3;
   if(!iGetArray(handle_iMA_Fast,buffer,start_pos,count,ma_fast) || 
      !iGetArray(handle_iMA_Normal,buffer,start_pos,count,ma_normal) || 
      !iGetArray(handle_iStdDev,buffer,start_pos,count,stddev) || 
      CopyRates(m_symbol.Name(),Period(),start_pos,count,rates)!=count)
     {
      PrevBars=0;
      return;
     }
//---
   if(ma_fast[0]>ma_normal[0])
      if(rates[1].close>rates[1].open)
         if(rates[1].close>ma_normal[0])
            if(stddev[0]>stddev[1])
               m_need_open_buy=true;
   if(ma_fast[0]<ma_normal[0])
      if(rates[1].close<rates[1].open)
         if(rates[1].close<ma_normal[0])
            if(stddev[0]>stddev[1])
               m_need_open_sell=true;
 
Vladimir Karputov:

You don't even need to try to take OnCalculate from the indicator to the EA! You just need to apply to the indicator in the Expert Advisor (using the indicator handle) and get the data.

Example of working with iMA and iStdDev iniMA codeiStdDev- code extract from OnTick, getting data from iMA indicators

i suspect you're damn right))))
now i'll try to play with arrays via ...Array...

 

And here's the other thing...
I got the handles right in the expert's hat

extern int    zazor      = 0;
extern double Lots       = 0.1;
extern int    TrailingStop = 15;
extern int    TrailingStep = 2;
extern int    Magic      = 123;
extern int    Slippage   = 5;
int Digits;

int timeprev=0;

int    ticket;
double price,TP,SL,lastlot;
string;

int ima1_handle          = iMA (Symbol(),0,14,0,MODE_EMA,PRICE_CLOSE);               //хендл
int ima2_handle          = iMA (Symbol(),0,64,0,MODE_EMA,PRICE_CLOSE);               //хендл
int Stoch_handle         = iStochastic (Symbol(),0,20,15,15,MODE_EMA,STO_CLOSECLOSE);//хендл
int ATR_handle           = iATR        (Symbol(),0,21);                              //хендл
double ima1_massiv [2];                                                              //статический массив для быстрой машки 

and on the forums, who's doing it... Everyone does it differently? Some in oninit, some in ontik,
It's just that when I use OnTick, I copy the data into an array and get the number of elements to be copied

void OnTick()
  { 
    int ima_count1 = CopyBuffer(ima1_handle,0,1,2,ima1_massiv);    //скопировал данные из 2х буферов быстрой машки
    string str_ima1 = IntegerToString(ima_count1);                 //отладочная
    printf("мой первый хендл = "  + str_ima1);                     //отладочная
   }
P.S., by the way, the tester saw all indicators whose handles are received in the EA header and drew everything on the visualizer chart
 

here is an article that clearly explains how to implement access to the indicator data
https://www.mql5.com/ru/articles/43

But guys, the data is copied into an array, no doubt, but I need to get specific numbers, that is, if the wave on the last tick of the current bar is 1.32456, then I need to get this number in the log (to make sure that the number is actually obtained), I need to take out this specific information in the double type,

to calculate the number of points of int type between two different mashes. how do i get this value?


Способы вызова индикаторов в MQL5
Способы вызова индикаторов в MQL5
  • www.mql5.com
В MQL5 существует несколько вариантов вызова индикаторов, и осуществляются они в основном при помощи функций IndicatorCreate() и iCustom(). Причем эти функции лишь возвращают хендл индикатора, и дальнейшая работа с индикаторами ведется именно через него. Так что же такое хендл? Как работать с функциями IndicatorCreate() и iCustom()? И как...
 
Sergey Lobzankin:

Here is an article that clearly explains how to implement access to the indicator data
https://www.mql5.com/ru/articles/43

But guys, the data is copied into an array, no doubt, but I need to get specific numbers, i.e. if the wave on the last tick of the current bar is 1,32456, I need to get this number in the log (to make sure the number is actually obtained), I need to take out this specific information in the double type,

to calculate the number of int points between two different mash-ups. how do you get this value?


Do you even look and read what you are told? I gave you an example in post. It's just getting data from two iMAs:

   double ma_fast[],ma_normal[],stddev[];
   MqlRates rates[];
   ArraySetAsSeries(ma_fast,true);
   ArraySetAsSeries(ma_normal,true);
   ArraySetAsSeries(stddev,true);
   ArraySetAsSeries(rates,true);
   int buffer=0,start_pos=0,count=3;
   if(!iGetArray(handle_iMA_Fast,buffer,start_pos,count,ma_fast) || 
      !iGetArray(handle_iMA_Normal,buffer,start_pos,count,ma_normal) || 
      !iGetArray(handle_iStdDev,buffer,start_pos,count,stddev) || 
      CopyRates(m_symbol.Name(),Period(),start_pos,count,rates)!=count)
     {
      PrevBars=0;
      return;
     }
//---
   if(ma_fast[0]>ma_normal[0])
      if(rates[1].close>rates[1].open)
         if(rates[1].close>ma_normal[0])
            if(stddev[0]>stddev[1])
               m_need_open_buy=true;
   if(ma_fast[0]<ma_normal[0])
      if(rates[1].close<rates[1].open)
         if(rates[1].close<ma_normal[0])
            if(stddev[0]>stddev[1])
               m_need_open_sell=true;

There are two iMA indicators - "Fast" and "Normal". The data from these two indicators is obtained in arraysma_fast andma_normal respectively. We requestcount of #start_pos from the bar.

And then we access the obtained data (in this example we access data on bar #0)

Reason: