/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// DATA 1 //< >
//------------------------------------------------------------------------//<-->
#property copyright "Copyright 2020, MetaQuotes Software Corp." //< 1>
#property link "https://www.mql5.com" //< 2>
#property version "1.000" //< 3>
#property indicator_chart_window //< 4>
#property indicator_buffers 1 //< 5>
#property indicator_plots 1 //< 6>
//< 7>
string LABEL_NAME = "AIS RED CANDLES COUNTER" ; //< 8>
string SYMBOL = _Symbol ; //< 9>
int DIGITS = _Digits ; //<10>
double POINT = _Point ; //<11>
long CHART = NULL ; //<12>
//<13>
//<14>
//<15>
//<16>
//<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 01:01 //
/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// DATA 2 //< >
//------------------------------------------------------------------------//<-->
sinput string S1="=================="; /* ============================ */ //< 1>
input int CANDLES_TOTAL = 27 ; /* NUMBER OF CANDLES */ //< 2>
sinput string S2="=================="; /* == LABEL FONT ============== */ //< 3>
input string FONT_NAME = "Courier New" ; /* FONT NAME */ //< 4>
input int FONT_SIZE = 10 ; /* FONT SIZE */ //< 5>
input color FONT_COLOR = White ; /* FONT COLOR */ //< 6>
sinput string S3="=================="; /* == LABEL POSITION ========== */ //< 7>
input int X = 5 ; /* X DISTANCE */ //< 8>
input int Y = 20 ; /* Y DISTANCE */ //< 9>
input int CORNER = 0 ; /* CORNER */ //<10>
input int WINDOW = 0 ; /* WINDOW */ //<11>
sinput string S4="=================="; /* ============================ */ //<12>
//<13>
//<14>
//<15>
//<16>
//<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 01:01 //
/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// FUNCTION 1 //< >
//------------------------------------------------------------------------//<-->
int OnInit () { //< 1>
//< 2>
ObjectCreate ( CHART , LABEL_NAME , OBJ_LABEL , WINDOW , 0 , 0 ) ; //< 3>
//< 4>
ObjectSetInteger ( CHART , LABEL_NAME , OBJPROP_CORNER , CORNER ) ; //< 5>
ObjectSetInteger ( CHART , LABEL_NAME , OBJPROP_XDISTANCE , X ) ; //< 6>
ObjectSetInteger ( CHART , LABEL_NAME , OBJPROP_YDISTANCE , Y ) ; //< 7>
//< 8>
ObjectSetInteger ( CHART , LABEL_NAME , OBJPROP_COLOR , FONT_COLOR ) ; //< 9>
ObjectSetString ( CHART , LABEL_NAME , OBJPROP_FONT , FONT_NAME ) ; //<10>
ObjectSetInteger ( CHART , LABEL_NAME , OBJPROP_FONTSIZE , FONT_SIZE ) ; //<11>
//<12>
//<13>
//<14>
//<15>
//<16>
return INIT_SUCCEEDED ; } //<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 01:01 //
/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// FUNCTION 2 //< >
//------------------------------------------------------------------------//<-->
void OnDeinit ( const int REASON ) { //< 1>
//< 2>
ObjectDelete ( CHART , LABEL_NAME ) ; //< 3>
ChartRedraw ( CHART ) ; //< 4>
//< 5>
//< 6>
//< 7>
//< 8>
//< 9>
//<10>
//<11>
//<12>
//<13>
//<14>
//<15>
//<16>
} //<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 01:01 //
/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// FUNCTION 3 //< >
//------------------------------------------------------------------------//<-->
int OnCalculate ( const int RATES_TOTAL , const int CALCULATED , //< 1>
const int BEGIN , const double & PRICE [] ) { //< 2>
//< 3>
if ( ! NEW_CANDLE () ) return NULL ; //< 4>
//< 5>
int CANDLES_GREEN = NULL ; //< 6>
int CANDLES_RED = NULL ; //< 7>
//< 8>
for ( int COUNTER = 1 ; COUNTER <= CANDLES_TOTAL ; COUNTER ++ ) //< 9>
if ( IT_IS_RED_CANDLE ( COUNTER ) ) CANDLES_RED ++ ; //<10>
else CANDLES_GREEN ++ ; //<11>
//<12>
//<13>
DRAW_LABEL ( CANDLES_GREEN , CANDLES_RED ) ; //<14>
//<15>
//<16>
return RATES_TOTAL ; } //<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 02:12 //
/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// FUNCTION 4 //< >
//------------------------------------------------------------------------//<-->
int NEW_CANDLE () { //< 1>
//< 2>
static datetime TIME_LAST = NULL ; //< 3>
datetime TIME_THIS = iTime ( SYMBOL , PERIOD_CURRENT , 0 ) ; //< 4>
//< 5>
if ( TIME_LAST < TIME_THIS ) //< 6>
{ //< 7>
TIME_LAST = TIME_THIS ; //< 8>
//< 9>
return true ; //<10>
} //<11>
else return NULL ; //<12>
//<13>
//<14>
//<15>
//<16>
} //<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 02:09 //
/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// FUNCTION 5 //< >
//------------------------------------------------------------------------//<-->
bool IT_IS_RED_CANDLE ( int INDEX ) { //< 1>
//< 2>
if ( iClose ( SYMBOL , PERIOD_CURRENT , INDEX ) //< 3>
< iOpen ( SYMBOL , PERIOD_CURRENT , INDEX ) ) //< 4>
return true ; //< 5>
else return false ; } //< 6>
//< 7>
//< 8>
//< 9>
//<10>
//<11>
//<12>
//<13>
//<14>
//<15>
//<16>
//<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 01:01 //
/******************************************************************************/
// AIS RED CANDLES COUNTER INDICATOR //
//============================================================================//
// FUNCTION 6 //< >
//------------------------------------------------------------------------//<-->
int DRAW_LABEL ( int CANDLES_GREEN , int CANDLES_RED ) { //< 1>
//< 2>
string TEXT = //< 3>
"CANDLES= " + IntegerToString ( CANDLES_TOTAL ) //< 4>
+ " GREEN= " + IntegerToString ( CANDLES_GREEN ) //< 5>
+ " RED= " + IntegerToString ( CANDLES_RED ) ; //< 6>
//< 7>
ObjectSetString ( CHART , LABEL_NAME , OBJPROP_TEXT , TEXT ) ; //< 8>
ChartRedraw ( CHART ) ; //< 9>
//<10>
//<11>
//<12>
//<13>
//<14>
//<15>
//<16>
return true ; } //<17>
//============================================================================//
// AIS AIRAT SAFIN 2020-05-02 01:01 //
/*****************************************************************************//
Files:
Bosinceanu Claudiu Catalin:
Can someone help me with a script for the next issue:
I want to know how many red candles there are in the last 27 minutes.
In the example below you can see that there are 9 red candles out of a total of 27.
That means we have 10 red candles in the last 27 minutes.And simply to appear on my screen: "There are 9 reds, 18 green candles."
Not compiled, not tested; just typed.
input int lookBack = 27; int start(){ int nUp=0, nDn=0; for(int iBar=lookBack; iBar>0; --iBar){ if(Close[iBar] > Open[iBar]) ++nUp; else ++nDn; } Comment( StringFormat("There are %d reds, %d green candles", nUp, nDn) ); }Not compiled, not tested; just typed.
Thank you very much
If I use the script on a range of 20 candles, it updates each candle
If I use the script on a range of 100 candles, it updates irregularly, once every 2-3 candles
Where the problem is?
Sometimes after the arrival of a new candle, the number of red and green candles remains unchanged
That is, the new
candle has the same color as the candle that was last and left
And just in case, I added an indication of the time until the end of the candle
Files:
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello boys,
Can someone help me with a script for the next issue:
I want to know how many red candles there are in the last 27 minutes.
In the example below you can see that there are 9 red candles out of a total of 27.
Let's assume that the next candle ends in red.
That means we have 10 red candles in the last 27 minutes.
And simply to appear on my screen: "There are 9 reds, 18 green candles."
If no one can help me with this script, can you at least tell me how difficult it can be to create one?
Thanks in advance!