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

 
Can't install MT4 at work (admins must be working correctly). Can anyone advise if there is any way to install MT4 locally on a flash drive so it doesn't require a connection to a server. I would then bring the currency history from home, I would only need it to test the Expert Advisors, without live trading. MetaEditor doesn't work either :(
 
paladin80:
In my experience, the most effective way to find errors is to display a message in the comments with the error number followed by a visual run of the EA. In the beginning it takes a lot of time, but then you quickly learn how to do it without errors. You can also exclude parts of the code with /* ... */, you can determine how the behaviour of the EA changes.
I do the same))
 
alsu:
You got it right. Further, when we take a value out of the box, it is of type double, but if the command is given to write the result into a variable of type int, the compiler will automatically take all necessary steps to put the value into a new box.


To finally make sure I have got it right, please check my thoughts on your last paragraph... So let us have the above mentioned expert:

//--------------------------------------------------------------------
// globalvar.mq4
// Предназначен для использования в качестве примера в учебнике MQL4.
//--------------------------------------------------------------------
int    Experts;                                 // Колич. экспертов
double Depo=10000.0,                            // Заданный депозит
       Persent=30,                              // Заданный процент     
       Money;                                   // Искомые средства
string Quantity="GV_Quantity";                  // Имя GV-переменной
//--------------------------------------------------------------------
int init()                                      // Спец. функция init
  {
   Experts=GlobalVariableGet(Quantity);         // Получим тек. знач.
   Experts=Experts+1;                           // Колич. экспертов
   GlobalVariableSet(Quantity, Experts);        // Новое значение
   Money=Depo*Persent/100/Experts;              // Средства для эксп.
   Alert("Для эксперта в окне ", Symbol()," выделено ",Money);
   return;                                      // Выход из init()
  }
//--------------------------------------------------------------------
int start()                                     // Спец. функция start
  {
   int New_Experts= GlobalVariableGet(Quantity);// Новое колич. эксп.
   if (Experts!=New_Experts)                    // Если изменилось
     {
      Experts=New_Experts;                      // Теперь текущ. такое
      Money=Depo*Persent/100/Experts;           // Новое знач. средств 
      Alert("Новое значение для эксперта ",Symbol(),": ",Money);
     }
   /*
   ...
   Здесь долен быть указан основной код эксперта,
   в котором используется значение переменной Money
   ...
   */
   return;                                      // Выход из start()
  }
//--------------------------------------------------------------------
int deinit()                                    // Спец. ф-ия deinit
  {
   if (Experts ==1)                             // Если эксперт один..
      GlobalVariableDel(Quantity);              //..удаляем GV-перемен
   else                                         // А иначе..
      GlobalVariableSet(Quantity, Experts-1);   //..уменьшаем на 1
   Alert("Эксперт выгружен из окна ",Symbol()); // Сообщ. о выгрузке
   return;                                      // Выход из deinit()
  }
//--------------------------------------------------------------------

Then in the string:

Experts=GlobalVariableGet(Quantity);         // Получим тек. знач.

We put a variable of integer type Experts in the box "GV-variable" for storage (converting it to type double). Then if (hypothetical assumption) there would be a string in the Expert Advisor

int New_Experts=Experts;

it would mean that there is a command to write the result into a variable of int type. In this case the compiler:

* would take the value of the variable of type double out of the box,

* make any necessary changes to the value of the Experts variable,

* assign this value to the variable New_Experts and...

* put the value of variable New_Experts into an "int" box.

So the variable type is nothing more than just an external wrapper/package of some value? and so GV variables can't be of the string type, as downgrading is only allowed for numeric values, and strings are not converted to numbers.

Right?

Thank you in advance for your reply.

 
Stells:
what not so for (f=1;f<Bars;f++)
{
Price1 = (iClose(Symbol_1,0,0) - iClose(Symbol_1,0,f)) / MarketInfo(Symbol_1, MODE_POINT)
Price2 = K*(iClose(Symbol_2,0,0) - iClose(Symbol_2,0,f)) / MarketInfo(Symbol_2, MODE_POINT);
Spread = Price1 - Price2;
Print ("Price1="+Price1, " Price2="+Price2);
if (Spread==0){t=f; break;}
}
Price12 = (iClose(Symbol_1,0,0) - iClose(Symbol_1,0,t)) / MarketInfo(Symbol_1, MODE_POINT);
Price22 = K*(iClose(Symbol_2,0,0) - iClose(Symbol_2,0,t)) / MarketInfo(Symbol_2, MODE_POINT);
Spread2 = Price12 - Price22;


if (MathAbs(Spread2) >= razdvizka && Spread2 < 0) { open trade }


want to fix the bar where the spread was equal to zero and control the spread from it

if(MathAbs(Spread)<eps) { ........ } and you still need to control the result - whether the point satisfying the condition is found or not. IMHO it's better to create a separate function, for example, like this:

int GetBarNumWithZerroDist(string Smbl1, string Smbl2, double K, double eps=0.00001)
{
int i=1;
double Smb1Cl0 = NrmalizeDouble(iClose(Smbl1,0,0));
double Smb2Cl0 = NrmalizeDouble(iClose(Smbl2,0,0));
double Smb1Pnt = MarketInfo(Smbl1, MODE_POINT);
double Smb2Pnt = MarketInfo(Smbl2, MODE_POINT);
int    mBars   = MathMin(iBars(Smbl1), iBars(Smbl2));

    for (i=1;i<mBars;i++) 
    {
        double Price1 =   (Smb1Cl0 - iClose(Symbol_1,0,i)) / Smb1Pnt;
        double Price2 = K*(Smb1Cl0 - iClose(Symbol_2,0,i)) / Smb2Pnt;
        double Spread = Price1 - Price2; 
        //Print ("Price1="+Price1, " Price2="+Price2);
        if(MathAbs(Spread)< eps) return(i);
    }
    return(-1);
}
 

hello.

Do you know if there is a #property in indicators that allows the indicator to always show the same period, e.g. d1?

and it will not switch even if you switch timeframes in MetaTrader?

thanks

------------------------------------------

oh... how many pros.....

 

help!!!!

how to call the indicator from the script, I really need it to be displayed in a window

 

Good evening! Please help me make changes to the EA code:
1. When testing everything is fine - but when trading the first trade has to be opened manually, stop and take too. I would like the EA to start trading automatically when the price arrives at a new tick.
2. Since in the case of a triggered stop loss, the next position is opened with twice the previous lot, the lot can theoretically increase to infinity (in my case, up to 51.2), I would like to limit it (eg 0.8) with the ability to change the threshold. When the threshold is reached and a stop is triggered, the Expert Advisor would not disconnect and would start over from 0.1.

//--- input parameters
extern double    Lot=0.1;
extern int       TP=22;
extern int       SL=20;
extern double    K_Martin=2;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
 {
double oop, ocp, osl, otp, ol; 
int Magic = 0;
int closetime= 0,lastorder=0, tip=0;
for(int i=0;i<OrdersHistoryTotal();i++) /* Цикл перебора ордер*/
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue; // Выбираем ордер из истории.
if(OrderMagicNumber()!=Magic) continue;
if(closetime<OrderCloseTime())
{
closetime = OrderCloseTime();
lastorder = OrderTicket();
tip=OrderType();
ol=OrderLots();
}
}
OrderSelect(lastorder,SELECT_BY_TICKET,MODE_HISTORY);
ocp= (OrderClosePrice());
oop= (OrderOpenPrice());
osl= (OrderStopLoss());
otp= (OrderTakeProfit());
ol= (OrderLots());
Print ("ОРДЕР №--[",OrderTicket(),"-",OrderLots(),"]--","цена открытия ОРДЕРА--[",OrderOpenPrice(),"]"); 
Print ("ОРДЕР №--[",OrderTicket(),"-",OrderLots(),"]--","цена закрытия ОРДЕРА--[",OrderClosePrice(),"]");
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==false )
{
if(tip == OP_SELL && osl==ocp) //Ордер SELL закрылся по по SL значит покупаем
{
OrderSend(Symbol(),OP_BUY,ol*K_Martin,Ask,0,Ask-SL*Point,Ask+TP*Point,0,0,0,Blue); /*Если выполняется условие то покупаем*/
}
if(tip == OP_SELL && otp==ocp) //Ордер SELL закрылся по по TP значит продаем
{
OrderSend(Symbol(),OP_SELL,Lot,Bid,0,Bid+SL*Point, Bid-TP*Point,0,0,0,Red); /*Если выполняется условие то продаем*/ 
} 
if(tip == OP_BUY && osl==ocp) //Ордер BUY закрылся по SL значит продаем
{
OrderSend(Symbol(),OP_SELL,ol*K_Martin,Bid,0,Bid+SL*Point,Bid-TP*Point,0,0,0,Red); /*Если выполняется условие то продаем*/ 
}
if(tip == OP_BUY && otp==ocp) //Ордер BUY закрылся по по TP значит покупаем
{
OrderSend(Symbol(),OP_BUY,Lot,Ask,0,Ask-SL*Point,Ask+TP*Point,0,0,0,Blue); /*Если выполняется условие то покупаем*/
} 
}
return(0);
}

 
Top2n:

Help, please. I've been struggling all day without any help.

Order is on the pickup (Main BAY, pending sellsstop as a safety net).

At closing sellsstop in the no-loss, postponed again in the same place.

Spin this thing,https://www.mql5.com/ru/code/8846.
 
7777877:


To finally make sure I have got it right, please check my thoughts on your last paragraph... So let us have the above mentioned expert:

Then in the string:

We put a variable of integer type Experts in the box "GV-variable" for storage (converting it to type double). Then if (hypothetical assumption) there would be a string in the Expert Advisor

it would mean that there is a command to write the result into a variable of int type. In this case the compiler:

* would take the value of the variable of type double out of the box,

* make any necessary changes to the value of the Experts variable,

* assign this value to the variable New_Experts and...

* put the value of variable New_Experts into an "int" box.

So the variable type is nothing more than just an external wrapper/package of some value? and so GV variables can't be of the string type, as downgrading is only allowed for numeric values, and strings are not converted to numbers.

Right?

Thanks in advance for the answer.

Not exactly. The point is that the Experts variable already has the int type, hence, the type conversion must take place BEFORE assigning a value to it, i.e. the compiler

* took out of the box a value of type double (it has no name in your program, and is written simply to some address known to the compiler in main memory or in CPU register)

* made all necessary changes to the value of the above variable and wrote a new value (of int type!) into Experts variable,

* assigned this value (of int! type) to the variable New_Experts. They have the same type, so it's just a matter of copying a value from one memory location to another.


P.S. It's great to see that there are people who comprehend their deeds in such detail. In fact, no kidding. Keep in touch.

 
Andrew1001:

Good evening! Please help me make changes to the EA code:
1. When testing everything is fine - but when trading the first trade has to be opened manually, stop and take too. I would like the EA to start trading automatically when the price reaches a new tick.
Since in the case of a triggered stop loss, the next position is opened with twice the previous lot, the lot can theoretically increase to infinity (in my case, up to 51.2), I would like to limit it (eg 0.8) with the ability to change the threshold. When the threshold is reached and a stop is triggered, the EA would not disconnect, but would start over from 0.1.


Try it:

extern double Lot=0.1,K_Martin=2,porog=0.8;
extern int TP=22,SL=20,Magic=233;
extern bool poz1_up=true;//ваш выбор:1-ая покупка или продажа(false)? 
extern bool Trade=true;//торговля разрешить?
bool fix;int init(){fix=true;return(0);}int deinit(){return(0);}
int start(){double oop,ocp,osl,otp,ol,lotos;int closetime=0,lastorder=0,tip=0;if(!Trade)return(0);
if(poz1_up&&fix){OrderSend(Symbol(),OP_BUY,Lot,Ask,0,Ask-SL*Point,Ask+TP*Point,0,Magic,0,Blue);fix=0;}  
if(!poz1_up&&fix){OrderSend(Symbol(),OP_SELL,Lot,Bid,0,Bid+SL*Point,Bid-TP*Point,0,Magic,0,Red);fix=0;}
for(int i=0;i<OrdersHistoryTotal();i++)
  {if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
   if(OrderMagicNumber()!=Magic)continue;
   if(closetime<OrderCloseTime())lastorder=OrderTicket();}
if(OrderSelect(lastorder,SELECT_BY_TICKET,MODE_HISTORY))
  {tip=OrderType();oop=OrderOpenPrice();osl=OrderStopLoss();
   otp=OrderTakeProfit();ol=OrderLots();ocp=OrderClosePrice();}
Print("ОРДЕР №--[",OrderTicket(),"-",OrderLots(),"]--","цена открытия--[",OrderOpenPrice(),
        "]--","цена закрытия--[",OrderClosePrice(),"]--","прибыль--[",OrderProfit(),"]");
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==0)
  {if(tip==OP_SELL){if(osl==ocp){lotos=ol*K_Martin;if(lotos>porog)lotos=Lot; 
     OrderSend(Symbol(),OP_BUY,lotos,Ask,0,Ask-SL*Point,Ask+TP*Point,0,Magic,0,Blue);}
     if(otp==ocp)OrderSend(Symbol(),OP_SELL,Lot,Bid,0,Bid+SL*Point,Bid-TP*Point,0,Magic,0,Red);} 
  if(tip==OP_BUY){if(osl==ocp){lotos=ol*K_Martin;if(lotos>porog)lotos=Lot;
     OrderSend(Symbol(),OP_SELL,lotos,Bid,0,Bid+SL*Point,Bid-TP*Point,0,Magic,0,Red);} 
  if(otp==ocp)OrderSend(Symbol(),OP_BUY,Lot,Ask,0,Ask-SL*Point,Ask+TP*Point,0,Magic,0,Blue);}}return(0);}
//+------------------------------------------------------------------+