Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 489
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 want to write an EA for MT4, one of its tasks is to draw Fibo lines, on M1, in one hour. That is, when 11.00 it should draw lines in the interval from 10.00 to 10.59, focusing on the highs and lows. Tried different methods, posted what was the last one. You can probably shorten the code to draw the levels.The problem is that it doesn't draw the lines in the given area.
int timemin=TimeMinute(Time[59]==0);
int timehour=TimeHour(Time[1] && TimeMinute(Time[0]));
int timemin1=TimeMinute(Time[0]==0);
int timehour1=TimeHour(Time[1] && TimeMinute(Time[59]))
int max=iHighest(Symbol(),1,MODE_HIGH,60,timehour);
int min=iLowest(Symbol(),1,MODE_LOW,60,timehour);
double barup=(iOpen(Symbol(),60,1)>iClose(Symbol(),60,1));
double bardn=(iOpen(Symbol(),60,1)<iClose(Symbol(),60,1));
ObjectDelete("FiboLevels"); //------New level
if (barup)
{
WindowRedraw();
ObjectCreate(0, "FiboLevels",OBJ_FIBO,0,Time[min],Low[min],Time[timehour1],High[max]);
ObjectSet("FiboLevels",OBJPROP_COLOR,clrGreen);
}
if (bardn)
{
WindowRedraw();
ObjectCreate(0, "FiboLevels",OBJ_FIBO,0,Time[max],Low[max],Time[timehour1],High[min]);
ObjectSet("FiboLevels",OBJPROP_COLOR,clrRed);
}
double f1=ObjectGet("FiboLevels",OBJPROP_PRICE1); //Selects the first price
double f2=ObjectGet("FiboLevels",OBJPROP_PRICE2); //Selects the second price and plots
double Diff=f2-f1;
string a11=DoubleToStr(f2-Diff*0.0,Digits);
string a12=DoubleToStr(f2-Diff*0.236,Digits);
string a13=DoubleToStr(f2-Diff*0.382,Digits);
string a14=DoubleToStr(f2-Diff*0.50,Digits);
string a15=DoubleToStr(f2-Diff*0.618,Digits);
string a16=DoubleToStr(f2-Diff*1.0,Digits);
bool a1=ObjectSet("FiboLevels",OBJPROP_FIBOLEVELS,6);
bool a2=ObjectSet("FiboLevels",OBJPROP_FIRSTLEVEL+0,0.0);
bool a3=ObjectSet("FiboLevels",OBJPROP_FIRSTLEVEL+1,0.236);
bool a4=ObjectSet("FiboLevels",OBJPROP_FIRSTLEVEL+2,0.382);
bool a5=ObjectSet("FiboLevels",OBJPROP_FIRSTLEVEL+3,0.50);
bool a6=ObjectSet("FiboLevels",OBJPROP_FIRSTLEVEL+4,0.618);
bool a7=ObjectSet("FiboLevels",OBJPROP_FIRSTLEVEL+5,1.0);
bool a111=ObjectSetFiboDescription("FiboLevels",0, "0.0%");
bool a122=ObjectSetFiboDescription("FiboLevels",1, "23.6%");
bool a133=ObjectSetFiboDescription("FiboLevels",2, "38.2%");
bool a144=ObjectSetFiboDescription("FiboLevels",3, "50.0%");
bool a155=ObjectSetFiboDescription("FiboLevels",4, "61.8%");
bool a166=ObjectSetFiboDescription("FiboLevels",5, "100.0%");
Hello. I want to write an EA for MT4, one of its tasks is to draw Fibo lines, on M1, in one hour. That is, when 11.00 it should draw lines in the interval from 10.00 to 10.59, focusing on the highs and lows. Tried different methods, posted what was the last one. You can probably shorten the code to draw the levels.The problem is that it doesn't draw lines in a given area.
double barup=(iOpen(Symbol(),60,1)>iClose(Symbol(),60,1));double bardn=(iOpen(Symbol(),60,1)<iClose(Symbol(),60,1));
ObjectDelete("FiboLevels"); //------New level
if (barup)
{
WindowRedraw();
ObjectCreate(0, "FiboLevels",OBJ_FIBO,0,Time[min],Low[min],Time[timehour1],High[max];
ObjectSet("FiboLevels",OBJPROP_COLOR,clrGreen);
}
if (bardn)
{
WindowRedraw();
ObjectCreate(0, "FiboLevels",OBJ_FIBO,0,Time[max],Low[max],Time[timehour1],High[min]);
ObjectSet("FiboLevels",OBJPROP_COLOR,clrRed);
}
this is shorter? bool barup=... WindowRedraw(); will still execute - took out of if
it can also be shorter ... see my file
Please insert the code correctly.
It's even clearer:
Guys, why do my orders open with every tick? Can you tell me how to concentrate on the bar?
Guys, why do my orders open with every tick? Can you tell me how to concentrate on the bar?
According to the conditions described in the ATS, gives the go-ahead to open so it opens.
There are a lot of solutions in this case. It all depends on what is more suitable for you.
We may determine that the next order should be opened only if the price has moved away from the last one by N points. You may request to open not more than one order on 1 bar. Such and so on and so forth.
Write down the conditions you need, and apply them to your tests.
According to the conditions described in the ATS, it opens the order.
There are a lot of solutions in this case. It all depends on what is more suitable for you.
We may determine that the next order should be opened only if the price has moved away from the last one by N points. You may request to open not more than one order on 1 bar. Such and so on and so forth.
Write down the conditions you need, and apply them to your tests.
Insteadif( iTime(Symbol(),PERIOD_M1,0)){ what should I write to open an order on one bar?
The question has been asked many times and correspondingly many times answered.Using a search, e.g. here
The question has been asked many times and correspondingly many times answered.Using a search, e.g. here
Thank you!
Good afternoon!
I have an EA that does certain calculations. It uses different math operations, arrays, loops. It saves the result to a file. It has to start everything from the beginning after it has performed all the actions. It has done all the calculations once and then hangs for the second time without any further action. Can you advise whether it is necessary to zero variables, clear arrays or something else before starting a new calculation?
Good afternoon!
I have an EA that does certain calculations. It uses different math operations, arrays, loops. It saves the result to a file. It has to start everything from the beginning after it has performed all the actions. It has done all the calculations once and then hangs for the second time without taking any action. Can you advise whether it is necessary to zero variables, clear arrays or something else before starting a new calculation?