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

 
ifitstrue:

Question on

What would be the index of the initial M1 bar if I were to draw a trend line on the past H1?

And by the start and end time of the line it is not clear how to find it.

Sorry, if I am not explaining it clearly.

It is difficult for me.

Besides indices there is also time...

 
//---
   for(int j=0;j<OrdersTotal();j++)
     {
      if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICZZ || OrderSymbol()!=Symbol()) continue;
   //--- check order type 
      if(OrderType()==OP_BUY)
        {
         //if(OrderProfit()>0.0)
           //{//Print("OrderProfitB()=",OrderProfit());
         if(iClose(NULL,PERIOD_CURRENT,1)-iOpen(NULL,PERIOD_CURRENT,1)>0.0)
           {if(iOpen(NULL,PERIOD_CURRENT,0)-iClose(NULL,PERIOD_CURRENT,0)>0.0)
              {Print("iCloseB()=",iClose(NULL,PERIOD_CURRENT,0));
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
                  Print("OrderClose error ",GetLastError());
              }  
           }
        }
      if(OrderType()==OP_SELL)
        {
         //if(OrderProfit()>0.0)
           //{//Print("OrderProfitS()=",OrderProfit());
         if(iOpen(NULL,PERIOD_CURRENT,1)-iClose(NULL,PERIOD_CURRENT,1)>0.0)
           {if(iClose(NULL,PERIOD_CURRENT,0)-iOpen(NULL,PERIOD_CURRENT,0)>0.0)
              {Print("iCloseS()=",iClose(NULL,PERIOD_CURRENT,0));
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
                  Print("OrderClose error ",GetLastError());
              }
           }
Hello! 2021.03.01_19:49 GMT+3. Wanted to improve the results of my trading system. But iOpen() and iClose() didn't seem to work. In the strategy tester, I checked the Expert Advisor, among 175 trades, only 81 of them seem to be closed by the conditions described in the code above. This code does not work. What can we do to make it work? How about asking MetaQuotes programmers? Now I'll look through the strategy tester's logs and post how rarely these functions work. Found it. 20210228.log . Time 13:53:02.192, open #155, iCloseB()=1.3434. Attached is the log file. Now I hope someone can tell me what to do with these iClose() and iOpen() functions to make them work. Because the trading system is not efficient enough. That's all for now. 2021.03.01_20:12 GMT+3.
Files:
20210228.log  277 kb
 
It happens on mt5 that on a certain timeframe it's time for a new bar to appear (and the quotes seem to be coming), but it's still not there. What is it? Specifics of pricing?
 
ifitstrue:

Question on

What would be the index of the initial M1 bar if I were to draw a trend line on the past H1?

And by the start and end time of the line it is not clear how to find it.

Sorry, if I am not explaining it clearly.

It is difficult for me.

H1 has a bar open time - it is iTime()

To understand the index of a bar with this time on M1 there is iBarShift()

It remains to know the minimum and maximum bar at M1 using iHighest() and iLowest()

 
Hello again! 2021.03.01_20:24 GMT+3. I wrote in this forum thread on page 1304 that my version 4 tester is slow. And Vitaly Muzichenko misunderstood me. I am writing the time when I finished writing the comment. And I am not rushing anyone. Although there were no answers to my question, I found the answer by accident. What am I doing with the strategy tester now? I check the "optimize" checkbox before testing the Expert Advisor. I optimize it. Although, I do not need optimization at the moment. I optimize it in approximately one second. Then I clear the checkbox "optimize". I check how the Expert Advisor works. Then the strategy tester works quickly. It is not forty minutes or an hour. I felt obliged to write this. Maybe it will be of use to anyone. I am writing my Expert Advisor in the fourth version of the terminal because my broker has ruble accounts in version 4 of the terminal and not in version 5. I don't want to mess with US dollar: it has a huge national debt ceiling and my broker translates my dollars into my roubles at non-market rate. that's all for now. 20:39 GMT+3.
 
Николай Никитюк:
Hello! 2021.03.01_19:49 GMT+3. Wanted to improve the results of my trading system. But it seems that iOpen() and iClose() functions do not work. In the strategy tester, I checked the Expert Advisor, among 175 trades, only 81 of them seem to be closed by the conditions described in the code above. This code does not work. What can we do to make it work? How about asking MetaQuotes programmers? Now I'll look through the strategy tester logs and post how rarely these functions work. Found it. 20210228.log . Time 13:53:02.192, open #155, iCloseB()=1.3434. Attached is the log file. Now I hope someone can tell me what to do with these iClose() and iOpen() functions to make them work. Because the trading system is not efficient enough. That's all for now. 2021.03.01_20:12 GMT+3.

The code seems fine, but I'm confused by the slippage...very small, put more slippage and check

 
Alexey Viktorov:
Good heavens! Did I want something? Did I ask for anything? Who do you think I am?
My mistake, sorry. Wrong person, wrong place. )
 
Николай Никитюк:
Hello! 2021.03.01_19:49 GMT+3. Wanted to improve the results of my trading system. But it seems that iOpen() and iClose() functions do not work. In the strategy tester, I have tested the Expert Advisor, among 175 trades, only 81 of them seem to be closed by the conditions described in the code above. This code does not work. What can we do to make it work? How about asking MetaQuotes programmers? Now I'll look through the strategy tester's logs and post how rarely these functions work. Found it. 20210228.log . Time 13:53:02.192, open #155, iCloseB()=1.3434. Attached is the log file. Now I hope someone can tell me what to do with these iClose() and iOpen() functions to make them work. Because the trading system is not efficient enough. That's all for now. 2021.03.01_20:12 GMT+3.

Try to rewrite it that way, because it's the same thing.

         if(Close[1]-Open[1]>0.0)
           {
            if(Close[0]-Open[0]>0.0)

Or, that's how I write it.

         if(Close[1]>Open[1])
           {
            if(Close[0]>Open[0])
              {
 
klub2003:

Hi all!

Here's the problem:
Price crosses the MA down or up.
I need to memorise it in order to use it later in calculating the number of points passed.

This is how I understand it:

double FixPrice; // variable

bool Fix=false; // marker

if ( Fix==false) {

if ( Close[0] > MA_lo ) FixPrice = Close[0];
} // measure until the price crosses the MA

if ( Close[0] < MA_lo ) Fix=true;

if ( Fix==true) FixPrice_L = FixPrice ;

And here is the next hitch - the price is not memorized!

I'd be very grateful for your help!
//+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//---

double     FixPrice;        // переменная ТАК БУДЕТ ЗАПОМИНАТЬСЯ. ГЛОБАЛЬНАЯ ПЕРЕМЕННАЯ
bool       Fix = false;      // маркер
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Fix == false)
     {
      if(Close[0] > MA_lo)
         FixPrice = Close[0];
     }                                                                              // делаем замер пока цена не пересечет МА
   if(Close[0] < MA_lo)
      Fix = true;
   if(Fix == true)
      FixPrice_L = FixPrice ;
//+------------------------------------------------------------------+
  }
//+------------------------------------------------------------------+

This is how you want it to be memorised.

But keep in mind that at the opening of a candle.

Close[0]=Open[0] 
и Close[0]=High [0] и Close[0]=Low[0]



Therefore, if you need immediate, real-time data, you'd better use

double Bidd=NormalizeDouble(Bid,Digits); если цена сверху или
double Askk=NormalizeDouble(Askk,Digits); если цена снизу МА

double MA_lo=NormalizeDouble(MA_lo,Digits);

It's better to normalize all prices, which will be compared in the condition, so you won't be surprised :)

 
MakarFX:

Чтобы перевернуть ФИБО поменяй местами  р1 и р2

С алертом я не помогу(

MakarFX
:

To reverse FIBO, swap p1 and p2

I can't help with the alerts(

Hi, thanks, got two different solutions, yours is the easiest....