How to Plot Text Characters on a Chart

 

Hi.

I'm working on some indicators where the basic display idea is just to mark certain bars.

I'm able to mark the bars with DingBats (graphic symbols) fine.

Is there a way to mark the bars with normal alphanumeric letters (lower and/or upper case) in the same fashion?

- sj

 

ObjectCreate() 1 of the Object Tipes is OBJ_TEXT

 

Thanks, I was able to work with that.

Below (and attached) is a simple implementation of marking up and down bars.

This is working for me, but as I am new to MT4, if anyone has any comments about the basic approach or code arrangement, they would be welcome.



//#property indicator_separate_window
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red

// Bring in ErrorDescription(), among others.
#include <stdlib.mqh>

//---- input parameters
// None

// Variables

color UpColor = Cyan ;
color DnColor = Red ;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+

int init()
{
int err ;
bool status ;

ObjectsDeleteAll(); // remove all objects from the chart.

return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{

int idx, first_idx, jdx, limit, counter, loop, BN, err ;
bool c1, c2, c3 ;
int Counted_Bars = IndicatorCounted();

// General error checks
if(Counted_Bars < 0) return(-1);

//---- force re-processing of latest bar (just in case ...)
if(Counted_Bars > 0) Counted_Bars--;

first_idx = Bars - Counted_Bars - 1 ; // Index of the first uncounted - we will start processing here, decrementing with each pass
idx = first_idx ;

err = GetLastError();
if( err == 4002 ){
Print( " Time[idx]: " + TimeToStr(Time[idx], TIME_DATE|TIME_SECONDS) + " idx: " + DoubleToStr(idx, 0) + " Before loop error(", err, "): ", ErrorDescription(err) );
return(-1) ;
}

// This loop runs from a higher numbered index down thru 0.
// In terms of the OHLC arrays, this is from past to future.
//
while(idx >= 0){ // Loop for uncounted bars

//Print( " Time[idx]: " + TimeToStr(Time[idx], TIME_DATE|TIME_SECONDS) + " idx: " + DoubleToStr(idx, 0) + " Loop top" );

BN = Bars - idx ; // BarNumber with low count at left of chart

if( Open[idx] < Close[idx] ){
// bool ObjectCreate( string name, int type, int window, datetime time1, double price1, datetime time2=0, double price2=0, datetime time3=0, double price3=0)
ObjectCreate("" + idx, OBJ_TEXT, 0, Time[idx], Low[idx] );
ObjectSetText("" + idx, "U", 10, "Arial", UpColor);
}

if( Open[idx] > Close[idx] ){
// bool ObjectCreate( string name, int type, int window, datetime time1, double price1, datetime time2=0, double price2=0, datetime time3=0, double price3=0)
ObjectCreate("" + idx, OBJ_TEXT, 0, Time[idx], High[idx] );
ObjectSetText("" + idx, "D", 10, "Arial", DnColor);
}

idx--;

} // end of: while(idx >= 0)

WindowRedraw() ;

return(0);

}

Files:
Reason: