Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 7
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello, I have not found a thread about upgrading the Metatrader 4 terminal for Android 2.3, so please do not kick me too much for posting in this thread. On the market terminal only for Android 4+. Where can I get an update, because mine stopped working.
Forum on trading, automated trading systems and trading strategy testing
Terminal mt5 and mt4 not working
Renat Fatkhullin, 2016.11.13 23:51
Sorry, we no longer support Android versions below 4.0.3I have nothing to explain there so no one is answering. The chart that you have shown is meaningless and it is a mystery how it was obtained.
The "Two-dimensional surface" option in the "Optimization graph" tab of the tester makes sense (imho) when we need to optimize 2 input parameters of the Expert Advisor, or visually see at what values of 2 parameters on the history were good results, whether these parameters are interdependent, and whether they make sense at all.
You have only 0 on both axes for some reason, and vertically these 0's are divided into 3 intermediate steps, so you have "cubes one in the centre, two lower/higher, and two/three in the same square". And the results look random - white and green "cubes" scattered randomly. So the graph is meaningless and doesn't seem to mean anything.
The graph may not make sense, but after optimisation in the period from 2014-2015 and when selecting and setting better parameters and re-testing from 2014 to today, the result of loss / drawdown remain unchanged, well, the profit increases in proportion to the period. Also, the bot was working on a demo for a month, and during testing for the last month with default parameters all deals coincide with the tester = +5pp. So, I`m not going to play with cubes and their colour.
Thanks for the clarification.
I'm trying to learn MQL4 and therefore please do not feel bad about my question.
Please advise how to correctly calculate the SL and TP for a pending order, in case it is placed not on the current price but on the price obtained during the calculations?
They should be calculated based on the candlestick length. It is approximately like this:
TP=NormalizeDouble(((iOpen(NULL,0,1))-(iLow(NULL,0,1)))*KoefTP*Point,Digits);
Thank you!
Hello!
I'm trying to learn MQL4, so please don't feel bad about my question.
Please advise how to correctly calculate SL and TP for a pending order and if it is placed not at the current price but at the price obtained during the calculations.
They should be calculated based on the candlestick length. It is approximately like this:
TP=NormalizeDouble(((iOpen(NULL,0,1))-(iLow(NULL,0,1)))*KoefTP*Point,Digits);
Thank you!
Here are the functions that will calculate the correct stop orders for any type of order:
double CorrectStopLoss(string symbol_name,int op,double price_set,double stop_loss) {
if(stop_loss==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,stop_loss),dg));
else return(NormalizeDouble(fmax(price+(lv+1)*pt,stop_loss),dg));
}
//+------------------------------------------------------------------+
double CorrectStopLoss(string symbol_name,int op,double price_set,int stop_loss) {
if(stop_loss==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,price-stop_loss*pt),dg));
else return(NormalizeDouble(fmax(price+(lv+1)*pt,price+stop_loss*pt),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,double take_profit) {
if(take_profit==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,take_profit),dg));
else return(NormalizeDouble(fmin(price-(lv+1)*pt,take_profit),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,int take_profit) {
if(take_profit==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,price+take_profit*pt),dg));
else return(NormalizeDouble(fmin(price-(lv+1)*pt,price-take_profit*pt),dg));
}
//+------------------------------------------------------------------+
int StopLevel(string symbol_name) {
int sp=(int)SymbolInfoInteger(symbol_name,SYMBOL_SPREAD);
int lv=(int)SymbolInfoInteger(symbol_name,SYMBOL_TRADE_STOPS_LEVEL);
return((lv==0)?sp*2:lv);
}
//+------------------------------------------------------------------+
{
//---
MqlDateTime server_time;
TimeToStruct(TimeCurrent(),server_time);
//--- если значение минут серверного времени кратно заданному значению, в частности 20-ти минутам или равно 0
if(server_time.min%minutesBefore==0 || server_time.min==0) {
if(SignalByRSI(Symbol(),TimeframeRSI,minutesBefore)==OP_BUY) {
//--- получили сигнал на покупку
Print("Сигнал на покупку ",TimeCurrent()); // Проверочное сообщение в журнал
//--- проверка наличия уже открытой позиции на покупку
if (OrdersTotal() == 0)
{
ticket=OrderSend(Symbol(),OP_BUY, Lts, Ask, 0, 0, 0, NULL, 1234, 0, Blue);
Alert ("Есть сигнал на покупку ", sim, per);
}
if (OrdersTotal() >0)
if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
if(OrderType()==OP_SELL)
{
OrderClose(ticket, OrderLots(), Bid,0,Blue);
{
ticket=OrderSend(Symbol(),OP_BUY, Lts, Ask, 0, 0, 0, NULL, 1234, 0, Blue);
Alert ("Есть сигнал на закрытие продажи и открытие покупки ", sim, per);
}
}
//--- вызов функции открытия позиции на покупку
}
if(SignalByRSI(Symbol(),TimeframeRSI,minutesBefore)==OP_SELL) {
//--- получили сигнал на продажу
Print("Сигнал на продажу ",TimeCurrent()); // Проверочное сообщение в журнал
//--- проверка наличия уже открытой позиции на продажу
if (OrdersTotal() == 0)
{
ticket=OrderSend(Symbol(),OP_SELL, Lts, Bid, 0, 0, 0, NULL, 1234, 0, Red);
Alert ("Есть сигнал на продажу ", sim, per);
}
if (OrdersTotal() >0)
if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
if(OrderType()==OP_BUY)
{
OrderClose(ticket, OrderLots(), Ask,0,Red);
{
ticket=OrderSend(Symbol(),OP_SELL, Lts, Bid, 0, 0, 0, NULL, 1234, 0, Red);
Alert ("Есть сигнал на закрытие покупки и открытие продажи ", sim, per);
}
}
//--- вызов функции открытия позиции на продажу
}
}
}
Here are the functions that will calculate the correct stop orders for any type of order:
double CorrectStopLoss(string symbol_name,int op,double price_set,double stop_loss) {
if(stop_loss==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,stop_loss),dg));
else return(NormalizeDouble(fmax(price+(lv+1)*pt,stop_loss),dg));
}
//+------------------------------------------------------------------+
double CorrectStopLoss(string symbol_name,int op,double price_set,int stop_loss) {
if(stop_loss==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,price-stop_loss*pt),dg));
else return(NormalizeDouble(fmax(price+(lv+1)*pt,price+stop_loss*pt),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,double take_profit) {
if(take_profit==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,take_profit),dg));
else return(NormalizeDouble(fmin(price-(lv+1)*pt,take_profit),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,int take_profit) {
if(take_profit==0) return(0);
double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,price+take_profit*pt),dg));
else return(NormalizeDouble(fmin(price-(lv+1)*pt,price-take_profit*pt),dg));
}
//+------------------------------------------------------------------+
int StopLevel(string symbol_name) {
int sp=(int)SymbolInfoInteger(symbol_name,SYMBOL_SPREAD);
int lv=(int)SymbolInfoInteger(symbol_name,SYMBOL_TRADE_STOPS_LEVEL);
return((lv==0)?sp*2:lv);
}
//+------------------------------------------------------------------+
Thank you, Artem, I will look into it.
You're welcome. Wherever you need to get accurate stop prices, knowing the open price of a market or pending order, get the required prices with these functions - they will return already calculated prices for the required stop order.
Suppose you have the set price of a pending order:
double priseSet=1.12345;
Then the stop loss price
int StopLoss=20; points for BuyLimit will be:
double sl=CorrectStopLoss(Symbol(),OP_BUYLIMIT,priceSet,StopLoss);
The sl variable will take the correctly calculated stop loss for BuyLimit with the StopLevel requirements.
Here's a tip. Suppose a short position is opened. In case of a buy signal to close the short and open the long.
Check if there is an open sell position. If so, close it.
Then open a buy position.
It's elementary.
I have a great desire to use mql4 to implement such an algorithm:
There are two MT4 terminals from different brokers. In one of them there is an "exclusive" indicator, which cannot be moved to another terminal (like in Market).
So what! Is it possible to take the readings of the "exclusive" indicator buffers and implement them in your own indicator in your own terminal?
Resources do not work somehow.