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

 
mila.com:

Thank you, is this correct?

label =ObjectGetInteger(0,nm,OBJPROP_COLOR,0);

if(label==Lime) BUY_ = true;

No, that's how you get the colour data as an int type.

Try to see what's printed in the comment.

Comment( ColorToString((color)ObjectGetInteger(0,"NaneOBJ",OBJPROP_COLOR,0), true) );

Read about the conversion

 
Vitaly Muzichenko:

Read about the conversion

Thank you, is the condition itself correct?
 
mila.com:
Thank you, is the condition itself correct?
string label = ColorToString((color)ObjectGetInteger(0,"MP140269",OBJPROP_COLOR,0), true);
if(label==Lime) BUY_ = true;

if(label==Red) BUY_ = false;
Probably not. If the data is ofstring type, you need to enclose it in quotes, and write a full character-by-character colour match: "clrLime".
 
Vitaly Muzichenko:
Probably not. If the data is ofstring type, you need to enclose it in quotes, and write a full character-by-character colour match: "clrLime".
Thanks, it worked )
 
Vitaly Muzichenko:
Probably not. If the data is ofstring type, you must enclose it in quotes, and write full character-by-character colour matching: "clrLime".
No, you don't have to enclose it in quotes - these are constants. I.e., it should be like this: if(label==clrLime) {}
 
Artyom Trishkin:
No, we do not need to put in quotes - these are constants. I.e., it should be like this: if(label==clrLime) {}

Thank you, it works.

Could you please tell me how to get the level of the stochastic indicator from the high timeframe correctly.

      int bar_sto2_0=iBarShift(Symbol(),TimeFrame2,iTime(Symbol(),TimeFrame2,i));
      int bar_sto2_1=iBarShift(Symbol(),TimeFrame2,iTime(Symbol(),TimeFrame2,i+1));
      double sto1_0=iStochastic(Symbol(),TimeFrame1,kperiod1,dperiod1,slowing1,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,i);
      double sto1_1=iStochastic(Symbol(),TimeFrame1,kperiod1,dperiod1,slowing1,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,i+1);
      double sto2_0=iStochastic(Symbol(),TimeFrame2,kperiod2,dperiod2,slowing2,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,bar_sto2_0);
      double sto2_1=iStochastic(Symbol(),TimeFrame2,kperiod2,dperiod2,slowing2,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,bar_sto2_1);
      
      if(sto2_0>55)
       {
      BufferUP[i]=low[i]-distance*MyPoint;
       }
      

When the indicator is set on a high timeframe, everything is correct, the arrow is set when the indicator line is above 55.

When switched to a lower chart, chaos.

 
mila.com:

Thank you, it works.

Could you please tell me how to get the stochastic indicator level correctly, from the high timeframe.

      int bar_sto2_0=iBarShift(Symbol(),TimeFrame2,iTime(Symbol(),TimeFrame2,i));
      int bar_sto2_1=iBarShift(Symbol(),TimeFrame2,iTime(Symbol(),TimeFrame2,i+1));
      double sto1_0=iStochastic(Symbol(),TimeFrame1,kperiod1,dperiod1,slowing1,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,i);
      double sto1_1=iStochastic(Symbol(),TimeFrame1,kperiod1,dperiod1,slowing1,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,i+1);
      double sto2_0=iStochastic(Symbol(),TimeFrame2,kperiod2,dperiod2,slowing2,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,bar_sto2_0);
      double sto2_1=iStochastic(Symbol(),TimeFrame2,kperiod2,dperiod2,slowing2,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,bar_sto2_1);
      
      if(sto2_0>55)
       {
      BufferUP[i]=low[i]-distance*MyPoint;
       }
      

When the indicator is set on a high timeframe, everything is correct, the arrow is set when the indicator line is above 55.

When you switch to a lower chart, chaos.

If you are talking about the cycle of the indicator, then in order to know which bar of the high timeframe corresponds to the bar, indicated by the cycle index in the low priceframe, you need to get the bar time i. Then this time is used to identify the bar of the highframe that corresponds to this time. For example: one bar of H4 corresponds to four bars of H1. Accordingly, four values of the cycle index i from H1 will point to the same bar on H4.

From your variables (their names) I cannot understand which bar you are getting the values from. So it's hard to say anything other than theory.

 
Artyom Trishkin:

If you are talking about the indicator cycle, in order to know which bar of the higher timeframe corresponds to the bar indicated by the cycle index in the lower tf, you need to get the time of bar i. Then this time is used to identify the bar of the highframe that corresponds to this time. For example: one bar of H4 corresponds to four bars of H1. Correspondingly, four values of the cycle index i from the H1 timeframe will point to the same bar on the H4 timeframe.

From your variables (their names) I cannot understand from which bar you get the values. Therefore it is difficult to say anything other than theory.

The indicator is set on M1.

The main condition for the upward arrow is the indicator line on M5 above the 55 level.

This condition is not met, even if the line is below the 55 level on M5, the arrow is still placed.

 

how to write the condition "if the high of 1 bar is higher than the low of 3..." into the robot.

The trigger should not be "OnTick()"

but every time 0 bar becomes 1

 
trader781:

how to write the condition "if the high of 1 bar is higher than the low of 3..." into the robot.

The trigger should not be "OnTick()"

but every time 0 bar becomes 1

You could do the following

//+------------------------------------------------------------------+
//|                                                       test03.mq4 |
//|                                                   Sergey Gritsay |
//|                         https://www.mql5.com/ru/users/sergey1294 |
//+------------------------------------------------------------------+
#property copyright "Sergey Gritsay"
#property link      "https://www.mql5.com/ru/users/sergey1294"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CNevBar
  {
private:
   datetime          curbar;
   datetime          lastbar;
public:
                     CNevBar();
                    ~CNevBar();
   bool              new_bar(string symbol,ENUM_TIMEFRAMES period);
  };
//+------------------------------------------------------------------+
void CNevBar::CNevBar()
  {

  }
//+------------------------------------------------------------------+
void CNevBar::~CNevBar(void)
  {

  }
//+------------------------------------------------------------------+
bool CNevBar:: new_bar(string symbol,ENUM_TIMEFRAMES period)
  {
   curbar=(datetime) SeriesInfoInteger(symbol,period,SERIES_LASTBAR_DATE);
   if(lastbar==0)lastbar=(datetime)SeriesInfoInteger(symbol,period,SERIES_LASTBAR_DATE);
   if(lastbar!=curbar)
     {
      lastbar=curbar;
      return(true);
     }
   return(false);
  }

CNevBar newbar;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(newbar.new_bar(_Symbol,PERIOD_CURRENT))
     {
      if(High[1]>Low[3])
        {

        }
     }

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

...

Reason: