Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1533

 
Алексей КоКоКо:

Can you tell me how to understand the documentation in general? I'm really worried that in the examples of even a simple graphical object like text, they throw in your face a sample with a bunch of code and nowhere do they write which parameters are mandatory and which are not. So in order to just write some text or set a trend or even understand the buffers for an indicator you don't understand what minimum parameters should be entered and you have to copy out and paste your code

Hello, the required parameters for the text are window index, coordinate reference and the text itself, the others are optional.

You need to keep in mind that there are two types of objects, OBJ_LABEL and OBJ_TEXT. The first object is bound to window pixels and the second to time and price on the chart.

Let's say we need a text label linked to pixels, then do this:

   ObjectCreate(0,name,OBJ_LABEL,0,0,0); // создаём объект в текущем (нулевом окне)
   ObjectSetString(0,name,OBJPROP_TEXT,text); // указываем какой текст должен в нём отображаться
   ObjectSetString(0,name,OBJPROP_FONT,fontname); // назначаем шрифт например Verdana или Tahoma
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize); // назначаем размер шрифта
   ObjectSetInteger(0,name,OBJPROP_COLOR, text_color); // назначаем цвет шрифта
   ObjectSetInteger(0,name,OBJPROP_CORNER,text_corner); // указываем от какого угла окна отсчитывать пиксели
   ObjectSetInteger(0,name,OBJPROP_ANCHOR,text_anchor); // указываем как должен быть выровнен текст по центру или какому-то краю
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,XOFFSET); // указываем координату по горизонтали
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,YOFFSET); // указываем координату по вертикали
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false); // указываем можно ли выделять и двигать метку мышкой или нельзя

this is almost minimal code that draws the text label

the same for the OBJ_TEXT object, but you also need to specify the price and time properties:

   ObjectSetDouble(0,name,OBJPROP_PRICE,0,price);
   ObjectSetInteger(0,name,OBJPROP_TIME,0,time);



text_corner should be one of the constant values:

ID

Description

CORNER_LEFT_UPPER

Centre of coordinates in the left top corner of the chart

CORNER_LEFT_LOWER

Centre of coordinates in the lower left corner of the chart

CORNER_RIGHT_LOWER

Centre of coordinates in the lower right corner of the chart

CORNER_RIGHT_UPPER

Centre of coordinates in the upper right corner of the chart


more details here: https://www.mql5.com/ru/docs/constants/objectconstants/enum_basecorner#enum_base_corner




text_corner should be one of the constant values:

Identifier

Description

ANCHOR_LEFT_UPPER

Anchor point in the upper left corner

ANCHOR_LEFT

Anchor point to the left in the centre

ANCHOR_LEFT_LOWER

Anchor point at the lower left corner

ANCHOR_LOWER

Anchor point below centre

ANCHOR_RIGHT_LOWER

Anchor point at the lower right corner

ANCHOR_RIGHT

Anchor point to the right in the centre

ANCHOR_RIGHT_UPPER

Anchor point at the upper right corner

ANCHOR_UPPER

Anchor point at the upper centre

ANCHOR_CENTER

Anchor point exactly in the centre of the object


more details here:https://www.mql5.com/ru/docs/constants/objectconstants/enum_basecorner



you can also connect the standard library #include <ChartObjects\ChartObject.mqh> and use its classes, but this only complicates your life in my opinion

 
transcendreamer:

Greetings, mandatory parameters for text are window index, coordinate binding and text itself, others are optional.

Keep in mind that there are two types of objects: OBJ_LABEL and OBJ_TEXT. The first one is bound to window pixels and the second one to time and price on the chart.

Let's say we need a text label linked to pixels, then do this:

this is almost minimal code that draws the text label

the same for OBJ_TEXT object, but you only need to set price and time properties:


God bless you )It's not just the text but many things, even the indicator buffers. What's in the cart removed?)

 
Алексей КоКоКо:

God bless you )It's not just the text, it's many things, even the indicator buffers. Why are you deleted from the trolley?)

I deleted from the trolley as usual because I was paranoid and the Chexists didn't find me out 😀 I have no idea what to do with it.

 
Artyom Trishkin:

And the right option is, well, very simple...

And what is it? Why don't you write it down?

 
Hi all, I have inserted in one EA "starhour and stophour" to open orders at a certain time, but I have not considered that the order which was opened for example at 22:00 will not be closed in stophour(23:00)
Since before there was no signal indicator to close the position and after 23:00 it is even forbidden to make any decisions.

Please advise how to make EA to be able to close opened positions after stophour (23:00).
Or just close all positions at 23:00, so as not to keep them all night.


Thanks in advance
 
Eugen8519:
Hi all, I have inserted in one EA "starhour and stophour" to open orders at a certain time, but I have not considered that an order which was open for example at 22:00 will not close in stophour(23:00)
Since before there was no signal indicator to close the position and after 23:00 it is even forbidden to make any decisions.

Please advise how to make EA to be able to close opened positions after stophour (23:00).
Or just close all positions at 23:00, so as not to keep them all night.


Thanks in advance

put "starhour and stophour" only on open orders

 
MakarFX:

put "starhour and stophour" only on opening orders

That's the problem - it only opens and closes starthour->stophour orders
And open orders are not closed after stophour

You cannot trade after stophour



The global parameters are set

bool           UseTimeLimit = true;
int            startHour    = 15;
int            stopHour     = 23;
bool           YesStop=false;
input          ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT;



And in OnTick

if(UseTimeLimit)
  {
    YesStop=true;
    MqlDateTime str1;
    TimeToStruct(TimeCurrent() , str1);
    if(str1.hour > startHour && str1.hour < stopHour)
       YesStop=false;
       if (YesStop)
       return;
  }
 
Eugen8519:
That's the problem, it only opens and closes starthour->stophour orders
And open orders do not close after stophour
Show close orders function
 
Eugen8519:
That's the problem, it only opens and closes starthour->stophour orders
And open orders are not closed after stophour

something like this

if(UseTimeLimit)
  {
    YesStop=true;
    MqlDateTime str1;
    TimeToStruct(TimeCurrent() , str1);
    if(str1.hour > startHour && str1.hour < stopHour)
       YesStop=false;
       if (YesStop)
       return;
  }
....
if(YesStop==false)
  {
   условие для открытия ордеров
  }
 
MakarFX:

something like this

This is how the order closes



(EMA0[m_bar_current]<WMA0[m_bar_current] && EMA0[m_bar_current+1]>WMA0[m_bar_current+1]) //Buy
     {
      if(!RefreshRates())
         return;
      TimeBar=time_0;
      CLOSEORDER("Sell");
     }
//if(color_buffer[m_bar_current+1]<color_buffer[m_bar_current]) //Sell
   if(EMA0[m_bar_current]>WMA0[m_bar_current] && EMA0[m_bar_current+1]<WMA0[m_bar_current+1]) //Sell
     {
      if(!RefreshRates())
         return;
      TimeBar=time_0;
      CLOSEORDER("Buy");
     }


void CLOSEORDER(string ord)
  {
   for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of open positions
      if(m_position.SelectByIndex(i))
         if(m_position.Symbol()==Symbol() && m_position.Magic()==m_magic)
           {
            if(m_position.PositionType()==POSITION_TYPE_BUY && ord=="Buy")
               m_trade.PositionClose(m_position.Ticket());  // Close Buy
            if(m_position.PositionType()==POSITION_TYPE_SELL && ord=="Sell")
               m_trade.PositionClose(m_position.Ticket()); // Close Sell
           }
  }
Reason: