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

Discussion in 'App Development' started by Thomas-M, Nov 21, 2019.

  1. Thomas-M

    Thomas-M

    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;
    }
     
  2. TommyR

    TommyR

    put your variables outside otherwise it will keep creating new one's which will catastrophically slow you down
     
  3. RedDuke

    RedDuke

    If you are new I suggest you try NinjaTrader, it has a full power of c# for custom code, tons of wizard capabilities, fantastic support and etc. It is free, until you need to submit a real trade.
     
  4. Thomas-M

    Thomas-M

    Thanks Tommy I didn't realize that at all.

    However, by looking at this, does it look like I am anywhere close to getting what I need? For example, I have seen from searching online, functions like MarketInfor() GetPrice, Mode etc...

    Do I need things like that in there, and is mine too basic to possibly do it right?

    Main thing I'm wondering, is it a job that's far from completion?
     
  5. Thomas-M

    Thomas-M

    Cheers RedDuke, I'll take a look, I've come across it before. Is that using a different language to MQL4? I assume NinjaTrader is a language or software yes?
     
  6. RedDuke

    RedDuke

    It is a software that was written and using c# aka C sharp.
     
  7. OP you need to learn to code first. Take a C# course and use NinjaTrader as that will be your fastest route to not being a total disaster.
     
  8. Actually, I take that back. You should probably just take some MQL4 courses. It's designed for people who don't really know how to code.
     
  9. Thomas-M

    Thomas-M

    And here it is :cool::)

    I didn't think it would be this easy at all, I thought fiercely complicated code would need to go into it. The main reason I was trying to get this done, was because I am actually studying
    MQL4 with a course on Udemy, but I just needed to get this done so that I wouldn't be distracted from learning by constantly looking at trading charts all day long. I know it seemed like the lazy way to get things, but now that I have this pretty much like 98% close to what I would consider perfect, I can now get on with the course and learn the basics the correct way.
    Not getting this done has been such a huge interference in my learning up until now. I can definitely say that having learned this, is going to be an absolute game-changer, not just from having it out of the way, but now I can see how much sooner it's going to be until placing trades with an actual trading robot, which makes what I know today pretty much levels higher than yesterday.

    And Cheers Tommy, that comment about having the variables outside is what done the trick.


    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 + AddPipp*Point;
    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 - SubtractPipp*Point;
    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.
     
  10. You seem to be the kind of person who is good at "learning by doing". Continue to come up with challenges for yourself and try to create the code for these. That will keep the course interesting to you, as you will see how you can use the things they teach in the course. Just keep on doing what you're doing and you will get there.
     
    #10     Nov 22, 2019
    Thomas-M likes this.