A question for MQL experts - page 2

 
spring
 
Guys, thanks so much everyone, I'll see what fits. Springtime ....
 

I apologise for the possibly incorrect question!

I'm currently dealing with the decompiled EA code. I cannot "get into" a bit of code.

//-----------------------------------------------------------      
int TotalSell() {  int count=0;
   for (int i=0; i<OrdersTotal(); i++) {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderType()==OP_SELL) count++;}return (count);}
//------------------------------------------------------------      
int TotalSellStop() { int count=0;
   for (int i=0; i<OrdersTotal(); i++){
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderType()==OP_SELLSTOP) count++;} return (count);}
//-------------------------------------------------------------------

Please decode (in Russian) line by line this obscure (top or bottom) construct for me ?

In general, the "concept" of this Expert Advisor, I figured it out. Initially, two pending orders are set - Buy Stop and Sell Stop. When either of the pending orders triggers, the second one is deleted. But, at the same time, a trailing stop is set on the open position and the opposite trailing stop-loss is set instead of the stop-loss price!

 
//-----------------------------------------------------------      
int TotalSell() {  int count=0;                                    //Функция возвращающая количество устаноавленныых SELL ордеров 
   for (int i=0; i<OrdersTotal(); i++) {                           //задается цикл от ноля до общего количества всех ордеров 
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;        //Выбирается ордер по позиции из списка, если не выбран - выход
      if (OrderSymbol()!=Symbol()) continue;                       //Сравнивается по символу, если соответствует - продолжить 
      if (OrderType()==OP_SELL) count++;}return (count);}          //Сравнивается по типу SELL, если соответствует то увеличивает счетчик ордеров на 1
//------------------------------------------------------------      
int TotalSellStop() { int count=0;                                 //Тоже что и предидущая функция но для SELLSTOP ордеров
   for (int i=0; i<OrdersTotal(); i++){
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderSymbol()!=Symbol()) continue;
      if (OrderType()==OP_SELLSTOP) count++;} return (count);}
//-------------------------------------------------------------------

That's all there is to it

 
Thank you, xeon!
 

Good evening everyone! A need has arisen.

To use a script that reverses open positions.

To my surprise, I found that the script does not work for some reason! I tried to figure it out, but .... It does not work.

And there, apparently, - too witty author got the design ..., inserted moronic accompanying comments.

/ Развернуть все ордера.mq4
// Скрипт
#property copyright "mandorr@gmail.com"
#include <WinUser32.mqh>
void start()
{
   int i=0, count=0;
   //закладываем массивы значений
   int cmd[];
   int ticket[];
   double lots[];
   string symbol[];
   string type[];
//------------------------------------------------------------   
   for (i=0; i<OrdersTotal(); i++)           {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
      if (OrderType()==OP_BUY || OrderType()==OP_SELL)      {
         ArrayResize(cmd,count+1); 
         ArrayResize(ticket,count+1); 
         ArrayResize(lots,count+1); 
         ArrayResize(symbol,count+1); 
         ArrayResize(type,count+1); 
         cmd[count]=OrderType();
         ticket[count]=OrderTicket();
         lots[count]=OrderLots();
         symbol[count]=OrderSymbol();
         if (OrderType()==OP_BUY) type[count]="Buy";//если открыта длинная позиция
         // заносим её в массив "Buy"
         else type[count]="Sell";// иначе в массив "Sell"
         count++;                                            }
   }
//---------------------------------------------------------------   
   string space="    ";
   string title="Кароче_В_натуре";
   string msg="Развернуть:"+"\n";
   for (i=0; i<count; i++) msg=msg+"\n"+"Order "+ticket[i]+" "+type[i]+" "+DoubleToStr(lots[i],1)+" Lots "+symbol[i]+space;
   if (MessageBox(msg,title,MB_YESNO|MB_ICONQUESTION)!=IDYES)
   {
      title="Аха";
      string ends=""; if (count>1) ends="и";
      msg="Ну и хрен с ним"+ends+" ...    "; 
      MessageBox(msg,title,MB_OK|MB_ICONEXCLAMATION);
      return;
   }
   for (i=0; i<count; i++)
   {
      if(!OrderSelect(ticket[i],SELECT_BY_TICKET)) continue;
      double ask=MarketInfo(symbol[i],MODE_ASK);
      double bid=MarketInfo(symbol[i],MODE_BID);
      int slippage=3;
      if (cmd[i]==OP_BUY )
      {
         OrderClose(ticket[i],lots[i],bid,slippage);
         OrderSend(symbol[i],OP_SELL,lots[i],bid,slippage,0,0,NULL,0,0);
      }
      if (cmd[i]==OP_SELL)
      {
         OrderClose(ticket[i],lots[i],ask,slippage);
         OrderSend(symbol[i],OP_BUY ,lots[i],ask,slippage,0,0,NULL,0,0);
      }
   }
}
// End
Please, can you tell me why it's not working?
 
// Развернуть все ордера.mq4
It's weird everything works just wouldn't be a bad thing to make it so :
 

That's not the point. I put the script on the chart (Alpari demo). I press the "YES" button in the window that appears, but nothing happens. The positions are not reversed. In the logbook at the moment of pressing

2008.04.29 01:15:41 Script Revers__all_orders EURJPY,M15: removed

 

Good afternoon. Please write an iCustom expression for this indicator:



Here is its code -

#property indicator_chart_window
#property indicator_buffers 2

//---- input parameters
extern int R=3;
//---- buffers
double HighBuffer[];
double LowBuffer[];
double VALUE1,VALUE2,VALUE11,VALUE22;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_ARROW,EMPTY,1,Blue);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Yellow);
   SetIndexArrow(0, 0x9F);
   SetIndexArrow(1, 0x9F);

   SetIndexBuffer(0,HighBuffer);
   SetIndexBuffer(1,LowBuffer);

   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
//---- name for DataWindow and indicator subwindow label
   short_name="HiLo";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
//----
   return(0);
  }
//+-----------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
ObjectsDeleteAll(0);   
//----
   return(0);
  }
//+-------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(),i,shift,Swing;   

//---- TODO: add your code here
i=(Bars-counted_bars)-1;

for (shift=i; shift>=0;shift--)  {

VALUE1=iMA(NULL,0,R,0,MODE_SMA,PRICE_HIGH,shift+1);
VALUE2=iMA(NULL,0,R,0,MODE_SMA,PRICE_LOW,shift+1);

if (Close[shift+1]<VALUE2 ) Swing=-1;
if (Close[shift+1]>VALUE1 ) Swing=1;

if (Swing==1) { HighBuffer[shift]=VALUE2; LowBuffer[shift]=0;  }
if (Swing==-1) { LowBuffer[shift]=VALUE1; HighBuffer[shift]=0; }
//----
}
   return(0);
  }
To be able to set the R parameter in the "properties" and the bar number, of course.
 

Yes, sort of like this, if you consider that the indicator name is hilo.mq4:

extern int iR=3;
extern int SignalBar=1;
//.......
//---получение значения HighBuffer
double buy = iCustom( NULL,0, "hilo",
iR,
0, // № буффера
SignalBar ); // № бара

//---получение значения LowBuffer
double sell = iCustom( NULL,0, "hilo",
iR,
1, // № буффера
SignalBar ); // № бара