I will write an advisor free of charge - page 161

 

Hello all! Who can write an indicator on 2 rays with a binding to the current price?

In general: at a certain distance from the price (Bid and Ask) are placed two horizontal rays - one below, the other above. The distance can be set in the indicator settings. Thank you!

 
Radmir Serebrennikov #:

Hello all! Who can write an indicator on 2 rays with a binding to the current price?

In general: at a certain distance from the price (Bid and Ask) are placed two horizontal rays - one below, the other above. The distance can be set in the indicator settings. Thank you!

Code: Dynamic High and Low

Dynamic High and Low

Figure 1: Dynamic High and Low

Dynamic High and Low
Dynamic High and Low
  • www.mql5.com
Индикатор без индикаторных буферов - просто две линии на постоянном расстоянии от цены
 
Vladimir Karputov #:

Code: Dynamic High and Low


Fig. 1. Dynamic High and Low

THANK YOU SO MUCH!!!
 
Can someone write a scriptor in mt5, which, after running, gives a list of available instruments with bdb bar? Bdb bar, it is also reversal, with a minimum below the previous and closing in the top 30% and vice versa, above and closing in the bottom 30%. There are about 3 thousand instruments.
 
Salud! A need has arisen to make trades using data from a file. In essence, a bot that takes a pair from a file, the direction, calculates lot-risk... I searched and did not find anything similar, do you have something similar?
 
Hello. Happy New Year to you! Please help me to add commands in MQL5 to close all buy positions at signal="buy". And vice versa, all buy positions will be closed at signal="sell". Thank you in advance.
 
Namiq Acalov #:
Hello. Happy New Year to you! Please help me to add commands in MQL5 to close all buy positions at signal="buy". And vice versa, all buy positions will be closed at signal="sell". Thank you in advance.

Use articleAlmost a constructor to create an EA- you need parameter'InpCloseOpposite' set to'true'

input group             "Additional features"

*** 
input bool                 InpCloseOpposite        = true;          // Positions: Close opposite

*** 
Почти конструктор для создания советника
Почти конструктор для создания советника
  • www.mql5.com
Предлагаю свой набор торговых функций в виде готового советника. Представленный способ позволяет получать множество торговых стратегий простым добавлением индикаторов и изменением входных параметров.
 
Vladimir Karputov #:

Use the articleAlmost constructor to create an EA- you need the'InpCloseOpposite' parameter set to'true'

Thank you Vladimir. I am reading it now.
 

Good evening, dear experts. Please advise how to find the lot size of the first order in the grid?

My question is how to specify maximal drawdown value for infopanel (drawdown itself is calculated, but it is floating; how to get the maximal value out of it).

I'm getting a good feedback, I'm trying MQL4 with examples and I got stuck with these two positions by try and error (

 
Namiq Acalov #:
Hello. Happy New Year to you! Please help me to add commands in MQL5 to close all buy positions at signal="buy". And vice versa, all buy positions will be closed at signal="sell". Thank you in advance.

The function is taken from the codeof Vladimir Karputov

//+------------------------------------------------------------------+
//|                                                ClosePosition.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
#define    InpMagic  0
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---
CTrade            m_trade;                      // trading object
CSymbolInfo       m_symbol;                     // symbol info object
CPositionInfo     m_position;                   // trade position object
CAccountInfo      m_account;                    // account info wrapper
//---
input double InpLots          =0.1; // Lots
input int    InpTakeProfit    =50;  // Take Profit (in pips)
//---
double            m_adjusted_point;             // point value adjusted for 3 or 5 points
double            m_take_profit=0.0;
//---
string m_name[]= {"Buy","Sell","CloseBuy","CloseSell"};
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- initialize common information
   m_symbol.Name(Symbol());                  // symbol
   m_trade.SetExpertMagicNumber(InpMagic); // magic
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(Symbol());
//--- 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;
//--- set default deviation for trading in adjusted points
   m_take_profit     =InpTakeProfit*m_adjusted_point;
//--- set default deviation for trading in adjusted points
   m_trade.SetDeviationInPoints(3*digits_adjust);
//---
   int u=15;
   for(int y=0; y<ArraySize(m_name); y++)
     {
      ButtonCreate(m_name[y],5,u,170,15,8);
      u=u+17;
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   for(int y=0; y<ArraySize(m_name); y++)
     {
      ObjectDelete(0,Symbol()+m_name[y]);
     }
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(!RefreshRates())
      return;
   if(ObjectGetInteger(0,Symbol()+"Buy",OBJPROP_STATE)!=0)
     {
      ObjectSetInteger(0,Symbol()+"Buy",OBJPROP_STATE,0);
      double priceAsk=m_symbol.Ask();
      double tpAsk   =m_symbol.Bid()+m_take_profit;
      //--- check for free money
      if(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_BUY,InpLots,priceAsk)<0.0)
         printf("We have no money. Free Margin = %f",m_account.FreeMargin());
      else
        {
         //--- open position
         if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,priceAsk,0.0,tpAsk))
            printf("Position by %s to be opened",Symbol());
         else
           {
            printf("Error opening BUY position by %s : '%s'",Symbol(),m_trade.ResultComment());
            printf("Open parameters : price=%f,TP=%f",priceAsk,tpAsk);
           }
        }
     }
   if(ObjectGetInteger(0,Symbol()+"Sell",OBJPROP_STATE)!=0)
     {
      ObjectSetInteger(0,Symbol()+"Sell",OBJPROP_STATE,0);
      double priceBid=m_symbol.Bid();
      double tpBid   =m_symbol.Ask()-m_take_profit;
      //--- check for free money
      if(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_SELL,InpLots,priceBid)<0.0)
         printf("We have no money. Free Margin = %f",m_account.FreeMargin());
      else
        {
         //--- open position
         if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,InpLots,priceBid,0.0,tpBid))
            printf("Position by %s to be opened",Symbol());
         else
           {
            printf("Error opening SELL position by %s : '%s'",Symbol(),m_trade.ResultComment());
            printf("Open parameters : price=%f,TP=%f",priceBid,tpBid);
           }
        }
     }
   if(ObjectGetInteger(0,Symbol()+"CloseBuy",OBJPROP_STATE)!=0)
     {
      ObjectSetInteger(0,Symbol()+"CloseBuy",OBJPROP_STATE,0);
      ClosePositions(POSITION_TYPE_BUY);
     }
   if(ObjectGetInteger(0,Symbol()+"CloseSell",OBJPROP_STATE)!=0)
     {
      ObjectSetInteger(0,Symbol()+"CloseSell",OBJPROP_STATE,0);
      ClosePositions(POSITION_TYPE_SELL);
     }
  }
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data                                 |
//+------------------------------------------------------------------+
bool RefreshRates(void)
  {
//--- refresh rates
   if(!m_symbol.RefreshRates())
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: ","RefreshRates error");
      return(false);
     }
//--- protection against the return value of "zero"
   if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: ","Ask == 0.0 OR Bid == 0.0");
      return(false);
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
//| Close positions                                                  |
//+------------------------------------------------------------------+
void ClosePositions(const ENUM_POSITION_TYPE pos_type)
  {
   for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of current positions
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic)
            if(m_position.PositionType()==pos_type)
              {
               if(m_position.PositionType()==POSITION_TYPE_BUY)
                 {
                  if(!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol
                     Print(__FILE__," ",__FUNCTION__,", ERROR: ","BUY PositionClose ",m_position.Ticket(),", ",m_trade.ResultRetcodeDescription());
                 }
               if(m_position.PositionType()==POSITION_TYPE_SELL)
                 {
                  if(!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol
                     Print(__FILE__," ",__FUNCTION__,", ERROR: ","SELL PositionClose ",m_position.Ticket(),", ",m_trade.ResultRetcodeDescription());
                 }
              }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ButtonCreate(string name,int Xdist,int Ydist,int Xsize,int Ysize,int FONTSIZE=12)
  {
   if(ObjectFind(0,Symbol()+name)<0)
      ObjectCreate(0,Symbol()+name,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_COLOR,clrWhite);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_BGCOLOR,clrDimGray);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_XDISTANCE,Xdist);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_YDISTANCE,Ydist);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_XSIZE,Xsize);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_YSIZE,Ysize);
   ObjectSetString(0,Symbol()+name,OBJPROP_FONT,"Sans Serif");
   ObjectSetString(0,Symbol()+name,OBJPROP_TEXT,name);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_FONTSIZE,FONTSIZE);
   ObjectSetInteger(0,Symbol()+name,OBJPROP_SELECTABLE,false);
  }
//+------------------------------------------------------------------+