# Check if market already hit the line?

175

Hey Guys,

I'm actually programming an EA who should by or sell if he is above or below a specified line. The prices for the specified lines I'm getting with this code:

//lowest and highest are datatime values. So I get a two specified bars!

//Beginning
leftToShiftLowest = iBarShift(NULL, 0, lowest);

//End
leftToShiftHighest = iBarShift(NULL, 0, highest);

Print("index of the bar for the time ",TimeToStr(lowest)," is ",leftToShiftLowest);
Print("index of the bar for the time ",TimeToStr(highest)," is ",leftToShiftHighest);

//Shifts for highest and lowest price
lowestShifts = iLowest(NULL, 0, MODE_LOW, ((leftToShiftLowest - leftToShiftHighest) + 1), leftToShiftHighest);
highestShifts = iHighest(NULL, 0, MODE_HIGH, ((leftToShiftLowest - leftToShiftHighest) + 1), leftToShiftHighest);

//Lowest Preis:
lowestPrice = iLow(NULL, 0, lowestShifts);

//Highest Preis:
highestPrice = iHigh(NULL, 0, highestShifts);

The nice thing is, that if a new Bar is appear, MQL is counting it. So it is much easier to implement this!
But I have one problem and I don't know, how I can solve this!

Namly, how can I check in real time, if the market already broken out?
Because if the market  did already broken out, the EA isn't allowed to trade anymore. He should only be allowed to trade at the break out. But not if the price is some where else and the buy/sell conditions are true. So I need one bool who is setted true, if the market did already broken out, so that the EA is not allowed to trade anymore.

Does anybody has an idea, how I can implement that?

Greetings and Thank You!

Moderator
8293

I am a bit confused by your code. Maybe it is due to poorly named variables

lowest and highest are datatime values but their names suggest that they are shift indexes. Would startTime and endTime be more self descriptive?

Also

leftToShiftLowest changed to leftToShiftStart and leftToShiftHighest changed to leftToShiftEnd or something similar

Anyway, still using your confusing variable names, you could try something like this

int latesttLowest = iLowest(NULL, 0, MODE_LOW, (leftToShiftLowest ,1);
if(latestLowest< leftToShiftHighest)
{
//Breakout to the low has already happened
}

175

What is your code doing? - I don't getting the sense...

I want to make sure, that the EA is only trading the break out and if it has already broken out and the Buy/Sell conditions are true, the EA should check, if the market has already broken out and if yes, the EA is not allowed to trade, though the conditions are true!
How can I do that?

Moderator
8293

Jan:

What is your code doing? - I don't getting the sense...

What don't you understand?

Jan:

I want to make sure, that the EA is only trading the break out and if it has already broken out and the Buy/Sell conditions are true, the EA should check, if the market has already broken out and if yes, the EA is not allowed to trade, though the conditions are true!
How can I do that?

then put something in here

{
//Breakout to the low has already happened
}