Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 489

 

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%");

 
Georgy Sled:

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

   ObjectDelete("FiboLevels"); //------Новый уровень
   WindowRedraw();

   if (iOpen(Symbol(),60,1)>iClose(Symbol(),60,1))
   {
      ObjectCreate(0,"FiboLevels",OBJ_FIBO,0,Time[min],Low[min],Time[timehour1],High[max]);
      ObjectSet("FiboLevels",OBJPROP_COLOR,clrGreen);
   }
   else
   {
      ObjectCreate(0,"FiboLevels",OBJ_FIBO,0,Time[max],Low[max],Time[timehour1],High[min]);
      ObjectSet("FiboLevels",OBJPROP_COLOR,clrRed);
   }

it can also be shorter ... see my file

Files:
Proba.mq4  3 kb
 
Artyom Trishkin:

Please insert the code correctly.


It's even clearer:


Thank you for explaining how to paste the code correctly)))) helped) Please check and help me write the code correctly, I will be much obliged! (Today I have a boiled Samsung TV I learned how to uninstall, but I can't cope with this code (((((
 
void fOrderOpen() {...
    if( iTime(Symbol(),PERIOD_M1,0)) {
     if((fMarketOrders(OP_BUY))) { ....{
int irvbuy=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,NULL,12345,0,0); 

Guys, why do my orders open with every tick? Can you tell me how to concentrate on the bar?

 
Rustam Bikbulatov:

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.

 
Konstantin Nikitin:

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?

 
Rustam Bikbulatov: Guys, why do my orders open with every tick? Any advice on how to concentrate on the bar?

The question has been asked many times and correspondingly many times answered.Using a search, e.g. here

 
STARIJ:

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?

 
Kot:

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?

They will definitely help. And there are no such specialists in this thread.