[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 484

 
san44es:

Folks, a word of advice!

There is a custom function that counts the Low price of the 5th bar of the background timeframe, how do I make it count the price of a specific timeframe?

iLow
 

Thank you ! The code is simpler now. Certainly simpler.

Thanks for the Slippage!

The loop for (int A = 0; A <100 ; A++) // we don't need this search of bars, it only helps me to see from the log that the EA has placed orders exactly where the arrows are or where the error number is. The point is that there were no signals in the tester. I saw on the same prints that the variables arrow1 and arrow2 were only zero on all bars and that is how I got out of the situation.

The cycle can of course be counted in either direction. But again I see error 129 everywhere! I see the arrows of the indicator in the chart and I want to make sure that the orders have been placed by them. So, on a screenshot in the beginning variables arrow 1and2 are equal, further on 17 bars from zero, the order is set - okey, super! Then the printer's messages that there is a sell with so-and-so tick, and the arrows on further bars are equal - great!!!!

 
Next you have to delete a sell on the red arrow and place a buy. Suddenly two orders are deleted!!! Two orders, the one that's clearly set and another one that didn't seem to be there!!! All right, the hell with it... Error 129 comes up and there's no order. I'm sorry if I've been baffling all the good volunteer helpers like this.
 
//+------------------------------------------------------------------+
//|                                                     советник.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#include <WinUser32.mqh>
  extern double  lot         = 1;                          
  extern int     taymfreym   = 0 ;                           
  extern double  stoplos     = 200 ;                          
  extern double  takeprofit  = 500 ; 
  extern int     magicnumber = 350;
  extern int     ControlBar  = 1;      // номер бара на котором снимаем показания индикатора                     


void BreakPoint()
{//if (!IsVisualMode()) return(0);
    keybd_event (19,0,0,0);
    Sleep (10);
    keybd_event (19,0,2,0);
}

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   Print (   "  НачалоНачал " ); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int i;
int start()
{
  //Print (   "  Начало " ); 
//----
    for (int A = 0; A <100 ; A++) // ни к чему этот перебор баров
    {
        double strela1 = iCustom (NULL, taymfreym, "индикатор", 2, A),
               strela2 = iCustom (NULL, taymfreym, "индикатор", 3, A);
        int BUY = 0, SELL = 0, ticket; 
        Print (A, "  strela1 " , strela1 , "    strela2  " , strela2);
    
    for (int i = OrdersTotal() - 1; i >= 0; i--)
    {  
        if (!OrderSelect (i - 1, SELECT_BY_POS)) continue;  // Если есть следующий
        if (OrderSymbol() != Symbol()) continue;      // Не наш фин. инструм
        if (OrderMagicNumber() != magicnumber) continue;
        int type = OrderType();
        if (type > 1) continue;
        ticket = OrderTicket();
        if (type == 0) {BUY++; Print ("BUY++   " , BUY  ,"  ticket ", ticket); break;}
        if (type == 1) {SELL++; Print ("SELL++   " , SELL  ,"  ticket ", ticket); break;}
    }
    if (strela1 < strela2)
    {
        if (SELL > 0) udalenie (OP_SELL);
        if (BUY == 0)
        {
            OrderSend (Symbol( ), OP_BUY, lot,NormalizeDouble(Ask, Digits), 3, NormalizeDouble( Bid- (stoplos*Point),Digits),   NormalizeDouble( Ask+( takeprofit*Point),Digits), NULL, magicnumber, 0, CLR_NONE);           
            Print ("strela1>strela2&&BUY==0&&SELL==0   " , GetLastError()  ,"  Ask ",Ask,"   stoplos= NormalizeDouble( Bid- (stoplos*Point),Digits)  ",
            NormalizeDouble ( Bid- (stoplos*Point),Digits),"    takeprofit= NormalizeDouble( Ask+( takeprofit*Point),Digits) ", NormalizeDouble( Ask+( takeprofit*Point),Digits));
        }
    }
    else if (strela1 > strela2)
    {
        if (BUY > 0) udalenie (OP_BUY);
        if (SELL == 0)
        {
            OrderSend (Symbol( ), OP_SELL, lot, NormalizeDouble (Bid, Digits), 3, NormalizeDouble( Ask+ (stoplos*Point),Digits),   NormalizeDouble( Ask-( takeprofit*Point),Digits), NULL, magicnumber, 0, CLR_NONE) ; 
            Print ("strela1>strela2&& OP_SELL  " , GetLastError()   ,"  Bid ",Bid,"    stoplos=   NormalizeDouble( Ask- (stoplos*Point),Digits)  ",
            NormalizeDouble (Ask- (stoplos*Point),Digits),"    takeprofit= NormalizeDouble( Bid+( takeprofit*Point),Digits) ", NormalizeDouble(Ask+( takeprofit*Point),Digits));
            Print( "strela1>strela2&& OP_SELL   " , GetLastError()  ," (stoplos*Point) ",(stoplos*Point),"   Point  ", Point,"   Digits  ", Digits);
        }
    }
    }
    BreakPoint();     
//----
    return (0);
}
//+------------------------------------------------------------------+

void udalenie (int Type = -1)
{
    int total = OrdersTotal();
    for (i = total - 1; i >= 0; i--)
    {
        if (!OrderSelect (i, SELECT_BY_POS)) continue;
        if (OrderSymbol() != Symbol()) continue;      // Не наш фин. инструм
        if (OrderMagicNumber( ) != magicnumber) continue;
        int type = OrderType();
        if (type > 1) continue;
        if (Type > -1) if (Type != type) continue;
        bool result = false;
        switch (type)
        { 
            case OP_BUY       : result = OrderClose (OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 3, CLR_NONE ); break;
            case OP_SELL      : result = OrderClose (OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 3, CLR_NONE ); break; 
        }
        if (!result)
        {
            int error =  GetLastError(); 
            string errorcomment = "Неудалось закрыть ордер №" + OrderTicket() + " " + Symbol() + " " + OrderType() + " " + error; 
            Print (errorcomment);
        }  
    }       
}
 
Wait, excuse me, I'll put the slips all over the place!
 
Dimka-novitsek:
Next you have to delete a sell on the red arrow and place a buy. Suddenly two orders are deleted!!! Two orders, the one that's clearly set and another one that didn't seem to be there!!! All right, the hell with it... Error 129 comes up and there's no order. You'll forgive me for baffling all the good volunteer helpers...

Dimka - give me your code in my personal message - I'll mess around - I have nothing to do while my"grail" is being tested ... and my brain needs a workout... And don't forget the indulgence...
 

Hi all, I'm a newbie, so please don't kick me wildly. A few questions have accumulated.

1) Where can I download the complete history of quotes. I have understood that MT4 terminal download quotes from MetaQuotes by default. But there is a gap from January 2012 to October 2012 and it is not closed when re-downloading. This calls into question the whole history from there.

2) The history has dates before 1999, the data for them some strange, very few, even by minutes. Does anyone even take them into account or delete them.

3) And some other nonsense is going on with the test. I decided to try to write a simple Expert Advisor: Buy when Open[1]<MA1 && Close[1]>MA1. When testing, the MA (exponential) always shows different values depending on the initial testing date. At that the longer is the МА period (for example 1000-1200) the bigger is the error. What is the problem?

 
Dimka-novitsek:

Thank you ! The code is simpler now. Certainly simpler.

Thanks for the Slippage!

The loop for (int A = 0; A <100 ; A++) // we don't need this search of bars, it only helps me to see from the log that the EA has placed orders exactly where the arrows are or where the error number is. The point is that there were no signals in the tester. I saw on the same prints that the variables arrow1 and arrow2 were only zero on all bars and that is how I got out of the situation.

The cycle can of course be counted in either direction. But again I see error 129 everywhere! I see the arrows of the indicator in the chart and I want to make sure that the orders have been placed by them. So, on a screenshot in the beginning variables arrow 1and2 are equal, further on 17 bars from zero, the order is set - okey, super! Then the printer's messages that there is a sell with so-and-so tick, and the arrows on further bars are equal - great!!!!

About the cycle:

for (int A = 0; A <100 ; A++)

Before you do something (write code), you need to have a clear idea of what you want to get. You have this indicator on every tick, and you can have a complete layout of its readings. In this way (loop) you'll have output in variables strela1 and strela2 readings at the 100th bar and you can trade by these readings (last winter)... :))) I didn't pay attention at once - you have included trading operations into loop of indicator readings - a total P... Of course, you know best. :)))

 
No, I need the loop to see the entry/exit, that is, to test the robot. How it places orders, how it makes mistakes. Well, it doesn't test in the tester...
 
Dimka-novitsek:
No, I need the cycle to see the entry/exit, that is, to test the robot. How it places orders, how it makes mistakes. It doesn't test in the tester...

What can I say - GENIAL... Good luck!

P.S. In my code found a small error in connection with change of direction of enumeration of orders, even reduced the code, as well as made an attempt to create optimizability in the tester (check it yourself).
And I have a suspicion that you don't read the data correctly from the indicator. The indicator has several buffers (4 in my version). Some, such as those that draw arrows - have a value ONLY where the arrow is. To search for signals in such buffers, you need to organise a loop (while()) with a condition that the return value is not equal (in my variant EMPTY_VALUE) to an "empty" value. Where there are "no arrows" (in these buffers), the signal must be searched for by comparing the return value with the price.

Files:
lxvhlxyx.mq4  5 kb
Reason: