If all 10 orders are placed correctly at the beginning, then they should be placed ok when all are closed.

Are you sure that all orders have been closed? All the time that there is 1 or more untriggered pending order, new orders will not be placed.

Moderator

10568

If all 10 orders are placed correctly at the beginning, then they should be placed ok when all are closed.

Are you sure that all orders have been closed? All the time that there is 1 or more untriggered pending order, new orders will not be placed.

31

Hi,

thank you for your rapid answer.

You're right: there were some orders on the chart, far from current price, and I did'nt see them.

Now I've reduced to 4 orders for testing and it's ok.

So does int start() function works as cycle itself? I mean: everything you put in the body, it repeats it every tick?

However i past my complete code, maybe you have suggestion for correct coding:

//+------------------------------------------------------------------+ //| testergrid.mq4 | //| Copyright 2016, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict extern double lot = 0.01; int init() { return(0); } int start() { double spread = NormalizeDouble(Ask-Bid, Digits); double tp = (1* 10*Point*10)-spread; double sl = (1* 20*Point*10)-spread; double d = (1* 10*Point*10); double dueD = (1* 20*Point*10); double treD = (1* 30*Point*10); double quattroD = (1* 40*Point*10); if (OrdersTotal()==0) { /* ObjectCreate("xx", OBJ_LABEL, 0, 0, 0); ObjectSetText("xx",OrdersTotal(),17, "Verdana", Green); ObjectSet("xx", OBJPROP_CORNER, 0); ObjectSet("xx", OBJPROP_XDISTANCE, 20); ObjectSet("xx", OBJPROP_YDISTANCE, 40); */ OrderSend(Symbol(), OP_BUY, 0.01, NormalizeDouble(Ask,Digits), 0, NormalizeDouble(Ask-sl,Digits),NormalizeDouble(Ask+tp,Digits), "10-20-corretto", 0, 0, Green); OrderSend(Symbol(), OP_SELL, 0.01, NormalizeDouble(Bid,Digits), 0, NormalizeDouble(Bid+sl,Digits),NormalizeDouble(Bid-tp,Digits), "10-20-corretto", 0, 0, Green); OrderSend(Symbol(), OP_BUYSTOP, 0.01, NormalizeDouble(Ask+d,Digits), 0, NormalizeDouble(Ask+d-sl,Digits),NormalizeDouble(Ask+d+tp,Digits), "10-20-corretto", 0, 0, Green); // OrderSend(Symbol(), OP_BUYSTOP, 0.01, NormalizeDouble(Ask+dueD,Digits), 0, NormalizeDouble(Ask+dueD-sl,Digits),NormalizeDouble(Ask+dueD+tp,Digits), "10-20-corretto", 0, 0, Green); // OrderSend(Symbol(), OP_BUYSTOP, 0.01, NormalizeDouble(Ask+treD,Digits), 0, NormalizeDouble(Ask+treD-sl,Digits),NormalizeDouble(Ask+treD+tp,Digits), "10-20-corretto", 0, 0, Green); // OrderSend(Symbol(), OP_BUYSTOP, 0.01, NormalizeDouble(Ask+quattroD,Digits), 0, NormalizeDouble(Ask+quattroD-sl,Digits),NormalizeDouble(Ask+quattroD+tp,Digits), "10-20-corretto", 0, 0, Green); OrderSend(Symbol(), OP_SELLSTOP, 0.01, NormalizeDouble(Bid-d,Digits), 0, NormalizeDouble(Bid-d+sl,Digits),NormalizeDouble(Bid-d-tp,Digits), "10-20-corretto", 0, 0, Green); // OrderSend(Symbol(), OP_SELLSTOP, 0.01, NormalizeDouble(Bid-dueD,Digits), 0, NormalizeDouble(Bid-dueD+sl,Digits),NormalizeDouble(Bid-dueD-tp,Digits), "10-20-corretto", 0, 0, Green); // OrderSend(Symbol(), OP_SELLSTOP, 0.01, NormalizeDouble(Bid-treD,Digits), 0, NormalizeDouble(Bid-treD+sl,Digits),NormalizeDouble(Bid-treD-tp,Digits), "10-20-corretto", 0, 0, Green); // OrderSend(Symbol(), OP_SELLSTOP, 0.01, NormalizeDouble(Bid-quattroD,Digits), 0, NormalizeDouble(Bid-quattroD+sl,Digits),NormalizeDouble(Bid-quattroD-tp,Digits), "10-20-corretto", 0, 0, Green); /* ObjectCreate("ObjName", OBJ_LABEL, 0, 0, 0); ObjectSetText("ObjName",OrdersTotal(),17, "Verdana", Red); ObjectSet("ObjName", OBJPROP_CORNER, 0); ObjectSet("ObjName", OBJPROP_XDISTANCE, 20); ObjectSet("ObjName", OBJPROP_YDISTANCE, 20); */ } return (0); }

31

Sorry,

I just have two more ideas:

1. how can i put time filtering throughout the day? Telling the EA: trade from xx.xx am to yy.yy pm.

2. I'd like to try to close all orders, pending and opened, when total profit (I mean difference beetween equity and balance) is equal to x

Can you kindly suggest any coding direction?

Thanks

105

It could be, depending on the expression used.

start(){

int infinite = 1;

while(infinite == 1){ //We go around and around until you change the value of infinite

}

for(;;){ //Should work

}

if(infinite == 1) { //Recursion with an if

start();

}

I dont know if start loops, but there are event driven functions built in, like OnTimer() and OnTick() which will execute your code based on time or new tick data.

Don't use too much recursion though the code segments into your cache and without the right escape logic or purpose you'll just burn out resources. :D

I use OnTick and then combine it with a homebrew timer for specific function calls.

105

Sorry,

I just have two more ideas:

1. how can i put time filtering throughout the day? Telling the EA: trade from xx.xx am to yy.yy pm.

2. I'd like to try to close all orders, pending and opened, when total profit (I mean difference beetween equity and balance) is equal to x

Can you kindly suggest any coding direction?

Thanks

If you plan on coding you're probably best learning this stuff, there's plenty of documentation.

Here's some really bad code, should get you started.

void timeBasic(){ string timestr = TimeToStr(TimeCurrent(),TIME_SECONDS); string timeMin = TimeToStr(TimeCurrent(),TIME_MINUTES); int hours = Hour(); int day = DayOfWeek(); Print("hour is ", hours, " Day of week is ", day); string time_var = StringSubstr(timestr,6,2); int timevar = StringToInteger(time_var); if(timevar == 0){ // 1 minute if((hours > 6 && hours < 12) && (day != (0 || 6))){ //Non weekend between 6 and 12 depending on your local time } } }

Your second question just loop through orders and check OrderProfit() > 0

31

19

Hi!

I'd like to ask you, if I open an order, why don't delete my integers? I have a lot of question, later I'd like to ask it. Thank you for your help!

if(_1feltetelLong==1 && !__isExist(0)) { if(OrderSend(Symbol(),0,_Lots,MarketInfo(Symbol(),MODE_ASK),0,MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_POINT)*_SL,MarketInfo(Symbol(),MODE_ASK)+MarketInfo(Symbol(),MODE_POINT)*_TP,"",__STRATEGY_MAGIC)==true){ if((_1feltetelLong=0)==true){Print("Nyitu_1L ",_1feltetelLong);}; if((_1feltetelShort=0)==true){Print("Nyitu_1S ",_1feltetelShort);}; if((_Nullcross=0)==true){Print("Nyitu_0C ",_Nullcross);}; }

19

My last problem was ok, I can do it.

I'd like to write a simple code. I'd like to do a simple scalping strategy with an exponential moving average. When the ask price = moving average. This is the first criteria. Second: ask=5pip+MA - open long.

Short position is ASK=MA (1.criteria), ask=MA-5pip. I write here the full code. Please help! What is the problem, why don't open positions after every cross (when ASK=MA)? Thank you for your help!

extern double __STRATEGY_MAGIC=115; //Inputs //Declaration extern double _TP=100,_SL=100; extern double _Lots=0.01; extern double _Tick=0.00001; double _Ask=Ask; double _Ema; bool _Compare,_Compare2,_Compare3,_Compare4; bool _Open_Long; bool _Open_Short; int _1feltetelLong=0,_1feltetelShort=0,_Nullcross=0; int d=0; int start() { _Ema=iMA(Symbol(),0,14,0,1,0,0); if(!__isExist(0)){ if (NormalizeDouble(_Ask,5)==NormalizeDouble(_Ema,5)) { _Nullcross=1;Print("Szel ",_Nullcross); } } if(_Nullcross==1){ if(_Ask+0.00005 > _Ema){_1feltetelLong=1;} if(_Ema-0.00005 > _Ask){_1feltetelShort=1;} } if(_1feltetelLong==1 && !__isExist(0)) { _Open_Long = OrderSend(Symbol(),0,_Lots,MarketInfo(Symbol(),MODE_ASK),0,MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_POINT)*_SL,MarketInfo(Symbol(),MODE_ASK)+MarketInfo(Symbol(),MODE_POINT)*_TP,"",__STRATEGY_MAGIC); _1feltetelLong=0; _1feltetelShort=0; _Nullcross=0; } if(_1feltetelShort==1 && !__isExist(0)) { _Open_Short = OrderSend(Symbol(),1,_Lots,MarketInfo(Symbol(),MODE_BID),0,MarketInfo(Symbol(),MODE_BID)+MarketInfo(Symbol(),MODE_POINT)*_SL,MarketInfo(Symbol(),MODE_BID)-MarketInfo(Symbol(),MODE_POINT)*_TP,"",__STRATEGY_MAGIC); _1feltetelShort=0; _1feltetelLong=0; _Nullcross=0; } for (d=0;d<OrdersTotal();d++) { if(OrderSelect(__Ticket(0),SELECT_BY_TICKET)==true){ if (OrderSymbol() == Symbol() && OrderMagicNumber()== __STRATEGY_MAGIC && OrderType()==OP_BUY ) { if (NormalizeDouble(Bid-_Tick,5)>NormalizeDouble(OrderOpenPrice(),5)){ if(OrderClose(__Ticket(0),_Lots,Bid,0,Red)==true){ _1feltetelLong=0; _1feltetelShort=0; _Nullcross=0; } } } if (OrderSymbol() == Symbol() && OrderMagicNumber()== __STRATEGY_MAGIC && OrderType()==OP_SELL) { if (NormalizeDouble(Ask+_Tick,5)<NormalizeDouble(OrderOpenPrice(),5)){ if(OrderClose(__Ticket(0),_Lots,Ask,0,Blue)==true){ _1feltetelLong=0; _1feltetelShort=0; _Nullcross=0; } } } } } return(0); } bool __selectOrderByMagic(int __magic){for(int __i=0;__i<OrdersTotal();__i++){if(OrderSelect(__i,SELECT_BY_POS,MODE_TRADES)&&OrderMagicNumber()==__STRATEGY_MAGIC+__magic)return(true);}return(false);} bool __isExist(int __magic){return(__selectOrderByMagic(__magic));} int __Ticket(int __magic){if(!__selectOrderByMagic(__magic))return(0);return(OrderTicket());}

I'm very very new to mql coding, and I'm asking you help with some basic concept.

I'm starting from a very simple attempt: I check if thare aren't orders opened or pending, and I open some orders, market and stop.

When all orders are triggered and closed, in loss or profit, and there are no order pending or opened again, it will place the same orders again.

The problem is I'm not able to put it into a cycle; in strategy tester it puts first 10 orders correctly, and when thery are closed, of course, nothing happens.

I've tried with for or while, but I'm very confused with them.

I've tried to put all the code into void onTick(void) function, but nothing happens..

Thank you very much!

This is an utility for automatic scaling of a chart and making at least 140 bars visible in it. This is necessary for a correct wave analysis according to the Bill Williams' strategy "Trading Chaos". The utility can be used on any timeframe available in МetaТrader 5. It draws a vertical line through the first bar the calculation starts from. This line allows you to see the probable starting point of the wave sequence along with a sufficient number of bars displayed in the chart. It also makes t

How to use Pair Trading Station Pair Trading Station is recommended for H1 time frame and you can use it for any currency pairs. To generate buy and sell signal, follow few steps below to apply Pair Trading Station to your MetaTrader terminal. When you load Pair Trading Station on your chart, Pair Trading station will assess available historical data in your MetaTrader platforms for each currency pair. On your chart, the amount of historical data available will be displayed for each currency

The main purpose of the indicator is to detect and mark trade signals on the histogram of the Awesome Oscillator according to the strategies "Trading Chaos, second edition" and "New Trading Dimensions". The indicator detects and marks the following trade signals: "Two peaks" - Divergence. The signal "Second wise-man" - third consequent bar of the Awesome Oscillator after its color is changed. The histogram crosses the zero line. The signal "Saucer".The indicator includes a signal block th

This is the Famous Timing Indicator You can now use the most famous Timing indicator on the planet. Millionaire Mostafa Belkhayate earned his reputation by using this specific indicator to validate the entry signals supplied by his also famous Center of Gravity indicator on the Forex market. I spent hours, days, weeks to decrypt the formula and now it is finally available to you. New and Unique for MetaTrader 5 Timing will give you perfect validations for your entry signals. It is the first

Does not support openning multiple orders on a single symbol on MT5 MultiMTCopier MT5Receiver - new and improved multi-terminal positions copier for your real/demo account, works faster, requires less, flexible in managing and upgrading, new information support. This Expert Advisor is designed for the MetaTrader 5 terminal, trades will be copied into this terminal. MultiMTCopier: The EA will copy all positions without delays Additionally integrated notification in situations requiring user

Market Profile defines a number of day types that can help the trader to determine market behaviour. A key feature is the Value Area, representing the range of price action where 70% of trading took place. Understanding the Value Area can give traders valuable insight into market direction and establish the higher odds trade. It is an excellent addition to any system you may be using. Blahtech Limited presents their Market Profile indicator for the MetaTrader community. Inspired by Jim Dalton’s

The script is intended for automatic placing of Sell Stop pending orders, Stop Losses and Take Profits on the user specified levels. This script is not that useful as "Virtual pending buy stop", since short positions are opened as Bid price crosses the levels. Thus spread widening is not dangerous. Nevertheless, you need to have this script to prevent unwanted hitting of the Stop Loss levels. Main Purposes: Automation of the process of placing the Sell Stop pending orders, Stop Losses and T

Percent Crosshair is a powerful and easy percentage measure tool. Measure the chart percentage very quick! Don't waste your time anymore! Just attach the Percent Crosshair indicator in the chart, select crosshair mode at toolbars or press "Ctrl+F" and start using the crosshair as you always do! The percent measure will be next to the indicative price. Customize your indicator the way you want! There are 4 entry parameters: Positive % color: set the desired color when % is positive. Negat

Reverse TradeCopier Follow can copy trades from an account that is running Reverse TradeCopier Source. Features: Copies trades from one source (master) account to multiple following (slave) accounts. Allows investor (read only) password for source (master) account. There are no complicated settings and input parameters, everything is easy. Works with different brokers. Works with different quotes symbols (EURUSD_FX, eurusd_m, etc.). Can copy orders from 4-digit quotes platform to 5-dig

The SetkaMT5 Expert Advisor is the MetaTrader 5 version of the Setka Expert Advisor which is designed for MetaTrader 4. This Expert Advisor has been written in MQL5 for the MetaTrader 5 Platform. Run the EA and it will create a grid of orders. Orders are created in both directions with a step that can be set in the EA properties. The number of limit and trend orders can also be set manually. Once the total profit reaches a predetermined value (you can specify it in the EA settings), all orders

Robust median Renko style indicator for creating custom charts resembling Median Renko, Mean Renko, Turbo Renko and Better Renko candles as well as vanilla Renko with wicks plus PointO charts. This all in one package provides all of the signals needed by day traders, scalpers and even long term traders. These include: The indicator is an overlay on the main chart so it is possible to utilize one-click trading and order manipulation directly on the custom charts. Visual order placement is a

This version of the Traders Dynamic Index has the redrawing of the historical data eliminated, the algorithm calculation speed optimized, more external parameters for a more precise adjustments, and its functionalities extended: added the selection of the initial oscillator and the smoothing methods of the averages. Parameters Mode Osc - estimation oscillator selection; Period Osc - the calculation period of the oscillator used; Price Osc - applied price for the oscillation calculati

This is an open interest indicator for MetaTrader 5. It fixes open interest value once per minute and writes it to the file (on your PC). The product works on any timeframe but only with exchange instruments.

Monitoring and Trend Analysis This product shows the trend strength levels based on 16 standard indicators, time periods and currency groups. Depending on the current trend, the indicator colors change from green to red, allowing you to see the full picture. Advantages Whatever your trading method and strategy are, you should always know, in which direction you are trading and what the probability of the trend change is. This indicator will help you answer these questions by calculating the

Fast Copy MT5 allows you to copy trades between different MetaTrader 5 (netting)(hedge) and MetaTrader 4 accounts in any direction and amount, quickly and easily (without loading the system). Any type of copying is available MT4 → MT5 MT4 → MT4 MT5 → MT5 MT5 → MT4 * For the MetaTrader 4 terminal — Fast Copy MT4 * For the MetaTrader 5 terminal — Fast Copy MT5 ** Before the purchase, you can test the program by downloading the free demo versions — Fast

The script is intended for automatic placing of Buy Stop pending orders, Stop Losses and Take Profits on the user specified levels. Main Purposes: Avoiding unwanted entering a long position in case of false hitting the level as a result of widening of the spread by a dealing center. Avoiding unwanted triggering of a Stop Loss in case a quote pierces a significant level (fractal) without further confirmation with the close price. Setting a necessary virtual order and entering the market in

This indicator is based on Bollinger Bands indicator. It helps user clearly know the Band is expand or contract.

The indicator is intended for determining the spread and swap size, the distance for setting stop orders and stop losses from the current price allowed and the risk per 1 point in the deposit currency. The indicator informs a trader about possible additional expenses and profits connected with transferring a position to the next trade session of the financial instrument. It also informs about the spread size and the distance of pending orders, stop loss and trailing from the current price. In a

Parameters Three variables are available for every strategy, any one of them can be disabled, their period can be changed. type_order=ORDER_FILLING _FOK - order filling type. ReverseTrade=false — trades opens in reverse direction if true. ExitOnBar=true — trades close on each bar only. spreadcover=false — Spread you pay includes in profit trades. It's like trade with zero spread but you should remember that it can decrease exact match between tester's result and live one. It

FULL Automatic is a fully autonomous trading robot for MetaТrader 5 without configurable parameters. It is similar to SAFE Automatic robot intended for traders having no knowledge of trading basics. It works in Low, Medium, High and Extremal trading modes. Trading strategy The EA applies modified versions of well-known strategies, including Elliott waves, following a trend, half-pyramiding, scalping, speculative trading with a double deposit protection. The EA switches the strategies automati

This indicator extracts a trend from a price series and forecasts its further development. Algorithm is based on modern technique of Singular Spectral Analysis (SSA). SSA is used for extracting the main components (trend, seasonal and wave fluctuations), smoothing and eliminating noise. Does not require the series to be stationary, as well as the information on presence of periodic components and their periods. It can be applied both to price series and to the data of other indicators. Implemen

The indicator represents an additional chart window with a lower time frame where bars are combined into groups that are equivalent in time to main chart time frame. Bars are synchronized by the right hand side of the window, i.e. the time of the last bar in the main window corresponds to the time of the last bar group in the additional window. The maximum number of groups is 16; the maximum number of bars combined into groups in the additional window is 256. Limitations on the numbers are requi

Create your own list of trading instruments Watch list* and combine it with several open charts Link **. Using this program, a user can create fully-fledged Watch lists, create and delete trading instruments and move through the list. A selected symbol shows charts in linked windows. Linked windows can have different periods, indicators, experts, trading panels, etc... Moving through his/her Watch list, a trader an see the full image of his/her strategy in all windows. A lot of traders use 1

The indicator is designed for easy construction of synthetic charts based on data of various financial instruments. It will be useful both arbitrage and pair trading, as well as for analysis purposes. Its main advantage is simplicity and clarity. Each chart is given as a common mathematical formula. For example, if you want to plot the spread (difference) between EURUSD and GBPUSD with coefficients 4 and 3, then set the following formula: EURUSD * 4 - GBPUSD * 3 The resulting chart is shown in

Does not support openning multiple orders on a single symbol on MT5 MultiMTCopier MT5Source - new and improved multi-terminal positions copier for your real / demo account, works faster, requires less, flexible in managing and upgrading, new information support. This expert is designed for terminal MetaTrader5 from which the position will be copied. MultiMTCopier: The EA will copy all positions without delays Additionally integrated notification in situations requiring user attention Butt

This is an unusual (visual) representation of the famous WPR indicator. Instead of a separate subwindow, it is displayed in the main chart as a channel and levels. The next version of the indicator will have a possibility of smoothing its values using a moving average. Parameters PeriodWPR - calculation period of the percent price channel LevelUp - the value of the upper level in percentage (negative) LevelDn - the value of the lower level in percentage (negative) Center - the value of t

This panel represents a demo account for binary options. It will catch an interest of those who start working with binary options and want to practice on a demo account. It will also spark an interest of those who use Meta Trader 5 to get signals for binary options. You can test any strategy using this panel. It supports any currencies available in your terminal. The panel is also very compact, and you can move it to any spot on your chart window. Now you do not need to look for a broker with a

All traders using VSA realize the importance of the volume. Unfortunately, tick and spot volumes are not suitable for these purposes. I have conducted mathematical calculations and managed to trnsform the price into the volume that is close to the futures one by its ratios. Now, you do not have to wrestle with the question of where to obtain the volume data. Besides, you will be able to use the currency pairs having no futures at all. With RealVolume, you do not need to remember data on each ti

Cluster analysis of volumes is now available in MetaTrader 5! The YuСlusters indicator is a professional tool for analyzing the trading volumes. The cluster graph is plotted based on tick data. For the exchange financial instruments these are the volume, type and price of a deal. For the Forex instruments - the real or tick volume (depending on the broker) and Bid price. There are 6 criteria of cluster generation: Time interval, the criterion is set in seconds. Price range, the criteri

Tick volume is equal to amount of ticks at the unit of time. There is direct correlation between tick volume and real amount of deals. Every change of the price is a result of a real request to perform a deal. Consequently, fewer requests we have, the less price changes we get, and, as a consequence, tick volume is smaller. In this case, when big amount of requests appear on the market, price changes happen more often. Big tick volume appears. Tick volume is an important indicator of trad