OrderClose triggered right after OrderSend

 

Hi everybody,

i have tried to fix this problem during the last days, but i really can't find where the mistake is.

i just want my EA to close an order when a specific condition is true, but it is triggered right after i open it.

i have read and tried several proposal from this forum, but none i have been able to adjust for my EA.

i hope someone can help me.

Thanks

Luca

P.S.

I know EA builders are not always good but i am not still good enough to write a new one from scratch.. :)

Files:
 
  1. Kuks: I know EA builders are not always good but i am not still good enough to write a new one from scratch.. :)

  2. EA builder, fxDreema, EATree, FxPro Quant, MQL5 Wizard, etc. are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.
    • Since you haven't learned MQL4/5, therefor there is no common language for us to communicate.
      If we tell you what you need, you can't code it.
      If we give you the code, you don't know how to integrate it into yours.
      We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

    • EA builder makes bad code counting up while closing multiple orders.
      EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
      EA builder makes bad code, not adjusting for 4/5 digit brokers, TP/SL and slippage.
      EA builder makes bad code, not adjusting for ECN brokers. (pre-Build 500)
      EA builder makes bad code, not checking return codes.
      EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)

  3.    bool newBars216 = false;
       static int lastBars5607;
       if ( lastBars5607 == 0 )  lastBars5607=Bars;
       if ( lastBars5607 != Bars )
    
    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              New candle - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. _fnOpenSell2 = OrderSend(  Symbol() , OP_SELL , fnFixLots(Lots) , MarketInfo(Symbol(), MODE_BID) , Slippage , SELL_STOP_LOSS , tpzero9913 , StringConcatenate(eaname1277,":", MagicNumber) , MagicNumber , 0 , CLR_NONE  );
    
    Check your return codes for errors and report them.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  5. int start(){
    int init( )
    int deinit( )
    
    Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference

  6. Kuks: but i really can't find where the mistake is.

    i just want my EA to close an order when a specific condition is true, but it is triggered right after i open it.

    Your open and close conditions are contradictory. Use the debugger or print out your variables, and find out why.

  7. Kuks: i have read and tried several proposal from this forum, but none i have been able to adjust for my EA.

    Don't double post!
              General rules and best pratices of the Forum. - General - MQL5 programming forum
File Functions - MQL4 Reference
File Functions - MQL4 Reference
  • docs.mql4.com
For security reasons, work with files is strictly controlled in the MQL4 language. Files with which file operations are conducted using MQL4 means cannot be outside the file sandbox. the common folder for all the terminals installed on a computer - usually located in the directory C:\Documents and Settings\All Users\Application...
 
whroeder1: That's not an EA builder, it is decompiled code (li9048) that has been partially humanized (total9048.)

In this case, I don't think it is decompiled code, but what "Visual Trader Studio" actually outputs (for some unknown reason).

EDIT: Confirmed, I took a look at the documentation and see that it is the case - it does output those "numeric" variable names.

The following image was taken from the documentation as is. I did not edit it or add the arrows.


 

whroeder1,

  1. i can guarantee you that all i did is lawful, i pay a monthly fee for the Visual Trader Studio which lets me create my own EA.
    Since the free version lets you create the ex4 file, and the paid version generates also the mq4 file, i believe that here is where the EA is decompiled.
    Visual Trader Studio do not decompile someone else ex4 files (i can send you its file where i built the schema and try yourself to build it).


I believe you ended up to your conclusion too easily, and since this is not my job but an hobby i am free to try, make mistakes and ask to this forum some help.

Anyway, thank you for the other points, i don't know how to use them but i will try to, if in the meanwhile someone can fix the errors i would really appreciate it.

Thanks

Luca

 

And just in case, the MACD_Platinum_Original comes with a book written by Jim Brown "MT4/MT5 High probability forex trading method" which i have regularly bought.

I am simply trying to convert his concept into an EA.

 
Kuks:

whroeder1,

  1. i can guarantee you that all i did is lawful, i pay a monthly fee for the Visual Trader Studio which lets me create my own EA.
    Since the free version lets you create the ex4 file, and the paid version generates also the mq4 file, i believe that here is where the EA is decompiled.
    Visual Trader Studio do not decompile someone else ex4 files (i can send you its file where i built the schema and try yourself to build it).

Please forgive @whroeder1. It was an honest mistake and most of us would have made the same assumption about those "weird" numeric variable names, because they appear on the forum many times from people using decompiled code, which causes them to be banned.

Since most of the experienced users here, do not use "EA Builders", nor do we support them, we did not know that this particular application produced these weird variable names.

However, everything else he stated is true and you should listen to his advice.

It is not at all advisable for you to use "EA Builders" because they produce very bad code, and since you don't know how to code yourself, you will not be able to understand the reasons, not the advice we give you on how to fix it.

So, I greatly advise you to learn proper coding yourself instead, and I am supplying the following book references to help you out, be that in MQL4 or MQL5 (listing both books):

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.

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:48

Expert Advisor Programming for MetaTrader 5


This book will teach you the following concepts:

  • Learn the basics of MQL5, including variables and data types, operators, functions, event handlers, and object-oriented programming.
  • Place, modify and close market and pending orders.
  • Calculate, verify and add stop loss and take profit prices to an open position.
  • Add a flexible trailing stop and/or break even stop to your strategy.
  • Manage your trade risk with money management.
  • Use pending orders to scale in and out of positions.
  • Use price, time and indicator data in your expert advisors.
  • Control program execution by trading on new bar open, and add flexible trade timers to your strategies.
  • Walk through the creation of several basic trading strategies from start to finish.
  • Inform the user with dialog boxes, email alerts, mobile notifications and sounds.
  • Draw trend lines, arrows and text labels on the chart.
  • Read and write data to CSV files.
  • Learn the basics of creating indicators, scripts and libraries in MetaEditor.
  • Debug, test and optimize your trading strategy.
  • And much more!

Whether you’re an experienced programmer moving from MQL4, or a novice just starting with MQL5, this book will give you the foundation to quickly program fully-featured and robust trading systems.



 

Fernando,

i had understood that you both could "see" something that i couldn't and that made my file looked liked "cracked".

I have bought the MT4 book (290 pages!), i will try to find some time to read it between family and work.

Regarding whroeder1, i am totally fine and i understand that decompiling should not be done and also i understand  why programmers hate it.


Thank you for the link, i lazily searched this book only on Amazon and it was only available in hard format, that's why i didnt buy it, now that i have it, i have to study!

Hope to help someone sooner or later

Luca

 
Kuks:

Thank you for the link, i lazily searched this book only on Amazon and it was only available in hard format

also available in pdf (ebook format) from the website here or here.
but i still prefer hard format :)

Expert Advisor Programming for MetaTrader 4 | Expert Advisor Programming for MetaTrader
Expert Advisor Programming for MetaTrader 4 | Expert Advisor Programming for MetaTrader
  • expertadvisorbook.com
Expert Advisor Programming for MetaTrader 4 Brand new and fully updated for the latest versions of MetaTrader 4, is a practical guide to programming expert advisors in the MQL4 language. Leverage the latest features imported from the MQL5 language, including object-oriented programming, enumerations, structure and more. This book will teach...
 
Mohamad Zulhairi Baba: also available in pdf (ebook format) from the website here or here. but i still prefer hard format :)
Those links were already provided above in my post, and that is where the OP purchased his copy (as he himself stated)!
Reason: