Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 137
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
Hi everyone! How do I write my condition! I need to put a stop-loss order after the price has passed the stop-loss distance
for Buy.....
if( )
{
------------
}
for Sell.....
function to transfer STB to Breakeven, the order ticket and distance in pips are passed into the function
{
double sl=0.0;
if(OrderSelect(ticket,SELECT_BY_TICKET))
{
if(OrderType()==OP_BUY)
{
if(Bid>=OrderOpenPrice() && Bid-OrderOpenPrice()>=distance*_Point) sl=OrderOpenPrice();
if(OrderStopLoss()!=0 && OrderStopLoss()>=OrderOpenPrice())return;
}
if(OrderType()==OP_SELL)
{
if(Ask<=OrderOpenPrice() && OrderOpenPrice()-Ask>=distance*_Point) sl=OrderOpenPrice();
if(OrderStopLoss()!=0 && OrderStopLoss()<=OrderOpenPrice())return;
}
ResetLastError();
if(sl<=0)return;
if(!OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0))
{
int error=GetLastError();
rezult=StringConcatenate(OrderSymbol(),": error modifying StopLoss order ",OrderTicket()," ",TypeToStr(OrderType())," №- ",error);
Print(rezult);
}
}
}
...
There won't be any painting)
The search logic itself is heavy there, and how to make it easier - I don't know yet.
Vitaly, I originally tried to explain you that it's not the calculations that slow down the tester, but the graphical objects in the visual testing. Do it the way he advises
You can roll it in the indicator without drawing.) And it is better to make a choice. Hop - drawing, hop - no drawing:)
and see the difference in speed.
It's not even the drawing that's lagging, it's just the presence of graphics on the chart.
It's not even the drawing that's slowing things down, it's just the presence of graphics on the chart.
Vitaly, I originally tried to explain to you that it's not the calculations that slow down the tester, but the graphical objects in the visual testing. Do what he says
and see the difference in speed.
It's not even the drawing that lags, it's just the presence of graphics on the chart.
I test the function without any graphics at all, the chart was made only to see the correctness of calculations while writing the code - it was purely technical and has long been removed from the code. The chart is blank during testing.
So, when without function, the testing "flies", but connect function - it goes slowly.
P.S. I don't need graphical objects in principle. Forget about graphics - I don't have them and won't have them!
I test the function without any graph at all, the graph was made only to see if the calculations were correct while writing the code - it was purely technical and was removed from the code a long time ago. The chart is blank during testing.
So, when I don't have function, then testing "flies", but connect function - it goes slowly.
P.S. I don't need graphical objects in principle. Forget about graphics - I don't have them and won't have them!
Have you looked here?
Cool, I'll try to pull the functions into the EA. I'll post the result later.
Thank you!!!
Please help me to understand how to write the code correctly to get the index of bars opened at 4:00 and 15:00
That's one.
int shift=Bars("EURUSD",PERIOD_CURRENT,some_time,TimeCurrent());
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
That's two.
int shift=iBarShift("EURUSD",PERIOD_CURRENT,some_time);
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
That's one.
int shift=Bars("EURUSD",PERIOD_CURRENT,some_time,TimeCurrent());
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
That's two.
int shift=iBarShift("EURUSD",PERIOD_CURRENT,some_time);
Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);