Trying to create an EA that will tell me every time the price moves by about 10 points

Hi

I’m fairly new to coding and especially to MQL4. I’ve tried the below code in a few different ways. What I am trying is,
Create a start price level, and if the Ask price is higher than this level, automatically create a new target level, which would be the current Ask price, plus 10 points (and for the first question to become disabled (in place of the new question) in order to stop getting infinite alerts when price is above. And now, if the price goes another 10 points higher, the alert will be triggered again, repeating the last steps. And the same for the opposite direction, so any time a level is hit, then a new target is put up above and below of 10 points.

I have some ideas, but I’m finding it difficult to implement the code, and may be missing a few functions or statements that are needed in MQL4.

Like for example, if the first level to check is above the start price level, then keep asking the question, but as soon as the Ask price goes above this level, stop asking the question and send an alert, but now start asking a new question for another 10 points higher than the ask price that triggered the alert.

So if someone can tell me what I need to get acquainted with here I would very much appreciate it. Below is one way I tried to do it, but I haven’t done anything much better than that.

Thanks

extern int AddPipp = 1000;
extern int SubtractPipp = 1000;

void OnTick()
{

double target = 27820;

if(Ask > target)

Alert(Ask);

target target + AddPipp*Point;
}

Need to put outside of OnTick() function the first target level.
And need to add a new loop to working properly.
Convert pips from integer to double.
Try this code…

extern double AddPipp = 1000;
extern double SubtractPipp = 1000;

double target = 27820;
void OnTick()
{
if(Ask > target)
{
Alert(Ask);
target + = AddPipp*Point;
}
}

Thanks Pannik

I have just done what you said, and can now understand the power of keeping things outside. And it is definitely a big step toward what I want. See below, I out the target at 27760, the price was at 27770 at the time, it triggered once (which is correct), then as soon as it got to 27780 it triggered again. So far that’s exactly what I’m looking for. Now all I need to do is, somehow combine both the Ask direction and the Bid direction, so if it goes down 10 points, from the beginning trigger, but also update it so that if it goes up 10 points from the start, then if it goes back down ten points trigger again and so on, so basically, 10 up trigger, 10 back down trigger 10 up trgger, 10 up again trigger.

For a while I thought this would never happen for me, but finally from this progress right now I can finally see some light. Thanks very much, I appreciate that. A tiny fix, but a huge outcome for me.

double target = 27760;
void OnTick()
{
if(Ask > target)
{
Alert(Ask);
target = target + AddPipp*Point;
}
}

Here we go. Finally!!! I’ve been trying to get this done for weeks :tired_face:

This is a massive step forward, now I can stop looking at a chart all existing minutes of the day and focus on actually studying MQL from the basics up, the correct way.

Thanks again, such a small little tweak, with a massive result.

extern double AddPipp = 1000;
//extern double Add5Pipps = 500;
extern double SubtractPipp = 1000;

double Asktarget = 27760;
//double Asktarget9 = 27769;
double Bidtarget = 27740;

void OnTick()
{
if(Ask > Asktarget) //remember, ask is the higher one.

{
Alert("Dow Ask is Higher ",Ask);
SendNotification("Dow Ask is Higher " + Ask);

Asktarget = Asktarget + AddPippPoint;
Bidtarget = Bidtarget + AddPipp
Point;

}

/*
{
if(Ask > Asktarget9)

Bidtarget = Bidtarget + Add5Pipps*Point;

Far too much code needed, and potential errors, to do it this way for now.
Better to start the entire program with an isfirsttick statement,
and when it is the first tick, change the values of The initial Ask and Bid targets, to
reflect a space where there will be a target of 10 points between the two.
It can be done, by making the Ask target, be 1 point below the Ask price.

If Offset erros happen later on, just reset the program. This is a temporary fix.
}

*/

if(Bid < Bidtarget)
{
Alert("Dow Bid is Lower ", + Bid);
SendNotification("Dow Bid is Lower " + Bid); //Bid is the Lower one

Bidtarget = Bidtarget - SubtractPippPoint;
Asktarget = Asktarget - SubtractPipp
Point;

}

}

//Some minor offset errors, with no immediate need to fix:
//If Ask is hit at about 21 points higher, it will raise the new Ask level by 30 points,
//while it will also raise the Bid by 30 points. If the initial prices are set intervals
//of 20 apart, then the Bid price will only have to travel about 7 points to reach the Bid alert.

//If however, the level that the Ask price hits, is about 27 points above, this will do the same
//as the above comment in the beginning, but now, the bid price will need to travel about 13 points
//to hit the Bid alert, while also making the new alert target for the Ask price, to be only 3
//points away.

You can to reset targets base on current prices, as example.

if(Bid < Bidtarget)
{
Alert("Dow Bid is Lower ", + Bid);
SendNotification("Dow Bid is Lower " + Bid); //Bid is the Lower one

Bidtarget -= SubtractPippPoint;
Asktarget = Ask + SubtractPippPoint;

}