Please help with a bit of coding & feel free to use what I have done already...

To add comments, please log in or register
antony
549
antony  

I have this indicator that in any timeframe draws two lines, one showing the highest price and one showing the lowest price of the day, useful for you daily trend traders...

The original is freeware that i downloaded but modified for my purpose.

The indicator also displays the value of these lines on the top left of the chart.

Does anyone know how to code it so it also shows the difference in the lines? basically the high minus the low of the day?

//+------------------------------------------------------------------+
//| Igrok.mq4 |
//| Andrei Andreev |
//| http://www.andand.ru/ |
//+------------------------------------------------------------------+

// BASED ON:
//+------------------------------------------------------------------+
//| ^X_Sensors.mq4 |
//| Version 2.0.1 |
//|------------------------------------------------------------------|
//| Copyright © 2007, Mr.WT, Senior Linux Hacker |
//| http://w-tiger.narod.ru/wk2/ |
//+------------------------------------------------------------------+
#property copyright "Andrei Andreev"
#property link "http://www.andand.ru/"

#property indicator_chart_window
extern int ForDays=1;
extern int _Shift = 10;
extern color _R_Color = Blue;
extern color _S_Color = Red;


int _N_Time, _My_Period, ObjectId;
string OBJECT_PREFIX = "LEVELS";
//-------------------------------------------------------------------------------------------
int init() {

_My_Period=PERIOD_D1;

_N_Time = 0;

ObjectCreate("S1 line", OBJ_TREND, 0, Time[_Shift], 0, Time[0], 0);

ObjectCreate("R1 line", OBJ_TREND, 0, Time[_Shift], 0, Time[0], 0);
ObjectCreate("R2 line", OBJ_TREND, 0, Time[_Shift], 0, Time[0], 0);

ObjectSet("S1 line", OBJPROP_RAY, 1);
ObjectSet("S1 line", OBJPROP_STYLE, STYLE_DASH);
ObjectSet("S1 line", OBJPROP_COLOR, _S_Color);


ObjectSet("R1 line", OBJPROP_RAY, 1);
ObjectSet("R1 line", OBJPROP_STYLE, STYLE_DASH);
ObjectSet("R1 line", OBJPROP_COLOR, _R_Color);

ObjectSet("R2 line", OBJPROP_RAY, 1);
ObjectSet("R2 line", OBJPROP_STYLE, STYLE_DASH);
ObjectSet("R2 line", OBJPROP_COLOR, _R_Color);


ObjectCreate("R1 label", OBJ_TEXT, 0, Time[0], 0);
ObjectCreate("R2 label", OBJ_TEXT, 0, Time[0], 0);

ObjectCreate("S1 label", OBJ_TEXT, 0, Time[0], 0);

ObjectId = 0;
return(0);
}
//-------------------------------------------------------------------------------------------
int deinit() {


ObjectDelete("R1 label");
ObjectDelete("R1 line");
ObjectDelete("R2 label");
ObjectDelete("R2 line");

ObjectDelete("S1 label");
ObjectDelete("S1 line");


ObDeleteObjectsByPrefix(OBJECT_PREFIX);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {

if ( _N_Time == Time[0] ) return(0);

double open,close, high, low, koeff1, koeff2,P, R1, R2, S1;
double _rates[][6];
double AverageRange;

ArrayCopyRates(_rates, NULL, _My_Period);
int err = GetLastError();
if(err == 4066) {
Sleep(1000);
if(iClose(NULL, _My_Period, 0) != Close[0]) {
Sleep(1000);
return(0);
}
}
close = _rates[1][4];
high = _rates[0][3];
low = _rates[0][2];
open = _rates[0][1];

AverageRange=0;
for (int i=1;i<ForDays+1;i++)
{
AverageRange=AverageRange+(_rates[i][3]-_rates[i][2])/Point;
}
AverageRange=NormalizeDouble(AverageRange/ForDays,0);
int _bars = iBarShift(Symbol(),Period(),iTime(Symbol(),1440,0),false);

R1 =MathMin(
(MathMin(iClose(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_OPEN,_bars,0)),
iOpen(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_OPEN,_bars,0)))),
(MathMin(iClose(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_CLOSE,_bars,0)),
iOpen(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_CLOSE,_bars,0)))));

R2 =MathMax(
(MathMax(iClose(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_OPEN,_bars,0)),
iOpen(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_OPEN,_bars,0)))),
(MathMax(iClose(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_CLOSE,_bars,0)),
iOpen(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_CLOSE,_bars,0)))));

Comment(R1,"\n",R2);
string s1,r1,r2;

s1 = DoubleToStr(S1, Digits);

r1 = DoubleToStr(R1, Digits);
r2 = DoubleToStr(R2, Digits);


//---- Pivot Lines
ObjectSetText("R1 label", " Min "+r1+"", 8, "Fixedsys", _R_Color);
ObjectSetText("R2 label", " Max "+r2+"", 8, "Fixedsys", _R_Color);
ObjectSetText("S1 label", " Open "+s1+"", 8, "Fixedsys", _S_Color);

ObjectMove("R1 label", 0, Time[0], R1);
ObjectMove("R2 label", 0, Time[0], R2);


ObjectMove("S1 label", 0, Time[0], S1);


ObjectMove("S1 line", 0, Time[_bars], S1);
ObjectMove("S1 line", 1, Time[0], S1);


ObjectMove("R1 line", 0, Time[_bars], R1);
ObjectMove("R1 line", 1, Time[0], R1);

ObjectMove("R2 line", 0, Time[_bars], R2);
ObjectMove("R2 line", 1, Time[0], R2);


//====

_N_Time = Time[0];
//---- End Of Program
return(0);
}
//+------------------------------------------------------------------+

void ObDeleteObjectsByPrefix(string Prefix)
{
int L = StringLen(Prefix);
int i = 0;
while(i < ObjectsTotal())
{
string ObjName = ObjectName(i);
if(StringSubstr(ObjName, 0, L) != Prefix)
{
i++;
continue;
}
ObjectDelete(ObjName);
}
}
//-------------------------------------------------------------------------------------------

Thanks

Antony

gordon
2325
gordon  

Please use the SRC button for code or attach it to the post! You have already been asked to this in the past.

Taskin Osman
778
Taskin Osman  

simply replace

Comment(R1,"\n",R2);

with

Comment(R1,"\n",R2," Difference is:",(R1-R2)/Point);

and it will show pip difference between R1 and R2, you may use other variables too like S1


fx1.net

antony
549
antony  

Hi

Excellent thank you. Works perfect.

Thanks

Antony

To add comments, please log in or register