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

 
hamdy elmarghany #: Thank you, Alain, for your reply. Could you please tell me which function I can parse the string ?

As explained by Alain, there is no such function. You have to code it yourself.

MQL is a compiled language, not an interpreted language. Such functionality does not exist.

 
Thank you very much for the reply. Can anyone help me with any example of this so that everyone can benefit ?
 
hamdy elmarghany #: Thank you very much for the reply. Can anyone help me with any example of this so that everyone can benefit ?

Study interpreted languages to see how they have accomplished that. For example, study how the eval() function is implemented in JavaScript or Python.

However, first consider if you really need it. Maybe you are making your problem worse by using an incorrect approach.

Reconsider your true objective (which you have not described) and whether it cannot be solved in a much simpler way.

 

I am creating an EA based on  a custom indicator that uses buy and sell buffers ,

I added  if (i>0) to the below code to make the arrow appear only when the candle is closed. (without it the arrows keep appearing and disappearing which affects how trades are opened)

Now my issue is, when I add  if (i>0) the EA based on this indicator does not open trades, but when i remove  if (i>0)  the EA runs but its not accurate since the arrows appear and disappear. 

any help will be appreciated. 


 if (i>0)

         Buffer1[i] = Close[i]; //Set indicator value at Candlestick Open

         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Buy"); //Alert on next bar open

         time_alert = Time[1];

 

George Kariuki #:

I added  if (i>0) to the below code to make the arrow appear only when the candle is closed. (without it the arrows keep appearing and disappearing which affects how trades are opened)

Now my issue is, when I add  if (i>0) the EA based on this indicator does not open trades, but when i remove  if (i>0)  the EA runs but its not accurate since the arrows appear and disappear.

  1. Indicators can not trade, so your added code does not affect trades.
  2. Drop your if. Stop looking at candle zero.
 

@Artyom Trishkin

Hi everyone. I want to draw short horizontal lines for high and lows when some conditions met. And after some time when conditions are met again I want to draw another horizontal lines high/low, but don't delete previous lines.

I used drawing trendline function from here, cause I have anchor points and I want those lines to be short. After testing my EA, I see it draws horizontal lines only first time, second time when conditions are met, it doesn't draw. 

I attached picture how I  want it to look like. But as you can see from picture, only first lines are drawn. 

If someone knows how to do it, please help. Much appreciated 

Drawing Horizontal Lines in MQL4
Drawing Horizontal Lines in MQL4
  • 2019.01.24
  • www.mql5.com
hello there, I am new to MQL4 and i am trying to draw a horizontal line (ray) on OHLC of a candlestick. So far, I am unable to do so...
 
Aidana Bolat #: I want to draw short horizontal lines for high and lows when some conditions met. And after some time when conditions are met again I want to draw another horizontal lines high/low, but don't delete previous lines. I used drawing trendline function from here, cause I have anchor points and I want those lines to be short. After testing my EA, I see it draws horizontal lines only first time, second time when conditions are met, it doesn't draw. I attached picture how I  want it to look like. But as you can see from picture, only first lines are drawn. If someone knows how to do it, please help. Much appreciated 
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • You can also search the Codebase for something similar, so you will have to do your own research.
  • Finally, you also have the option to hire a programmer in the Freelance section.
 
Fernando Carreiro #:
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • You can also search the Codebase for something similar, so you will have to do your own research.
  • Finally, you also have the option to hire a programmer in the Freelance section.
void DrawHighLow(){
if(HLineDrawn==false){

   TrendCreate(ChartID(),"High",0,iTime(Symbol(),PERIOD_CURRENT,14),dchigh,iTime(Symbol(),PERIOD_CURRENT,0),dchigh,clrYellow,0,1,false,true,false,false,true,0);       //draws dchigh from last 14 candles to current time
   TrendCreate(ChartID(),"Low",0,iTime(Symbol(),PERIOD_CURRENT,14),dclow,iTime(Symbol(),PERIOD_CURRENT,0),dclow,clrYellow,0,1,false,true,false,false,true,0);           //draws dclow from last 14 candles to current time
   HLineDrawn=true;
}

}

bool TrendCreate(const long            chart_ID=0,        // chart's ID 
                 const string          name="TrendLine",  // line name 
                 const int             sub_window=0,      // subwindow index 
                 datetime              time1=0,           // first point time 
                 double                price1=0,          // first point price 
                 datetime              time2=0,           // second point time 
                 double                price2=0,          // second point price 
                 const color           clr=clrRed,        // line color 
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style 
                 const int             width=1,           // line width 
                 const bool            back=false,        // in the background 
                 const bool            selection=true,    // highlight to move 
                 const bool            ray_left=false,    // line's continuation to the left 
                 const bool            ray_right=false,   // line's continuation to the right 
                 const bool            hidden=true,       // hidden in the object list 
                 const long            z_order=0)         // priority for mouse click 
  { 

//--- reset the error value 
   ResetLastError(); 
//--- create a trend line by the given coordinates 
   if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create a trend line! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set line color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- set line display style 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- set line width 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the line by mouse 
//--- when creating a graphical object using ObjectCreate function, the object cannot be 
//--- highlighted and moved by default. Inside this method, selection parameter 
//--- is true by default making it possible to highlight and move the object 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- enable (true) or disable (false) the mode of continuation of the line's display to the left 
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_LEFT,ray_left); 
//--- enable (true) or disable (false) the mode of continuation of the line's display to the right 
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 





void OnTick()
  {


   if( Conditions()){          //Conditions() is a function that checks if conditions are met
   
      dchigh = iHigh(Symbol(), PERIOD_CURRENT, iHighest(Symbol(), PERIOD_CURRENT, MODE_HIGH, 14, 1));   //global variable last 14 candles high
      dclow = iLow(Symbol(), PERIOD_CURRENT, iLowest(Symbol(), PERIOD_CURRENT, MODE_LOW, 14, 1));      //global variable last 14 candles low
   
     
      DrawHighLow();
      }

      


  if(  CurrentOrders()==0 && Close[0]>dchigh)  {                     

     OpenNew(OP_BUY);              //opens new BUY order
     dchigh=10000000;      //kind of resetting global variables 
     dclow=-10000000;
     HLineDrawn=false;
   }




...
}      
Hi, I attached my code, and some pictures. Basically I want to draw short horizontal lines, without deleting previous horizontal lines. And as time goes by, there should be multiple horizontal lines at different time in my chart. But my algo draws only first time, second time when it needs to be drawn, it doesn't draw. Hope it makes sense. 
My EA is working the way I want it to be, except drawing these lines. I want to visualize it, so I can analyze previous trades
I searched answer in different forums, but couldn't find it. That's why I am writing on this forum.  Thank you!
 
@Aidana Bolat #:  Basically I want to draw short horizontal lines, without deleting previous horizontal lines.

Then give each set of graphical objects a different and unique name. If you always name them "High" (or "Low") then you will only have one of them.

Give them names like "High1", "High2", etc., or give them names with which you can manage them more easily.

For example including the start date/time or something meaningful which allows you to manage the various objects more easily.

 
Fernando Carreiro #:

Then give each set of graphical objects a different and unique name. If you always name them "High" (or "Low") then you will only have one of them.

Give them names like "High1", "High2", etc., or give them names with which you can manage them more easily.

For example including the start date/time or something meaningful which allows you to manage the various objects more easily.

I see, thank you for your contribution! I learnt MQL reading this forum and mostly reading your answers. Thank you so much!