Creating a robot - page 2

 
Renat Akhtyamov:
Check out the codebase, there are a lot of experts out there. Examine one of them thoroughly and you'll understand. That your task can be programmed in no more than 30 minutes

depending on the task... there are templates, but they are so primitive :(

 
VVT:

depending on the task... there are templates, but they are so primitive :(

And I don't digest the porta-potties 😂
 
VVT:

Depending on the task... there are templates, but they are so primitive :(

One thing I do know is that the more primitive a programme is, the less risk of failure is there. As in mechanics, the fewer parts, the more reliable the mechanism. So, the main thing is the balance between functionality and reliability.

 
Роман Жилин:

One thing I do know is that the more primitive the programme, the lower the risk of failure. As in mechanics, the fewer parts, the more reliable the mechanism. So, the main thing is the balance between functionality and reliability.

I agree, I've already said it somewhere here, an Expert Advisor should contain the most important things needed to solve the problem, and everything else is just a pile of junk that takes up the computer's resources.

 

Here's a quick snapshot to open from the buttons

//+------------------------------------------------------------------+
//|                                                         0001.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#define    InpMagic  182979245
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
//---
CPositionInfo  m_position; // trade position object
CTrade         m_trade;    // trading object
CSymbolInfo    m_symbol;   // symbol info object
//---
input double InpLots          =0.01; // Lots
//---
double m_adjusted_point;   // point value adjusted for 3 or 5 points
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(!m_symbol.Name(Symbol())) // sets symbol name
      return(INIT_FAILED);;
//---
   m_trade.SetExpertMagicNumber(InpMagic);
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(m_symbol.Name());
//--- tuning for 3 or 5 digits
   int digits_adjust=1;
   if(m_symbol.Digits()==3 || m_symbol.Digits()==5)
      digits_adjust=10;
   m_adjusted_point=m_symbol.Point()*digits_adjust;
//---
   m_trade.SetDeviationInPoints(3*digits_adjust);
   if(!m_position.Select(Symbol()))
     {
      CheckObject();
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   if(ObjectFind(0,"BUY")==0)
     {
      ObjectDelete(0,"BUY");
     }
   if(ObjectFind(0,"SELL")==0)
     {
      ObjectDelete(0,"SELL");
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   CheckButon();
  }
//+------------------------------------------------------------------+
//| Check for long position closing                                  |
//+------------------------------------------------------------------+
bool CheckButon(void)
  {
//---
   bool res=false;
     {
      if(ObjectGetInteger(0,"BUY",OBJPROP_STATE)!=0)
        {
         ObjectSetInteger(0,"BUY",OBJPROP_STATE,0);
         double price=m_symbol.Ask();
           {
            //--- open position
            if(m_trade.PositionOpen(m_symbol.Name(),ORDER_TYPE_BUY,InpLots,price,0.0,0.0))
               printf("Position by %s to be opened",m_symbol.Name());
            else
              {
               printf("Error opening BUY position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
               printf("Open parameters : price=%f,TP=%f",price,0.0);
              }
            PlaySound("ok.wav");
           }
        }
      if(ObjectGetInteger(0,"SELL",OBJPROP_STATE)!=0)
        {
         ObjectSetInteger(0,"SELL",OBJPROP_STATE,0);
         double price0=m_symbol.Bid();
           {
            if(m_trade.PositionOpen(m_symbol.Name(),ORDER_TYPE_SELL,InpLots,price0,0.0,0.0))
               printf("Position by %s to be opened",m_symbol.Name());
            else
              {
               printf("Error opening SELL position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
               printf("Open parameters : price=%f,TP=%f",price0,0.0);
              }
            PlaySound("ok.wav");
           }
        }
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//| Check for long position closing                                  |
//+------------------------------------------------------------------+
bool CheckObject(void)
  {
//---
   bool res=false;
     {
      ObjectCreate(0,"BUY",OBJ_BUTTON,0,0,0);
      ObjectSetInteger(0,"BUY",OBJPROP_XDISTANCE,ChartGetInteger(0,CHART_WIDTH_IN_PIXELS)-102);
      ObjectSetInteger(0,"BUY",OBJPROP_YDISTANCE,37);
      ObjectSetString(0,"BUY",OBJPROP_TEXT,"BUY");
      ObjectSetInteger(0,"BUY",OBJPROP_BGCOLOR,clrMediumSeaGreen);
      ObjectCreate(0,"SELL",OBJ_BUTTON,0,0,0);
      ObjectSetInteger(0,"SELL",OBJPROP_XDISTANCE,ChartGetInteger(0,CHART_WIDTH_IN_PIXELS)-50);
      ObjectSetInteger(0,"SELL",OBJPROP_YDISTANCE,37);
      ObjectSetString(0,"SELL",OBJPROP_TEXT,"SELL");
      ObjectSetInteger(0,"SELL",OBJPROP_BGCOLOR,clrDarkOrange);
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
Files:
0001.mq5  5 kb
 
SanAlex:

Here's a quick one I made to open with buttons.

Thanks, I think I'll look into it, for starters.

 
Роман Жилин:

Thanks, I think I will study it first.

I do not recommend to fit the strategy to the EA, better the other way round. Alternatively, you could put together the necessary parts of other EAs to implement your strategy.

 
Роман Жилин:

Need the right direction for a newbie, I feel like I'm going around in circles


Guide-Forum-Stories-Compiler-Errors (and so on in a circle each time).

I think I learn something new, but I get the feeling I'm severely depressed, I cannot open even basic order when starting an EA. I need someone to shine a torch in the deepest part of the night with no paths. I'm still wandering as I've lost my way.


Completely program, on opening a trade when it starts and please clarify what's what. Help me out a lot.

Hello Roman!

There are two great articles for beginners that have helped me a lot:

https://www.mql5.com/ru/articles/481

https://www.mql5.com/ru/articles/496

Sincerely, Vladimir.

Торговые операции на MQL5 - это просто
Торговые операции на MQL5 - это просто
  • www.mql5.com
Почти все трейдеры приходят на рынок для того, чтобы заработать денег, хотя есть и доля тех, кому важен не сам торговый результат, а участие в процессе, драйв. Впрочем, получить удовольствие от процесса можно не только торгуя вручную, но и занимаясь разработкой автоматических торговых систем. Ведь создание торгового робота может быть таким же...
 
MrBrooklin:

Hello Roman!

There are two great articles for beginners that have helped me a lot:

https://www.mql5.com/ru/articles/481

https://www.mql5.com/ru/articles/496

Sincerely, Vladimir.

Vladimir, thank you. I came across the first article but the second one is exactly what I need now.


Regards, Roman.

 
Роман Жилин:

Vladimir, thank you. I stumbled upon the first article, but the second one is just what I need now.


Sincerely yours, Roman.

I am also actively using the MQL5 Reference (MQL5 Documentation tab on the MQL5 website). It contains almost all information. The only big disadvantage of this book - it is written for people who have basic knowledge of other programming languages, but not for beginners. For example, I still don't understand the sense of the constantly occurring phrase beginning with"Returns":

AccountInfoDouble

Returns value of double type of corresponding account property


Who returns, who does it return, where does it return to, why does it return? I still don't understand it.

Regards, Vladimir.

Документация по MQL5: Информация о счете / AccountInfoDouble
Документация по MQL5: Информация о счете / AccountInfoDouble
  • www.mql5.com
AccountInfoDouble - Информация о счете - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5