How do i check if current bar high is 2 pips greater that previous bars high?

 

I have a piece of code that look like this:

extern double PipsUp=3;

extern double PipsDown=3;

for (iCount=1; iCount<1; iCount++)

{

double HighHigh = High[0] + PipsDown/10000;

double LowHigh = High[0] - PipsDown/10000;

Comment ("High", High[0], " - HighHigh = ", HighHigh, " - LowHigh = ", LowHigh);

} //for iCount[/PHP]

I want to take the value of current candle's high and add e.g. 2 pips to it and then compare with previous candle high's value. like this: Is bla bla > bla bla ...

e.g 1.43566 + 2pips = 1.43576

It don't think it works with the 4/5 digit brokers problems when i use PipsDown/10000 so i have got this code below, but i'm not sure how to use it.

[PHP] //++++ These are adjusted for 5 digit brokers.

int pips2points; // slippage 3 pips 3=points 30=points

double pips2dbl; // Stoploss 15 pips 0.0015 0.00150

int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips)

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers.

pips2dbl = Point*10; pips2points = 10; Digits.pips = 1;

} else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; }

// OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl

}

So what i'm looking for is: What should i use instead of 10000 for it to work with 4/5 brokers? I have tried with pips2dbl but it doesn't work.

Thank you in advance for your help.

 

Variable Names and Past/Current Bars

Georgebaker:

I want to take the value of current candle's high and add e.g. 2 pips to it and then compare with previous candle high's value. like this: Is bla bla > bla bla ...

e.g 1.43566 + 2pips = 1.43576

It don't think it works with the 4/5 digit brokers problems when i use PipsDown/10000 so i have got this code below, but i'm not sure how to use it.

Thank you in advance for your help.

Hi George,

First, it helps if you name your variables to better show what they actually are...

Instead of HighHigh and LowHigh (because you won't really know each time if the LowHigh is higher or lower than the compared HighHigh bar)..

Use names like PrevHigh and CurrHigh or something similar to make it much clearer..

Secondly, your example is only getting the CURRENT bar...High[0]...so all the values will be the same.

Third, the decimal points should not be a problem for the calculation you are trying to do, since all the price decimals will always be the same for the same pair.

The decimal calculation is only needed when you place the trade or modify the trade.

For your formula, just use the same number of decimal places you see in the price (Close[0]) and assign it directly to your variable. One less calculation your EA needs to do.

Example:

PipsDown = 0.0002; -or-

PipsDown = 0.00020; -depending on your broker

Try the following for your code logic:

PrevHigh = High[1];

CurrHigh = High[0];

if (PrevHigh >= CurrHigh + PipsDown) Then do this;

Or you can compare and calculate them directly:

BarDiff = High[1] - High[0];

if (BarDiff > PipsDown) Then do this;

There are a number of ways to do what you want. Try different ways to see the best for your needs.

And always Print or Comment your values so you immediately know it's working the way you want.

Hope this helps,

Robert

 

Hi Robert,

I’m normally used these variable names, the reason that I use some other names right now is that I only want to look at one bar and I only want to get the high of the current bar at the moment. Then I’m trying to add and deduct 3 pips of the current bar High[0]

I just want to ‘debug’ the code so I can see what happens with the numbers and that it actually calculating correctly.

E.g. If High[0]=0.85370, then I want to see that HighHigh is 0.85400 when I add 3 pips to High[0] and 0.85330 when I deduct 3 pips from High[0], that’s all I want to do at the moment.

What you’re explaining with ‘Prev’ and ‘Curr’ comes after

My problem is that I don’t think I can use 10000 in this line below. I need to use some of the code from the second section that controls the 4/5 digits

‘double HighHigh = High[0] + PipsDown/10000;’

Hope you understand what i mean.