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
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.
Indicators can not trade, so your added code does not affect trades.
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
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.
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(constlong chart_ID=0, // chart's ID conststring name="TrendLine", // line name constint 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 constcolor clr=clrRed, // line color constENUM_LINE_STYLE style=STYLE_SOLID, // line style constint width=1, // line width constbool back=false, // in the background constbool selection=true, // highlight to move constbool ray_left=false, // line's continuation to the left constbool ray_right=false, // line's continuation to the right constbool hidden=true, // hidden in the object list constlong 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);
}
voidOnTick()
{
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!
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.
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.
@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
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!
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.
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.