Mql5 open, close

 

Need to enter at a certain point with mt5.

How would you put it? Current price on the current candle == 80 points in..?

 

Code:

//+------------------------------------------------------------------+
//|                                  Example Current candle size.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property version   "1.001"
//+------------------------------------------------------------------+
//| Enum Pips Or Points                                              |
//+------------------------------------------------------------------+
enum ENUM_PIPS_OR_POINTS
  {
   pips=0,     // Pips (1.00045-1.00055=1 pips)
   points=1,   // Points (1.00045-1.00055=10 points)
  };
//--- input parameters
input ENUM_PIPS_OR_POINTS  InpPipsOrPoints   = pips;           // Pips Or Points:
input uint                 InpCandleSize     = 80;             // Candle: Size
//---
double   m_candle_size           = 0.0;      // Candle: Size               -> double
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- tuning for 3 or 5 digits
   int digits_adjust=1;
   if(Digits()==3 || Digits()==5)
      digits_adjust=10;
   double m_adjusted_point=Point()*digits_adjust;
   if(InpPipsOrPoints==pips) // Pips (1.00045-1.00055=1 pips)
     {
      m_candle_size              = InpCandleSize               * m_adjusted_point;
     }
   else // Points (1.00045-1.00055=10 points)
     {
      m_candle_size              = InpCandleSize               * Point();
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   MqlRates rates[];
   ArraySetAsSeries(rates,true);
   int start_pos=0,count=3;
   if(CopyRates(Symbol(),Period(),start_pos,count,rates)!=count)
      return;
//--- signal search
   if(MathAbs(rates[0].open-rates[0].close)>=m_candle_size)
     {
      //--- the current candle has reached the specified size
      //--- Your code is here ...
      int d=0;
     }
  }
//+------------------------------------------------------------------+
 
Thanks
 
mmee55 :

How can the signal search be used to refer to buy and sell? 

What's the signal?

 
mmee55:

The 80points(your code) has to be greater than the based candles... the start + 80 for a buy and 80 points below for a sell.

So what I'm set at is..

buy=(80points > start)

Sell=(80points < start)

How would it read off yours... it'll be reading from your ontick signal search part? 

We are waiting for the size of the current bar to reach the specified size

How to start with MQL5
How to start with MQL5
  • 2021.01.11
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
void OnTick()
  {
//---
   MqlRates rates[];
   ArraySetAsSeries(rates,true);
   int start_pos=0,count=3;
   if(CopyRates(Symbol(),Period(),start_pos,count,rates)!=count)
      return;
//--- signal search
   if(MathAbs(rates[0].open-rates[0].close)>=m_candle_size)
     {
     Buy=(rates[0].close > start );
     Sell =(rates[0].close < start );
     }
  }
//+----------------------------------------------------------

The code works...the buy and sell I've added to the code works, but its premature and opens a position to early, instead of 80points in... can anyone point me into the right direction.. I've also tried rates[0].close>=m_candle_size >< start ..but it doesn't run well

 
mmee55 :

The code works...the buy and sell I've added to the code works, but its premature and opens a position to early, instead of 80points in... can anyone point me into the right direction.. I've also tried rates[0].close>=m_candle_size >< start ..but it doesn't run well

Read the help: MathAbs

Think first, write code later. Are you aware that there can be two types of bars: bearish and bullish? Do you know how these two types of bars differ?

Documentation on MQL5: Math Functions / MathAbs
Documentation on MQL5: Math Functions / MathAbs
  • www.mql5.com
MathAbs - Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
if(MathAbs(rates[0].open-rates[0].close)>=m_candle_size)
     {
     Buy=(rates[0].close > start );
     Sell =(rates[0].close < start );
     }
  }
//+---

Mathabs displayed here? Or does it need to be within buy and sell?.. I'm aware of bulls and bears as far as I know.. positions are opening fine it's just they open 76 points to early and I've done alot of thinking to try figure it out....but I'm now just stuck on it,  also not an expert with mql so I'm not completely aware of everything within the language yet.

 
mmee55 :

Mathabs displayed here? Or does it need to be within buy and sell?.. I'm aware of bulls and bears as far as I know.. positions are opening fine it's just they open 76 points to early and I've done alot of thinking to try figure it out....but I'm now just stuck on it,  also not an expert with mql so I'm not completely aware of everything within the language yet.

How is a bullish bar different from a bearish bar? This is an elementary question. This is the ABC of Forex. Please answer: " What is the difference between a bullish bar and a bearish bar?"

 
Vladimir Karputov:

How is a bullish bar different from a bearish bar? This is an elementary question. This is the ABC of Forex. Please answer: " What is the difference between a bullish bar and a bearish bar?"

Bulls up bears down.. is there something im missing.. is there another way of putting it when coding?

 
mmee55 :

Bulls up bears down.. is there something im missing.. is there another way of putting it when coding?

How else can you describe it? What is the difference between a bullish bar and a bearish one?

What does "up" and "down" mean?