How to get candle trend by time

 

Hi 

I am new in mql programming,

I want to get specified candle trend by time :

for example I want to get the candle in 8:15am (m15 time frame) trend , and if its red (down) do something or green (up) do somthing 

please help me to write this

 
IrPhoenix:

Hi 

I am new in mql programming,

I want to get specified candle trend by time :

for example I want to get the candle in 8:15am (m15 time frame) trend , and if its red (down) do something or green (up) do somthing 

please help me to write this

Code:

//+------------------------------------------------------------------+
//|                                  Example Candle Type By Time.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"
//--- input parameters
input datetime          Time        = D'2020.08.03 09:04:12';
input ENUM_TIMEFRAMES   TimeFrame   = PERIOD_M15;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int bar_shift=iBarShift(Symbol(),TimeFrame,Time);
   if(bar_shift==-1)
     {
      Comment("ERROR: iBarShift");
      return;
     }
   else
     {
      MqlRates rates[];
      int start_pos=bar_shift,count=1;
      if(CopyRates(Symbol(),TimeFrame,start_pos,count,rates)!=count)
        {
         Comment("ERROR: CopyRates");
         return;
        }
      string bar_type=(rates[0].close<rates[0].open)?"Down":"Up";
      Comment("Input: ",Time,", Search: ",rates[0].time,", Type: ",bar_type);
     }
  }
//+------------------------------------------------------------------+

Result:


 

Thanks 

do you have file for mq4 ?

 
IrPhoenix :

Thanks 

do you have file for mq4 ?

You are on the MQL5 forum. Therefore, you have received an answer in MQL5. If you have questions about the old language and the old terminal, write only in the MQL4 and MetaTrader 4 section.

 
Ok 
Thank you 
Reason: