There are two ways to do it:
- way: to build a mechanism for closing positions into an existing MQL5 Expert Advisor
- way: write a specialized MQL5 Expert Advisor - it will be responsible for closing positions
… I want … I want … I want … I want …
I have decided to ask for help without offering any code …
Can anyone help me get started with this?
- Help you with what? You haven't stated a problem, you stated a want.
How To Ask Questions The Smart Way. 2004
Prune pointless queries. You have only four choices:-
Search for it. Do you expect us to do your research for you?
-
Beg at:
- Coding help - MQL4 programming forum
- Make It No Repaint Please! - MQL4 programming forum
- MT4 to MT5 code converter - MQL5 programming forum
- Please fix this indicator or EA - General - MQL5 programming forum - Page 193 #1027
- Requests & Ideas (MQL5 only!) - Expert Advisors and Automated Trading - MQL5 programming forum
-
MT4: Learn to code it.
MT5: Begin learning to code it.
If you don't learn MQL4/5, 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 your code. -
or pay (Freelance) someone to code it. Top of every page is the link Code Base.
Hiring to write script - General - MQL5 programming forum 2019.08.21
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
No free help 2017.04.21 -
-
Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.
Always post all relevant code.
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problemWe can't see your broken code.
Fix your broken code.
The reason I thought it best to ask for help before coding anything is because I am totally confused. Here is the code I have written to place the orders when the price closes above the upper BB or below the lower BB.
The next thin I want to do is check if the last candle closed below the upper BB if I have open BUY orders and check if the last candle closed above the lower BB if I have open SELL orders. I am so confused that I don't even know where to start.
// Inputs input double varTradeLots = 0.01; //Size of trades input int varBbPeriod = 20; //Bollinger Band period input int varBbBandsShift = 0; //Bollinger Band shift input int varBbDeviation = 2; //Bollinger Band deviation input int varBbAppliedPrice = PRICE_CLOSE; //Bollinger Band applied price input bool varTradeAlert = true; //Alert after trade has been placed input bool varTradeTest = false; //Message instead of placing trade string timeFrame; string tradeSide; double tradeId; datetime lastBarCheck; datetime checkTime; double uband; double lband; /* +------------------------------------------------------------------+ | Expert initialization function | +------------------------------------------------------------------+ */ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } /* +------------------------------------------------------------------+ | Expert deinitialization function | +------------------------------------------------------------------+ */ void OnDeinit(const int reason) { //--- } /* +------------------------------------------------------------------+ | Expert tick function | +------------------------------------------------------------------+ */ void OnTick() { /* +--------------------------------------------------------------------+ | Run only once per bar | +--------------------------------------------------------------------+ */ // MessageBox ("The time[0] is " + Time[0]); if (lastBarCheck != Time[0]) { getBandValues(Close[1]); tradeSide = "No"; if (Close[1] > uband) { tradeSide = "BUY"; } else if (Close[1] < lband) { tradeSide = "SELL"; } else { Alert("NO TRADE"); } placeOrder(tradeSide); lastBarCheck = Time[0]; } }; int getBandValues (double close1) { uband=iBands(NULL,0,varBbPeriod,varBbDeviation,varBbBandsShift,varBbAppliedPrice,MODE_UPPER,0); lband=iBands(NULL,0,varBbPeriod,varBbDeviation,varBbBandsShift,varBbAppliedPrice,MODE_LOWER,0); return(0); }; int placeOrder(string tradeDirection) { if (tradeDirection != "No") { if (tradeDirection == "BUY") { if (varTradeTest == true) { Alert(""); Alert("Symbol = ", Symbol(), " ", timeFrame, " | Direction = ", tradeDirection, " | Volume = ", varTradeLots, " lots"); Alert("TRADE ALERT:"); } else { tradeId = OrderSend(Symbol(),OP_BUY,varTradeLots,Ask,0,0,0); if (varTradeAlert == true) { Alert(""); Alert("Symbol = ", Symbol(), " ", timeFrame, " | Direction = ", tradeDirection, " | Volume = ", varTradeLots, " lots"); Alert("TRADE PLACED:"); } } } else if (tradeDirection == "SELL") { if (varTradeTest == true) { Alert(""); Alert("Symbol = ", Symbol(), " ", timeFrame, " | Direction = ", tradeDirection, " | Volume = ", varTradeLots, " lots"); Alert("TRADE ALERT:"); } else { tradeId = OrderSend(Symbol(),OP_SELL,varTradeLots,Bid,0,0,0); if (varTradeAlert == true) { Alert(""); Alert("Symbol = ", Symbol(), " ", timeFrame, " | Direction = ", tradeDirection, " | Volume = ", varTradeLots, " lots"); Alert("TRADE PLACED:"); } } } } return (0); } // +------------------------------------------------------------------+ // | Tester function | // +------------------------------------------------------------------+ double OnTester() { //--- double ret=0.0; //--- //--- return(ret); } // +------------------------------------------------------------------+ // | ChartEvent function | // +------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- } // +------------------------------------------------------------------+
Study the attached file source code , it points out some things .
Enjoy [_]p
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have started an EA that will place either BUY or SELL orders based on certain criteria. This EA will run on multiple charts at the same time and will place orders in many different symbols. When a certain condition appears (say price closing below the 11 EMA), I want to close all BUY orders for that symbol. If the same condition appears on other charts, I want them to close all BUY orders for their respective symbols also. When a different condition occurs (say closing above the 11 EMA), I want to close all SELL orders for that symbol. If the same condition appears on other charts, I want them to close all SELL orders for their respective symbols also.
I have read many posts on this subject and must confess to being more confused than when I started. Therefore, I have decided to ask for help without offering any code that I have been working on so far as, given a free rein, your solution will no doubt be more elegant. Can anyone help me get started with this?