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

 
FOTOGRAF14:

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

void zero_profit(int ticket, int distance)
  {
   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);
        }

     }
  }


...

 
Vitaly Muzichenko:

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

Alexey Kozitsyn:

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.

 
Alexey Viktorov:

It's not even the drawing that's slowing things down, it's just the presence of graphics on the chart.

No argument... That's why I said that when I don't need it, I turn it off (DRAW_NONE) and that's it... and you can access the values all the same.
 
Alexey Viktorov:

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!

 
Vitaly Muzichenko:

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?
 
Artyom Trishkin:
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 to understand how to write the code correctly to get the index of bars opened at 4:00 and 15:00
 
missha689:
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.

datetime some_time=D'2017.03.03 4:00';
  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.

datetime some_time=D'2004.03.21 12:00';
  int      shift=iBarShift("EURUSD",PERIOD_CURRENT,some_time);
  Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
Доступ к таймсериям и индикаторам - Справочник MQL4
Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
Доступ к таймсериям и индикаторам - Справочник MQL4
 
Alexey Viktorov:

That's one.

datetime some_time=D'2017.03.03 4:00';
  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.

datetime some_time=D'2004.03.21 12:00';
  int      shift=iBarShift("EURUSD",PERIOD_CURRENT,some_time);
  Print("index of the bar for the time ",TimeToStr(some_time)," is ",shift);
I understand that it is set to a specific day as the date is specified but how do I set the bar index to be at 15 yesterday and the bar index to be at 4 today
 
Can you tell me how to find out yesterday's date and time programmatically?
Reason: