Positioning problem

 
Good evening to all,
I have a problem when I try to run my algorithm which should take a position as soon as the price reaches 10 points before launching the next trade but my algorithm does not take any position, do you know why? 
Here is the code: 

extern int priceinit = 0;

extern int i = 0;

void OnTick()

  {

      priceinit = Ask;

         

      if (Ask==priceinit+100*_Point && OrdersTotal()==0)

          { 

         

            OrderSend (_Symbol,OP_BUY,AccountBalance()/100000,Ask,3,Ask-500*_Point,Ask+100*_Point,NULL,0,0,Green);


          }

    

  }




Thanks in advance and have a nice evening :-D
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  3. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at 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 to 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 (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  4. Lot Size must be a multiple of Lot Step and be at least Min Lot.
 
William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  3. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at 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 to 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 (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  4. Lot Size must be a multiple of Lot Step and be at least Min Lot.

Thank you for your reply, but I don't quite understand your answers... What exactly do I have to change for my program to work? I think it's in the Ask, because in the other programs the change of order works without any problem...


Thank you in advance. 

 
Hugo Tram: What exactly do I have to change for my program to work?

Everything! You have to change everything, because it is ALL wrong!

Try to first learn the language properly, before attempting to write an EA.

You will also have to learn the trading concepts as well, not just the coding. Without the trading knowledge you will not know what to program.

For the coding, I suggest reading a book, for example this one:

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:40

Expert Advisor Programming for MetaTrader 4


This book will teach you the following concepts:

  • The basic of the MLQ4 language, including variables and data types, operations, conditional and loop operators, functions, classes and objects, event handlers and more.
  • Place, modify and close market and pending orders.
  • Add a stop loss and/or take profit price to an individual order, or to multiple orders.
  • Close orders individually or by order type.
  • Get a total of all currently opened orders.
  • Work with OHLC bar data and locate basic candlestick patterns.
  • Find the highest high and lowest low of recent bars.
  • Work with MetaTrader’s built-in indicators, as well as custom indicators.
  • Add a trailing stop or break even stop feature to an expert advisor.
  • Use money management and lot size verification techniques.
  • Add a flexible trading timer to an expert advisor.
  • Construct several types of trading systems, including trend, counter-trend and breakout systems.
  • Add alert, emails, sounds and other notifications.
  • Add and manipulate chart objects.
  • Read and write to CSV files.
  • Construct basic indicators, scripts and libraries.
  • Learn how to effective debug your programs, and use the Strategy Tester to test your strategies.

All of the source code in this book is available for download, including an expert advisor framework that allows you to build robust and fully-featured expert advisors with minimal effort.


 
Hugo Tram:

As William has already said

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

      priceinit = Ask;
      if (Ask==priceinit+100*_Point && OrdersTotal()==0)

This is the same as

     if (Ask==Ask+100*_Point && OrdersTotal()==0)

Do you really think that Ask can equal Ask + n ??

 
Fernando Carreiro:

Everything! You have to change everything, because it is ALL wrong!

Try to first learn the language properly, before attempting to write an EA.

You will also have to learn the trading concepts as well, not just the coding. Without the trading knowledge you will not know what to program.

For the coding, I suggest reading a book, for example this one:


Yes thank you, it seems to be a very good book, do you think it is complete and covers all the concepts of programming in MQL4? 


Thanks

 
Keith Watford:

As William has already said

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

This is the same as

Do you really think that Ask can equal Ask + n ??

1) Yes, I see... Usually it was done automatically without me having to do any manipulation...


2) Yes, that's exactly what I was thinking, but how do you lock in the price of priceinit at ASK? And that as soon as the ace has taken 10 points from Price init then place a buy order? The worry is to lock in the value of the price init? But how to do it?


Thanks a lot 

Reason: