Questions from Beginners MQL4 MT4 MetaTrader 4 - page 36

 

Hello !

Help me fix the code so that the bar captions are in the centre of the bar above the high bar and not on the side

#property strict
#property indicator_chart_window

input int TextSize = 8; //size font
input color TextColor = clrYellow; //text colour
input int TextAngle = 90; //text rotation angle
input int MaxBar = 100; //number of bars starting from 0 for which the candlestick size is calculated

int OnInit()
{
return(INIT_SUCCEED);
}

int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int i;
for ( i = 0; i < MaxBar; i++ ) {
if ( ObjectFind ("candlesize "+ IntegerToString(i)) >=0 ) {
ObjectDelete("candlesize "+ IntegerToString(i))
}
ObjectCreate ("candlesize "+ IntegerToString(i),
OBJ_TEXT,
0,
time[i],
high[i]+StepPer()*Point);
ObjectSet ("candlesize "+IntegerToString(i),
OBJPROP_ANGLE,
TextAngle
);
ObjectSetText ("candlesize "+IntegerToString(i),
DoubleToStr(NormalizeDouble((high[i]-low[i]+Point)/Point, 0), 0),
TextSize,
NULL,
TextColor
);
}
return(rates_total);
}

int StepPer ()
{
int i = 0;
switch (Period())
{
case PERIOD_M1:
i = 5;
break;
case PERIOD_M5:
i = 15;
break;
case PERIOD_M15:
i = 25;
break;
i = 40;
break;
case PERIOD_H1:
i = 60;
break;
case PERIOD_H4:
i = 90;
break;
case PERIOD_D1:
i = 220;
break;
case PERIOD_W1:
i = 500;
break;
case PERIOD_MN1:
i = 2000;
break;
default:
break;
}
return (i);
}

 
ed3sss:

Proof: Print("Previous job PriceAsk-",PriceAsk); the log is empty.

Without details it's not a proof )))) Show me the full text of the init and the declaration of variables.

Also, why check ALL orders, from the very beginning of the account life, if you need the latest? - How else to do it, if there are 10 currency pairs open?

You have to go through them from the end and exit the cycle in time. What has 10 pairs got to do with it? Even a hundred, you have a symbol to choose from.

 
Игорь:

Hello !

Help me to correct the code so that the inscriptions above the bars would be in the centre of the bar above the high bar and not on the side

Learn how to use SRC button to insert code.

And read about OBJPROP_ANCHOR.

 
Vitalie Postolache:

Learn how to use the SRC button to insert code.

And read about OBJPROP_ANCHOR.

Got it !

Sorry for the abruptness !

 
Игорь:

Got it, thanks !

Sorry for the harshness !

#property strict
#property indicator_chart_window

input int      TextSize = 8; //размер шрифта
input color    TextColor = clrYellow; //цвет текста
input int      TextAngle = 90; //угол поворота текста
input int      MaxBar = 100;  //количество баров, начиная с 0, для которых вычисляется размер свечей

int OnInit()
{
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int i;
   for ( i = 0; i < MaxBar; i++ )   {
      if ( ObjectFind ("candlesize"+ IntegerToString(i)) >=0 )   {
             ObjectDelete("candlesize"+ IntegerToString(i));
      }
      ObjectCreate ("candlesize"+ IntegerToString(i),  
                    OBJ_TEXT,  
                    0,  
                    time[i],  
                    high[i]+StepPer()*Point);
       //--- установим привязку к правому верхнему углу
      ObjectSetInteger(ChartID(),"candlesize"+IntegerToString(i),OBJPROP_ANCHOR,ANCHOR_UPPER);
     ObjectSet (  "candlesize"+IntegerToString(i),  
                    OBJPROP_ANGLE,  
                    TextAngle
                 );
      ObjectSetText ( "candlesize"+IntegerToString(i),  
                      DoubleToStr(NormalizeDouble((high[i]-low[i]+Point)/Point, 0), 0),  
                      TextSize,  
                      NULL,  
                      TextColor
                     );
   }
   return(rates_total);
}

int StepPer ()
{
     int i = 0;
     switch (Period())
     {
          case PERIOD_M1:
          i = 5;
          break;
          case PERIOD_M5:
          i = 15;
          break;
          case PERIOD_M15:
          i = 25;
          break;
          case PERIOD_M30:
          i = 40;
          break;
          case PERIOD_H1:
          i = 60;
          break;
          case PERIOD_H4:
          i = 90;
          break;
          case PERIOD_D1:
          i = 220;
          break;
          case PERIOD_W1:
          i = 500;
          break;
          case PERIOD_MN1:
          i = 2000;
          break;
          default:  
          break;
     }
     return (i);
}  
I put it in and it's still off centre and on the wrong bar !?
 
#property strict
#property indicator_chart_window

input int      TextSize = 8; //размер шрифта
input color    TextColor = clrYellow; //цвет текста
input int      TextAngle = 90; //угол поворота текста
input int      MaxBar = 100;  //количество баров, начиная с 0, для которых вычисляется размер свечей

int OnInit()
{
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int i;
   for ( i = 0; i < MaxBar; i++ )   {
      if ( ObjectFind ("candlesize"+ IntegerToString(i)) >=0 )   {
             ObjectDelete("candlesize"+ IntegerToString(i));
      }
      ObjectCreate ("candlesize"+ IntegerToString(i),  
                    OBJ_TEXT,  
                    0,  
                    time[i],  
                    high[i]+StepPer()*Point);
       //--- установим привязку к правому верхнему углу
      ObjectSetInteger(ChartID(),"candlesize"+IntegerToString(i),OBJPROP_ANCHOR,ANCHOR_UPPER);
     ObjectSet (  "candlesize"+IntegerToString(i),  
                    OBJPROP_ANGLE,  
                    TextAngle
                 );
      ObjectSetText ( "candlesize"+IntegerToString(i),  
                      DoubleToStr(NormalizeDouble((high[i]-low[i]+Point)/Point, 0), 0),  
                      TextSize,  
                      NULL,  
                      TextColor
                     );
   }
   return(rates_total);
}

int StepPer ()
{
     int i = 0;
     switch (Period())
     {
          case PERIOD_M1:
          i = 5;
          break;
          case PERIOD_M5:
          i = 15;
          break;
          case PERIOD_M15:
          i = 25;
          break;
          case PERIOD_M30:
          i = 40;
          break;
          case PERIOD_H1:
          i = 60;
          break;
          case PERIOD_H4:
          i = 90;
          break;
          case PERIOD_D1:
          i = 220;
          break;
          case PERIOD_W1:
          i = 500;
          break;
          case PERIOD_MN1:
          i = 2000;
          break;
          default:  
          break;
     }
     return (i);
}  
Guys, can you help a hobo over the middle where the joint is?
 
Игорь:
#property strict
#property indicator_chart_window

input int      TextSize = 8; //размер шрифта
input color    TextColor = clrYellow; //цвет текста
input int      TextAngle = 90; //угол поворота текста
input int      MaxBar = 100;  //количество баров, начиная с 0, для которых вычисляется размер свечей

int OnInit()
{
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int i;
   for ( i = 0; i < MaxBar; i++ )   {
      if ( ObjectFind ("candlesize"+ IntegerToString(i)) >=0 )   {
             ObjectDelete("candlesize"+ IntegerToString(i));
      }
      ObjectCreate ("candlesize"+ IntegerToString(i),  
                    OBJ_TEXT,  
                    0,  
                    time[i],  
                    high[i]+StepPer()*Point);
       //--- установим привязку к правому верхнему углу
      ObjectSetInteger(ChartID(),"candlesize"+IntegerToString(i),OBJPROP_ANCHOR,ANCHOR_UPPER);
     ObjectSet (  "candlesize"+IntegerToString(i),  
                    OBJPROP_ANGLE,  
                    TextAngle
                 );
      ObjectSetText ( "candlesize"+IntegerToString(i),  
                      DoubleToStr(NormalizeDouble((high[i]-low[i]+Point)/Point, 0), 0),  
                      TextSize,  
                      NULL,  
                      TextColor
                     );
   }
   return(rates_total);
}

int StepPer ()
{
     int i = 0;
     switch (Period())
     {
          case PERIOD_M1:
          i = 5;
          break;
          case PERIOD_M5:
          i = 15;
          break;
          case PERIOD_M15:
          i = 25;
          break;
          case PERIOD_M30:
          i = 40;
          break;
          case PERIOD_H1:
          i = 60;
          break;
          case PERIOD_H4:
          i = 90;
          break;
          case PERIOD_D1:
          i = 220;
          break;
          case PERIOD_W1:
          i = 500;
          break;
          case PERIOD_MN1:
          i = 2000;
          break;
          default:  
          break;
     }
     return (i);
}  
Help a vagabond out there, where's the joint in the middle?
I don't know if it's over the bar or on the side even though I said centre!
 
Игорь:

I have inserted it and it is still off centre and on the wrong bar !?

Well, after turning, the dot is no longer at the top centre, but to the left centre, so the text is shifted to the right.

ObjectSetInteger(ChartID(),"candlesize"+IntegerToString(i),OBJPROP_ANCHOR,ANCHOR_LEFT);
The anchor point is set at 0 degrees rotation, you need to consider the angle of rotation and set the anchor point to be at the bottom if the object is over High, in your case it would be the left centre point.
 
Vitalie Postolache:

Well, after turning, the dot is no longer at the top centre, but to the left centre, so the text is shifted to the right.

ObjectSetInteger(ChartID(),"candlesize"+IntegerToString(i),OBJPROP_ANCHOR,ANCHOR_LEFT);
Anchor point is set at a rotation of 0 degrees, you need to consider the angle of rotation and set the anchor point, which will be at the bottom if the object is over High, in your case it will be a point to the left in the centre.

Thank you so much !!!!!

It all worked out the way I wanted !

Once again, I apologize for misunderstanding and my harshness !

 
Vitalie Postolache:

Without details it's not proof )))) Show the full text of the init and the declaration of variables.

From the end to go through and exit the loop in time. What do 10 pairs have to do with it? Even a hundred, you have a character-by-character selection there.

bool s=false;
double b=AccountBalance();
i=0;
for(;i<OrdersTotal();i++)
{//+----------------------------------------------------------------------------------------+for
ViborOrdera=OrderSelect(i,SELECT_BY_POS);
if(OrderSymbol()!=Symbol())continue;
if(OrderType()>1)continue;
s=true;
int Ticket=OrderTicket();
double Lots=OrderLots();
double Price;
if(OrderType()==1)Price=NormalizeDouble(Ask,Digits);else Price=NormalizeDouble(Bid,Digits);
//+-----------------------------------------------------------------------------------------+
ViborOrdera=OrderClose(Ticket,Lots,Price,3);
if(GetLastError()==6){Alert("No connection");return(0);}
if(GetLastError()==132){Alert("Market is closed");return(0);}
RefreshRates();
i--;

}//+---------------------------------------------------------------------------------------+for

Ok, same loop here, why does it close orders?)

Reason: