Help with order after 20pips

 

Hi guys,

I am very new to MQL5, have written myself an EA but I am stuck. I have a simple strategy as I am just testing creating EA's.

I have a strategy where i have 2 EMA's (fast and slow EMA) when they crossover, I create a buy or sell order, I have also been able to set a fixed sl and tp and a set trade size.

My question is, I want to delay the order. When the EMA's cross, I want to add the buy or sell order after 20 PIPS. Only rule is that EMA's must not have a crossover prior to price getting to 20pips.

So EMA's crossover, price moves 20pips before EMA's crossover again, enter an order.

What I currently have for a buy order:

if(fastMaArray[0] > slowMaArray[0] && fastMaArray[1] < slowMaArray[1]) {

         Print("Fast MA is now > than slow MA");

         double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);

         double sl = ask - 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);

         double tp = ask + 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);

         trade.Buy(0.01,_Symbol,ask,sl,tp,"This is a buy order");

Any help here would be greatly appreciated.

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
konadams70:

Hi,

to share code use the 'Code' button. I have corrected this for this time.

 

 
  1. konadams70: I want to delay the order. When the EMA's cross, I want to add the buy or sell order after 20 PIPS.

    Any help here would be greatly appreciated.

    Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
              No free help (2017)

  2.          double sl = ask - 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);
             double tp = ask + 100 * SymbolInfoDouble(_Symbol,SYMBOL_POINT);

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

 

Hi William,

You know, I've been in the I.T. industry for over 20 years as a systems engineer. Often using forums to provide help and to offer help.

I always run into people like you. Angry and toxic. I hope you feel good about yourself with you post trying to belittle me and others and I say others because scrolling through this forum looking for answers I have seen your posts and they are all the same.

Please, do us all a favour, go outside, see some sunlight, smell the grass, get some fresh air. We don't need you here. You can either help someone starting out on their journey of learning to code this language or skip by. Its not that hard.

Be nice, thats not hard either.



William Roeder #:
  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
              No free help (2017)

  2. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

 
konadams70:

Hi guys,

I am very new to MQL5, have written myself an EA but I am stuck. I have a simple strategy as I am just testing creating EA's.

I have a strategy where i have 2 EMA's (fast and slow EMA) when they crossover, I create a buy or sell order, I have also been able to set a fixed sl and tp and a set trade size.

My question is, I want to delay the order. When the EMA's cross, I want to add the buy or sell order after 20 PIPS. Only rule is that EMA's must not have a crossover prior to price getting to 20pips.

So EMA's crossover, price moves 20pips before EMA's crossover again, enter an order.

What I currently have for a buy order:

Any help here would be greatly appreciated.

Hi! I would compare candle 1 and candle 2 for crossover if(mafast(2)<maslow(2) && mafast(1)>maslow(1)) targetbuy=Ask+20*_Point; 
You reset targetbuy to 0 if crossing back. And then if (Ask > targetbuy && targetbuy!=0 ) open buy trade and reset targetbuy to 0 again
 
konadams70 #: I always run into people like you. Angry and toxic.

I always run into people like you, wanting a slave to code things for them for free.

When you work and have a problem, do you pass it to a coworker and want them to code it for you? No, you don't. Then why do you think you can here?

konadams70: I want to … I want to … Any help here would be greatly appreciated.

Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
          No free help (2017)

konadams70 #: We don't need you here. 
  1. Others disagree with you.

    Thank you, William Roeder! - General - MQL5 programming forum (2022)

  2. On my Do Not Help List, live in ignorance Snowflake.
 
Daniel Cioca #:
Hi! I would compare candle 1 and candle 2 for crossover if(mafast(2)<maslow(2) && mafast(1)>maslow(1)) targetbuy=Ask+20*_Point; 
You reset ta
Daniel Cioca #:
Hi! I would compare candle 1 and candle 2 for crossover if(mafast(2)<maslow(2) && mafast(1)>maslow(1)) targetbuy=Ask+20*_Point; 
You reset targetbuy to 0 if crossing back. And then if (Ask > targetbuy && targetbuy!=0 ) open buy trade and reset targetbuy to 0 againHi

Hi Daniel,

Thanks for your help. I will try and work it out with this, hope I can.

Much appreciated. 

Reason: