[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 278

 
Good evening! Dear forum users!
//+------------------------------------------------------------------+
//|                                            ИндюкДимонакомпил.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#import "user32.dll"
   int   PostMessageA(int  hWnd,int  Msg,int  wParam,string lParam);
#import
#define WM_COMMAND                     0x0111
int delimiter = 0;

#property indicator_chart_window

#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 DarkBlue
double ВерхняячертаBuffer1[];
double НижняячертаBuffer2[];
double СинняячертаBuffer3[];
 double вершина; 
 double основание_первого_снижения;
 double начало;
 double вершина_волны_3;
 extern int T=4,K=200;
 int timeframe, start ;
 int бар_вершина ;
 int бар_основание_первого_снижения;
 int бар_начало;
int pereklutsatel;
double naklon,linija2; int P;extern int RO=-1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

SetIndexStyle(0,DRAW_SECTION,STYLE_SOLID,2,CLR_NONE);//Alert ("SetIndexStyle ",GetLastError( ) );
  SetIndexBuffer(0,ВерхняячертаBuffer1);//Alert ("SetIndexBuffer ",GetLastError( ) );
   SetIndexEmptyValue(0,0.0);
   
   SetIndexStyle(1,DRAW_SECTION,STYLE_SOLID,2,CLR_NONE);//Alert ("SetIndexStyle ",GetLastError( ) );
  SetIndexBuffer(1,НижняячертаBuffer2);//Alert ("SetIndexBuffer ",GetLastError( ) ); 
   SetIndexEmptyValue(1,0.0);
   
   SetIndexStyle(2,DRAW_SECTION,STYLE_SOLID,T,CLR_NONE);//Alert ("SetIndexStyle ",GetLastError( ) );
  SetIndexBuffer(2,СинняячертаBuffer3);//Alert ("SetIndexBuffer ",GetLastError( ) ); 
   SetIndexEmptyValue(2,0.0);
   
   
  ObjectDelete("вершина");
  ObjectDelete("основание_первого_снижения  ");
   ObjectDelete("начало");
    ObjectDelete("точка4");
    ObjectDelete("пятая_точка!");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("вершина");
  ObjectDelete("основание_первого_снижения  ");
   ObjectDelete("начало");
    ObjectDelete("точка4");
    ObjectDelete("пятая_точка!");
   ObjectsDeleteAll(WindowOnDropped( ) , OBJ_TEXT);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit=Bars-counted_bars-1;

   for (int i=limit;i>=0;i--) {
//----
 for ( int J=0;J<=RO;J++){
//----

  // for(int i=Bars; i>=0;i--)
   i=Bars;
      бар_вершина=iHighest( NULL,  timeframe, MODE_HIGH, K, start ) ;
       вершина =High[ бар_вершина ];
       бар_основание_первого_снижения=iLowest( NULL,  timeframe, MODE_LOW,NormalizeDouble ( бар_вершина/2,0), start ) ;
       основание_первого_снижения=Low[ бар_основание_первого_снижения ];
       бар_начало=iLowest( NULL,  timeframe, MODE_LOW,NormalizeDouble (бар_вершина*1.5,0), бар_вершина ) ;
       начало=Low[ бар_начало ];
       
   ObjectCreate( "вершина",  OBJ_TEXT , WindowOnDropped( ) , Time[бар_вершина],  вершина+(10*Point)) ; 
    ObjectSetText( "вершина", "вершина", 5, "вершина",Crimson ) ;// Alert("GetLastError()",GetLastError());
      // ObjectSet(  "вершина",  OBJPROP_COLOR, Crimson) ;
      
   ObjectCreate( "основание_первого_снижения",  OBJ_TEXT , WindowOnDropped( ) , Time[бар_основание_первого_снижения],  основание_первого_снижения-(10*Point)) ; 
    ObjectSetText( "основание_первого_снижения", "основание_первого_снижения", 5, "основание_первого_снижения",Crimson ) ;   
   
    ObjectCreate( "начало",  OBJ_TEXT , WindowOnDropped( ) , Time[бар_начало],  начало-(10*Point)) ; 
    ObjectSetText( "начало", "начало", 5, "начало",Crimson ) ;   
           
  if(начало>основание_первого_снижения){naklon=(начало-основание_первого_снижения)/(бар_начало-бар_основание_первого_снижения);
 // Alert("naklon  ", naklon);
    НижняячертаBuffer2[бар_начало]=начало;linija2=начало;for(i=бар_начало-1;i>=0;i--){linija2=linija2-naklon;
   
    НижняячертаBuffer2[i]=linija2;  // Alert ("linija2  " , linija2 );  Alert("НижняячертаBuffer2[i]  ", НижняячертаBuffer2[i] , "  i " , i);
     
   }
    НижняячертаBuffer2[бар_основание_первого_снижения]=основание_первого_снижения;}
    
    
         for (i=0;i<100;i++){  СинняячертаBuffer3[i]= Open[i];}
          for (i=330;i<500;i++){  СинняячертаBuffer3[i]= Open[i];}

     ВерхняячертаBuffer1[бар_начало]=начало;
     
 double точка4; int бар_точка4;   бар_точка4=iHighest( NULL,  timeframe, MODE_HIGH, бар_основание_первого_снижения, 3 ) ; 
  точка4 =High[ бар_точка4 ];  
   
   if(вершина>точка4){naklon=(начало-точка4)/(бар_начало-бар_точка4);
   ObjectCreate( "точка4",  OBJ_TEXT , WindowOnDropped( ) , Time[бар_точка4],  точка4+(10*Point)) ; 
    ObjectSetText( "точка4", "точка4", 5, "точка4",Crimson ) ;  
   double linija1=начало;for(i=бар_начало-1;i>=0;i--){linija1=linija1-naklon;ВерхняячертаBuffer1[i]=linija1; }}
   
double vulf=НижняячертаBuffer2[0];
  if ( vulf==Ask||vulf==Bid)vulf=1;
 if (vulf+(10*Point)>Ask&&vulf-(10*Point)<Bid)vulf=1 ; 
           
      Alert ("vulf  " , vulf );   Comment ("  vulf!!! "  , vulf);  
   if (vulf==1){Comment ("  Есть вульв!!! "  , "  timeframe " , timeframe);
   ObjectCreate( "пятая_точка!",  OBJ_TEXT , WindowOnDropped( ) , Time[0],  Bid-(10*Point)) ; 
    ObjectSetText( "пятая_точка!", "пятая_точка!", 5, "пятая_точка!",Crimson ) ;   return(0);  }
    if (vulf!=1) {    
   
     if(delimiter<3){delimiter++;Comment(delimiter);return(0);}
   delimiter=0;
    fChangePeriod();P++;
                                 
                   }  } }
//----
   return(0);
  }
//+------------------------------------------------------------------+

void fChangePeriod(){int ii,hwd = WindowHandle(Symbol(),Period());
   switch(Period()){
      case PERIOD_W1    : ii = 33134; break; //PERIOD_D1;
      case PERIOD_D1    : ii = 33136; break; //PERIOD_H4;
      case PERIOD_H4    : ii = 33135; break; //PERIOD_H1;
      case PERIOD_H1    : ii = 33140; break; //PERIOD_M30;
      case PERIOD_M30   : ii = 33139; break; //PERIOD_M15;
      case PERIOD_M15   : ii = 33138; break; //PERIOD_M5;
      case PERIOD_M5    : ii = 33137; break; //PERIOD_M1;
      case PERIOD_M1    : ii = 33141; break; //PERIOD_W1;
   }     
   PostMessageA(hwd, WM_COMMAND, ii, 0);
   return;
}
The indicator I'm moulding works like hell... With a lot of flaws, how should I say, even a lot worse... Among other things, it draws intermittently. Yes, it often doesn't draw on the chart, but sometimes it does... What could be the common cause?
 
drknn:


Have you looked here? https://book.mql4.com/ru/samples/index

Generally, like any other program, yours will consist of separate blocks, each of which performs some task. You take one such block and write your own code, debug it and then move on to the next block. And so on till the end of the program.

Thank you...
 
evillive:

Good afternoon!

Please advise me on a reliable way to identify a flat, if there is one at all.

There is. I'm charging for real this week also based on it.
 
evillive:

Good afternoon!
Please advise me on a reliable way to identify a flat, if there is one at all.

A flat is a price movement consisting of one or more flat elements.
A flat element is an element of the price movement formed when the price moves in any direction from its starting point with subsequent price rollback to this point.

 

For the delivery of the order the following command is used

tikett= OrderSend( Symbol(), OP_SELLSTOP,  volume*A, Price -otstup*Point, Point* 3,R2, Price-takeprofit*Point-otstup*Point, "OP_SELLSTOP" , 2000,  expiration,C'0,128,255' );

The command OrderSend commands the robot to place the order; the currency pair is written in brackets in the first position. Here we have Symbol() that gives us the currency pair where the Expert Advisor has been placed. This is followed by the name of the trade operation. Then we have the lot volume and we have a variable multiplier here. Price, then a deviation of 3 pips, Stop Loss, Take Profit, name, magic number - any number you have chosen, then I don't remember, then colour. Everything is in this order. You can do without tikett=, just OrderSend.

And here, pay attention! The order will be placed on every tick, up to hundreds of orders, if it is just written in the start. We need conditions so that the order would be placed when it is necessary. Example.

for ( i=OrdersTotal();i>0;i--){ OrderSelect(i-1,SELECT_BY_POS );//Alert ("OrderType( )", OrderType( ));
 if( OrderMagicNumber( )==2000 &&OrderSymbol()==Symbol()) { 
if(OrderType( ) ==OP_SELLSTOP) { Y++;}
if(OrderType( ) ==OP_SELL) { Y++;}}}
Y=Y-dolivka1;//Alert ("Y++", Y," dolivka1 ",dolivka1);
 if (Y<=0){ // Alert ("Y", Y );
   tikett= OrderSend( Symbol(), OP_SELLSTOP,  volume*A, Price -otstup*Point, Point* 3,R2, Price-takeprofit*Point-otstup*Point, "OP_SELLSTOP" , 2000,  expiration,C'0,128,255' );
   // Alert ("OP_SELLSTOP", GetLastError( )); 
    Error=GetLastError( ); } J=0;

   if (Error !=0 ) { Print ( " Error OP_SELLSTOP " , Error , "tikett",tikett," volume*A ",volume*A," Price -otstup*Point ",Price -otstup*Point," Price-takeprofit*Point-otstup*Point ",Price-takeprofit*Point-otstup*Point, 
  " Ask ", Ask , " Bid " , Bid );
   Error=0;}

Tired. Use the help, to analyse the ready examples.

 
drknn:


Have you seen it here? https://book.mql4.com/ru/samples/index

Generally, like any other program, yours will consist of separate blocks, each block performs a task. We take one such block and write our own code, debug it from end to end and then move on to the next block. And so on to the end of the program.


Well, I will try to be more specific... My Expert Advisor successfully opens ONE pending order and it has to modify it after some time... To do this, I need to know its index or a position number in a pending order. How can I obtain this position number or its index? Do we have to search for orders using a for loop? I have ONE order... Here is a part of the code of my program that doesn't work


if (OrderSelect (1, SELECT_BY_POS, MODE_TRADES)==true)

{ticket = OrderTicket();

return();}

How should I write it correctly?

 
AlexLaptist:


And yet I will try to put the question more precisely... My Expert Advisor successfully opens ONE pending order and after some time it has to modify it... To do this, we need to know its index or a position number in pending orders. How can I obtain this position number or its index? Do we have to search for orders using a for loop? I have ONE order... Here is a part of the code of my program that doesn't work


if (OrderSelect (1, SELECT_BY_POS, MODE_TRADES)==true)

{ticket = OrderTicket();

return();}

How do I write it correctly?


The function OrderSend(), if executed successfully, returns the number of the ticket of the order it just opened - this is its sequence number on the server, and there is no other such order. So there is no need to run a retracement of the order, just remember its ticket. Just remember it as soon as the order is opened.

int Ticket=OrderSend();
if(Ticket<0){
// тут принтуем сообщение об ошибке.
}
// Вам нужно всё равно создать счётчик ордеров, который обнулит переменную Ticket в том случае, если ордера в рынке больше нет.
 
drknn:


The OrderSend() function, if successfully executed, returns the order ticket number that it has just opened - this is its serial number on the server and there is no other such order. So there is no need to run a retracement of the order, just remember its ticket. Just remember it as soon as the order is opened.

And how long will we 'remember' him for? You could lose it...

IMHO - we should always take fresh and up-to-date information as we need it, rather than storing it in memory, dependent on the occasion.

It would be better to find the order right before modifying it rather than hope for the chance... Just in case the power is not switched off, for example...

 
AlexLaptist:


And yet I will try to put the question more precisely... My Expert Advisor successfully opens ONE pending order and after some time it has to modify it... To do this, we need to know its index or a position number in pending orders. How can I obtain this position number or its index? Do we have to search for orders using a for loop? I have ONE order... Here is a part of the code of my program that doesn't work


if (OrderSelect (1, SELECT_BY_POS, MODE_TRADES)==true)

{ticket = OrderTicket();

return();}

How do I write it correctly?

Maybe it goes something like this:

//+----------------------------------------------------------------------------+
int TicketLastSetOrder(string sy, int mn) { // 
   datetime t;
   int      i, op, ticket=-1;
   for (i=0; i<OrdersTotal(); i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         op=OrderType();
         if (OrderMagicNumber()!=mn)   continue;
         if (OrderSymbol()!=sy)        continue;
         if (op<2 || op>5)             continue;
         if (OrderOpenTime()>t)  {
            t=OrderOpenTime();
            ticket=OrderTicket();
            }
         }
      else Print("FUNC TicketLastSetOrder(): Error select order: "+GetLastError());
      }
   return(ticket);
}
//+----------------------------------------------------------------------------+

Returns the ticket of the last set order or -1

When calling, please specify the required symbol and the EA's magik, for example:

   int TicketMyOrder=TicketLastSetOrder(Symbol(), Magic);

This function will return the ticket of the last pending order placed at the current symbol (the only one in your case). Magic - the magic number of your EA

 

You could put the ticket in global variables as well. :) You can roll the hell out of it at all. But as an idea selection of the order before modification will work. Only if it is not necessary to reset lots only 1 time for all time of an order lifetime (with single modification at that) :) :).

In short, there are a lot of variants :)