Coding questions ... - page 2

 

Ray

If you want to use TimeFrame as a first parameter to HAMA indicator (first parameter after the indicator name in iCustom() call) then it must be defined as string.

If, on the other hand, you want to use it as a second parameter of iCustom() call, then it has to be defined as integer (int) and in that case you can pass "" (empty string) as a first parameter to the indicator itself. So, in the form you are using it now, change
extern int TimeFrame = 0;[/PHP]

to

[PHP]extern string TimeFrame = "";

But be aware that in second case previous bar might not mean previous bar of a target time frame but a previous bar of a mtf indicator in a current time frame

traderduke:
Mladen

I'm sure this question will be redundent but I can't get it to work so here goes another MTF question. My EA calls the Indicator for that chart it is on and works great. I can't get the MTF to work correctly, for instance 1m chart with 15m indicator. The indicator works on the chart as you can see but the EA will only use the Chart TF. I 'm sure I got the layout wrong near line 1672 to 1750 is the area of the problem.

Can you help??

Ray
 

mladen

I made the changes BUT---see chart. As you can see The Sell arrow was based on the 1m chart not the 5min. I changed the input to a string see chart and the custom to a string see the chart, what am I missing?? I'm also getting weird hits in the Experts tab of the terminals,"cannt resize the array and in and outs on the indicator.

Ray

 

Ray

All you had to change is the extern int TimeFrame to extern string TimeFrame

Do not change the iCutom() calling line (it was OK - remove the "" surrounding TimeFrame, and enter in parameters (type it in) a time frame you wish to use (5 in your case) when you start the test or EA working))

PS: please reread the last part of my previous message - if you wish to check the previous bar of a target time frame do not use the form you are using now, since you are not going to get results that you expect, but use the iCustom(NULL,TimeFame,indicatorName,"",... the rest of parameters) form - that way you will get the expected result and don't forget to turn the TimeFrame parameter to int for that form of iCustom() call)

 

weird label behavior...

Hi everybody,

I have a small problem but it's driving me nut ...

The subroutine below is working fine; my problem start if I active the instruction to draw the background panel (right now excluded at the end of the subroutine), the "atr" label disappear.

I've tried everything without success. Please Help me ...!!!!!!

Thanks in advance for reply

Best Regards

void Reminder()

{

day1shift = 0; if(TimeDayOfWeek(iTime(NULL, PERIOD_D1, day1shift)) == 0) day1shift++;

day2shift = day1shift + 1; if(TimeDayOfWeek(iTime(NULL, PERIOD_D1, day2shift)) == 0) day2shift++;

rmndr1 = UniqueID + " rmndr1";

rmndr2 = UniqueID + " rmndr2";

dow = TimeDayOfWeek(iTime(NULL, PERIOD_D1, day1shift));

switch(dow)

{

case 0: dowStr = "S u n d a y"; break;

case 1: dowStr = "M o n d a y"; break;

case 2: dowStr = "T u e s d a y"; break;

case 3: dowStr = "W e d n e s d a y"; break;

case 4: dowStr = "T h u r s d a y"; break;

case 5: dowStr = "F r i d a y"; break;

}

fullatr1 = iATR (NULL, PERIOD_D1, ATRPeriod, day1shift) / (Point * modifier);

LowYesterday = iLow (NULL, PERIOD_D1, day2shift);

HighYesterday = iHigh (NULL, PERIOD_D1, day2shift);

HighToday = iHigh (NULL, PERIOD_D1, day1shift);

LowToday = iLow (NULL, PERIOD_D1, day1shift);

RangeToday = MathAbs (HighToday - LowToday) / (Point * modifier);

string box = UniqueID + " Data Box";

string atr = UniqueID + " ATR";

string HY = UniqueID + " HY";

string LY = UniqueID + " LY";

string RT = UniqueID + " RT";

int Xdist = 15;

int Ydist = 36;

int Yoffset = 14;

ObjectCreate (rmndr1, OBJ_LABEL, 0, 0, 0);

ObjectSet (rmndr1, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (rmndr1, OBJPROP_XDISTANCE, Xdist);

ObjectSet (rmndr1, OBJPROP_YDISTANCE, 18);

ObjectSet (rmndr1, OBJPROP_BACK, false);

ObjectSetText (rmndr1, "P i v o t s D _ v 6 - " + dowStr, 9, "Tahoma Bold", Gainsboro);

ObjectCreate (rmndr2, OBJ_LABEL, 0, 0, 0);

ObjectSet (rmndr2, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (rmndr2, OBJPROP_XDISTANCE, Xdist);

ObjectSet (rmndr2, OBJPROP_YDISTANCE, Ydist);

ObjectSet (rmndr2, OBJPROP_BACK, false);

ObjectSetText (rmndr2, "Mode : " + mode + " - " + timeframe, 9, "Tahoma", Reminder_Color);

ObjectCreate (atr, OBJ_LABEL, 0, 0, 0);

ObjectSet (atr, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (atr, OBJPROP_XDISTANCE, Xdist);

ObjectSet (atr, OBJPROP_YDISTANCE, Ydist + Yoffset);

ObjectSet (atr, OBJPROP_BACK, false);

ObjectSetText (atr, "ATR (" + ATRPeriod + ") : " + DoubleToStr(fullatr1, 1) + " pips", 9, "Tahoma", Reminder_Color);

ObjectCreate (RT, OBJ_LABEL, 0, 0, 0);

ObjectSet (RT, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (RT, OBJPROP_XDISTANCE, Xdist);

ObjectSet (RT, OBJPROP_YDISTANCE, Ydist + Yoffset*2);

ObjectSet (RT, OBJPROP_BACK, false);

ObjectSetText (RT, "Range Today : " + DoubleToStr(RangeToday, 1) + " pips", 9, "Tahoma", Reminder_Color);

ObjectCreate (HY, OBJ_LABEL, 0, 0, 0);

ObjectSet (HY, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (HY, OBJPROP_XDISTANCE, Xdist);

ObjectSet (HY, OBJPROP_YDISTANCE, Ydist + Yoffset*3);

ObjectSet (HY, OBJPROP_BACK, false);

ObjectSetText (HY, "High Yesterday : " + DoubleToStr(HighYesterday, dig), 9, "Tahoma", Reminder_Color);

ObjectCreate (LY, OBJ_LABEL, 0, 0, 0);

ObjectSet (LY, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (LY, OBJPROP_XDISTANCE, Xdist);

ObjectSet (LY, OBJPROP_YDISTANCE, Ydist + Yoffset*4);

ObjectSet (LY, OBJPROP_BACK, false);

ObjectSetText (LY, "Low Yesterday : " + DoubleToStr(LowYesterday, dig), 9, "Tahoma", Reminder_Color);

/* ObjectCreate (box, OBJ_LABEL, 0, 0, 0);

ObjectSet (box, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (box, OBJPROP_XDISTANCE, 8);

ObjectSet (box, OBJPROP_YDISTANCE, 12);

ObjectSet (box, OBJPROP_COLOR, Reminder_Bkgrnd_Color);

ObjectSet (box, OBJPROP_BACK, false);

ObjectSetText (box, "gg", 76, "Webdings"); */

}

 

brax

Change this line (for box object only)
ObjectSet (box, OBJPROP_BACK, false);[/PHP]

to this
[PHP]ObjectSet (box, OBJPROP_BACK, true);

then it looks like this on my PC (patched it to one indicator and I used some default colors )

regards

Mladen

Files:
brax.gif  25 kb
 

Thanks for reply Mladen,

I've already tried that solution, but is not what I want. The purpose of the background box colored is to keep the info visible when the candles/bars are in that area of the chart; also the background box color will be "added" to the background color of the chart.

And, main thing, why only the atr label disappear?

mladen:
brax Change this line (for box object only)
ObjectSet (box, OBJPROP_BACK, false);[/PHP]
to this
[PHP]ObjectSet (box, OBJPROP_BACK, true);

regards

Mladen
 

brax

Now I understand

Here you go (it looks like this now - as you see it is not transparent any more). The thing is that metatrader arranges the drawing order of objects according to their names, so you have to keep the names in ascending order if you want an exact order of drawing

and the code :

void Reminder()

{

int day1shift = 0; if(TimeDayOfWeek(iTime(NULL, PERIOD_D1, day1shift)) == 0) day1shift++;

int day2shift = day1shift + 1; if(TimeDayOfWeek(iTime(NULL, PERIOD_D1, day2shift)) == 0) day2shift++;

string rmndr1 = UniqueID + "5";

string rmndr2 = UniqueID + "6";

int dow = TimeDayOfWeek(iTime(NULL, PERIOD_D1, day1shift));

string dowStr;

switch(dow)

{

case 0: dowStr = "S u n d a y"; break;

case 1: dowStr = "M o n d a y"; break;

case 2: dowStr = "T u e s d a y"; break;

case 3: dowStr = "W e d n e s d a y"; break;

case 4: dowStr = "T h u r s d a y"; break;

case 5: dowStr = "F r i d a y"; break;

}

double fullatr1 = iATR (NULL, PERIOD_D1, ATRPeriod, day1shift) / (Point * modifier);

double LowYesterday = iLow (NULL, PERIOD_D1, day2shift);

double HighYesterday = iHigh (NULL, PERIOD_D1, day2shift);

double HighToday = iHigh (NULL, PERIOD_D1, day1shift);

double LowToday = iLow (NULL, PERIOD_D1, day1shift);

double RangeToday = MathAbs (HighToday - LowToday) / (Point * modifier);

string box = UniqueID + "0";

string atr = UniqueID + "1";

string HY = UniqueID + "2";

string LY = UniqueID + "3";

string RT = UniqueID + "4";

int Xdist = 15;

int Ydist = 36;

int Yoffset = 14;

ObjectCreate (rmndr1, OBJ_LABEL, 0, 0, 0);

ObjectSet (rmndr1, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (rmndr1, OBJPROP_XDISTANCE, Xdist);

ObjectSet (rmndr1, OBJPROP_YDISTANCE, 18);

ObjectSet (rmndr1, OBJPROP_BACK, false);

ObjectSetText (rmndr1, "P i v o t s D _ v 6 - " + dowStr, 9, "Tahoma Bold", Green);

ObjectCreate (rmndr2, OBJ_LABEL, 0, 0, 0);

ObjectSet (rmndr2, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (rmndr2, OBJPROP_XDISTANCE, Xdist);

ObjectSet (rmndr2, OBJPROP_YDISTANCE, Ydist);

ObjectSet (rmndr2, OBJPROP_BACK, false);

ObjectSetText (rmndr2, "Mode : " + mode + " - " + timeframe, 9, "Tahoma", Reminder_Color);

ObjectCreate (atr, OBJ_LABEL, 0, 0, 0);

ObjectSet (atr, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (atr, OBJPROP_XDISTANCE, Xdist);

ObjectSet (atr, OBJPROP_YDISTANCE, Ydist + Yoffset);

ObjectSet (atr, OBJPROP_BACK, false);

ObjectSetText (atr, "ATR (" + ATRPeriod + ") : " + DoubleToStr(fullatr1, 1) + " pips", 9, "Tahoma", Reminder_Color);

ObjectCreate (RT, OBJ_LABEL, 0, 0, 0);

ObjectSet (RT, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (RT, OBJPROP_XDISTANCE, Xdist);

ObjectSet (RT, OBJPROP_YDISTANCE, Ydist + Yoffset*2);

ObjectSet (RT, OBJPROP_BACK, false);

ObjectSetText (RT, "Range Today : " + DoubleToStr(RangeToday, 1) + " pips", 9, "Tahoma", Reminder_Color);

ObjectCreate (HY, OBJ_LABEL, 0, 0, 0);

ObjectSet (HY, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (HY, OBJPROP_XDISTANCE, Xdist);

ObjectSet (HY, OBJPROP_YDISTANCE, Ydist + Yoffset*3);

ObjectSet (HY, OBJPROP_BACK, false);

ObjectSetText (HY, "High Yesterday : " + DoubleToStr(HighYesterday, dig), 9, "Tahoma", Reminder_Color);

ObjectCreate (LY, OBJ_LABEL, 0, 0, 0);

ObjectSet (LY, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (LY, OBJPROP_XDISTANCE, Xdist);

ObjectSet (LY, OBJPROP_YDISTANCE, Ydist + Yoffset*4);

ObjectSet (LY, OBJPROP_BACK, false);

ObjectSetText (LY, "Low Yesterday : " + DoubleToStr(LowYesterday, dig), 9, "Tahoma", Reminder_Color);

ObjectCreate (box, OBJ_LABEL, 0, 0, 0);

ObjectSet (box, OBJPROP_CORNER, Reminder_Corner);

ObjectSet (box, OBJPROP_XDISTANCE, 8);

ObjectSet (box, OBJPROP_YDISTANCE, 12);

ObjectSet (box, OBJPROP_COLOR, Reminder_Bkgrnd_Color);

ObjectSet (box, OBJPROP_BACK, false);

ObjectSetText (box, "gg", 76, "Webdings");

}

As you can see only the names are modified in order to let the background the first in metatrader list of objects

regards

Mladen

brax64:
Thanks for reply Mladen,

I've already tried that solution, but is not what I want. The purpose of the background box colored is to keep the info visible when the candles/bars are in that area of the chart; also the background box color will be "added" to the background color of the chart.

And, main thing, why only the atr label disappear?
Files:
brax_ok.gif  24 kb
 

Hi again Mladen,

thank you very much!!!! now is perfect..

some time coding is a "tricky thing..."

mladen:
brax

Now I understand

Here you go (it looks like this now - as you see it is not transparent any more). The thing is that metatrader arranges the drawing order of objects according to their names, so you have to keep the names in ascending order if you want an exact order of drawing

Mladen
 

ATR calculation - exclude sunday bar

Can anyone share with me code snippet to exclude Sunday bar in ATR calculation?

Thanks in advance.

 

RSI Levels on Chart

hello,

i want to program an indicator which displays rsi levels, for example 70 for overbought or 30 for oversold on the chart.

the idea is to use these levels as a channel.

as far as i understand the rsi calculation, it should be possible to calculate the distance to a given level from the current closing price.

the levels should exactly correspond with the rsi in the separate window.

i also dont need to show the rsi itself on the chart.

does anybody of you know how i could do this calculation?

thank you and best regards,

mike

Reason: