double ATR_Max() {
int i;
double m;
datetime tim;
iATR_H1_PER = 15;// периодif ( tim != Time[0] ) {
while( i < WindowBarsPerChart() ) {
double a = iATR( NULL, 0, iATR_H1_PER, i );
if ( m < a ) {
m = a;
}
i++;
tim = Time[0];
}
}
Alert( " Максимальное значение ATR для видимого количества баров равно - ", m );
return(m);
}
Boeing747 : I think tim = Time[0] would be better placed after the loop ...because asking Time[0] is done on all number of visible bars - it's not rational.
Thanks for the correction. The number of errors grows exponentially at night))))
Good afternoon. Do you know if it is possible to change indicator parameters on the fly in mql4? The idea is simple: the ZigZag indicator is installed on the chart. The script should be written and the hot key should be attached to it. By pressing it the zigzag parameters will be changed on the chart.
Thus, the function checks the values of the two previous bars and if they are too big, it returns TRUE. The question is how to improve it nicely: to make this function look for big candles on more candles. For example 24.
satorifx : Good afternoon. Do you know if it is possible to change indicator parameters on the fly in mql4? The idea is simple: the ZigZag indicator is installed on the chart. The script should be written and the hot key should be attached to it. As soon as I press it, the ZigZag parameters will change on the chart.
I made a homemade Expert Advisor to test trading, but I cannot figure out one thing...
Bay/sell is opened using maximal and minimal MAs
// Condition for opening BUY position if(MA_L1<MA_L0&&Ask<=MA_L0&MA_0>MA_1&&HA_up>HA_dw)
// Condition for opening a SELL position if(MA_H1>MA_H0&&Bid>=MA_H0&MA_0<MA_1&HA_up<HA_dw)
#include <b-Lots.mqh>externdouble TrailingStop = 30;
externdouble Sploss = 15;
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+int start() {
double HA_up,HA_dw;
double MA_H0,MA_H1,MA_L0,MA_L1,MA_0,MA_1;
int i, cnt, ticket, total;
bool flag=true;
if(Bars<100) {
Print("bars less than 100");
return(0);
}
// Проверяем стоит ли открываться
cnt=OrdersHistoryTotal()-1;
for(i=cnt;i>=0;i--) {
if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY )) continue;
if(OrderOpenTime()>=Time[0]) { // Time[0] - если позиция открывается на нулевом баре текущего символа
flag=false;
break;
}
}
cnt=OrdersTotal()-1;
for(i=cnt;i>=0;i--) {
if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if(OrderOpenTime()>=Time[0]) { // Time[0] - если позиция открывается на нулевом баре текущего символа
flag=false;
break;
}
}
if(!flag) return(0);
//-----------------------------------------------
MA_H0=iMA(0,0,3,0,MODE_SMA,PRICE_HIGH,0);
MA_H1=iMA(0,0,3,0,MODE_SMA,PRICE_HIGH,1);
MA_0=iMA(0,0,3,0,MODE_EMA,PRICE_MEDIAN,0);
MA_1=iMA(0,0,3,0,MODE_EMA,PRICE_MEDIAN,1);
MA_L0=iMA(0,0,3,0,MODE_SMA,PRICE_LOW,0);
MA_L1=iMA(0,0,3,0,MODE_SMA,PRICE_LOW,1);
HA_up=iCustom(0,0,"Heiken Ashi",3,0);
HA_dw=iCustom(0,0,"Heiken Ashi",2,0);
//задали все данные
total=OrdersTotal();
if(total<1)
{
// Проверка свободной маржиif(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// Условие открытие позиции BUYif(MA_L1<MA_L0&&Ask<=MA_L0&&MA_0>MA_1&&HA_up>HA_dw)
{
Lots=GetSizeLot();
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Bid-Sploss*Point,0,"",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
elsePrint("Error opening BUY order : ",GetLastError());
return(0);
}
// Условие открытие позиции SELLif(MA_H1>MA_H0&&Bid>=MA_H0&&MA_0<MA_1&&HA_up<HA_dw)
{
Lots=GetSizeLot();
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Ask+Sploss*Point,0,"",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
elsePrint("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // длинная позиция открыта
{
if(NormalizeDouble (MathAbs(MA_H0-Bid),Digits)<Point)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
return(0);
}
// трейлинг-стоп для длинной позицииif(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if(NormalizeDouble (MathAbs(MA_L0-Ask),Digits)<Point)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
return(0);
}
// трейлинг-стоп для короткой позицииif(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
Question: The position on the current candle is not closed (the conditions have not come). How to close it on the next candle, when it matches MA_0= iMA ( 0, 0, 3, 0, MODE_EMA, PRICE_MEDIAN, 0 );
We have a condition to close it: crossing the high or low of the current candle, but we need the position to close on the next candle after it is opened.
We can write if ( NormalizeDouble ( MathAbs (MA_0-Ask), Digits )< Point ), but how to fulfill the condition of the second open candle.
If you can answer with code, the example is clearer.
Do you really have to be a smart aleck to understand that if a new person comes to the forum with a question, they need a specific solution or a link to something similar, not a dumb excuse that "anything is possible"?
Do you really have to be a smart aleck to understand that if a new person comes to the forum with a question, they need a specific solution or a link to something similar, not a dumb excuse that "anything is possible"?
People who are trying to do something on their own get help here. They guide you in the right direction, explain, etc. ...
You asked a question and you got an answer. Have you tried to start writing something yourself?
When asking a question in a certain format, first think about what kind of answer you will get to the format of the question...
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
So, hopefully the final form of the function.
So, hopefully the final form of the function.
So, hopefully the final form of the function.
I think tim = Time[0] would be better placed after the loop ...because asking Time[0] is done on all number of visible bars - it's not rational.
Thanks for the correction. The number of errors grows exponentially at night))))
The idea is simple: the ZigZag indicator is installed on the chart. The script should be written and the hot key should be attached to it. By pressing it the zigzag parameters will be changed on the chart.
Continuing the current topic of finding a high volatility filter. Here is the code of an existing filter from WSR
int init()
Here is the function itself:
Thus, the function checks the values of the two previous bars and if they are too big, it returns TRUE. The question is how to improve it nicely: to make this function look for big candles on more candles. For example 24.
Good afternoon. Do you know if it is possible to change indicator parameters on the fly in mql4?
The idea is simple: the ZigZag indicator is installed on the chart. The script should be written and the hot key should be attached to it. As soon as I press it, the ZigZag parameters will change on the chart.
I made a homemade Expert Advisor to test trading, but I cannot figure out one thing...
Question: The position on the current candle is not closed (the conditions have not come). How to close it on the next candle, when it matches MA_0= iMA ( 0, 0, 3, 0, MODE_EMA, PRICE_MEDIAN, 0 );Bay/sell is opened using maximal and minimal MAs
// Condition for opening BUY position
if(MA_L1<MA_L0&&Ask<=MA_L0&MA_0>MA_1&&HA_up>HA_dw)
// Condition for opening a SELL position
if(MA_H1>MA_H0&&Bid>=MA_H0&MA_0<MA_1&HA_up<HA_dw)
We have a condition to close it: crossing the high or low of the current candle, but we need the position to close on the next candle after it is opened.
We can write if ( NormalizeDouble ( MathAbs (MA_0-Ask), Digits )< Point ), but how to fulfill the condition of the second open candle.
If you can answer with code, the example is clearer.
There is such a possibility.
Thank you for the incredibly detailed response.
Do you really have to be a smart aleck to understand that if a new person comes to the forum with a question, they need a specific solution or a link to something similar, not a dumb excuse that "anything is possible"?
Thank you for the incredibly detailed response.
Do you really have to be a smart aleck to understand that if a new person comes to the forum with a question, they need a specific solution or a link to something similar, not a dumb excuse that "anything is possible"?
People who are trying to do something on their own get help here. They guide you in the right direction, explain, etc. ...
You asked a question and you got an answer. Have you tried to start writing something yourself?
When asking a question in a certain format, first think about what kind of answer you will get to the format of the question...