[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 284

 
 
waitra >> :

int NumberOfPos_HISTORY

I tried it, it only counts the number of open current positions, it does not count history, it returns the value to zero when closing the order, maybe something else should be changed?

Here I have done it. I took another function of I.Kim and changed it a bit.

It works like clockwork:

The START function may be used for control.

Comment ("ордера на истории= ",NumberOfPos_HISTORY_2(NULL,-1,Magic));

And here is the function itself:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru            |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                  |
//|  Описание : Возвращает кол-во ордеровиз из  истории счета  |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                           |
//|    sy - наименование инструмента   (""   - любой символ, |
//|                                     NULL - текущий символ)        |
//|    op - операция                   (-1   - любая позиция)       |
//|    mn - MagicNumber                (-1   - любой магик)             |
//+----------------------------------------------------------------------------+
int NumberOfPos_HISTORY_2 (string sy="", int op=-1, int mn=-1) {
     int      i, k=OrdersHistoryTotal(), kp=0;
  if ( sy=="0") sy=Symbol();
  for ( i=0; i< k; i++) {
    if (OrderSelect( i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()== sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if ( op<0 || OrderType()== op) {
            if ( mn<0 || OrderMagicNumber()== mn) {               
                if (OrderProfit()<0 || OrderProfit()>=0) kp++;           
            }  } } } }  }  return( kp);}


 

Hello all!!!

//+------------------------------------------------------------------+
//|                                                   SimpleMA22.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//---- input parameters
extern int       MAFP=21;
extern int       MASP=55;
extern double    Lots=0.1;
extern int       StopLoss=60;
extern int       TakeProfit=30;
extern int       MagicNumber=123456;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
   
bool CheckOrders(int Type)
{
 bool Result= True;
 for(int i=0; i<OrdersTotal(); i++)
  if(OrderSelect( i, SELECT_BY_POS))
   if(OrderMagicNumber()== MagicNumber && OrderSymbol() == Symbol())
      if(OrderType()== Type)
        {
         if( Type==OP_BUY)
           if(!OrderClose(OrderTicket(),OrderLots(),Bid,0))
             Result= False;
         if( Type==OP_SELL)
           if(!OrderClose(OrderTicket(),OrderLots(),Ask,0))
             Result= False;
         } 
        else Result= False;
 return( Result); 
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
    // Узнаем уровень стопов и спрэд
    int Spread = MarketInfo(Symbol(), MODE_SPREAD);
    int StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL);

    // Рассчитываем значения средних на 0-ом и 1-ом барах
    double MAF_0 = iMA(NULL, 0, MAFP, 0, 1, 1, 0);
    double MAF_1 = iMA(NULL, 0, MAFP, 0, 1, 1, 1);
    double MAS_0 = iMA(NULL, 0, MASP, 0, 1, 1, 0);
    double MAS_1 = iMA(NULL, 0, MASP, 0, 1, 1, 1);
    
    // открытие позиции Buy покупка
    if( MAF_1 < MAS_1 && MAF_0 > MAS_0)
     if( CheckOrders(OP_SELL))
      {
       if( StopLoss <= StopLevel+ Spread)
         double SL = 0;
        else
         SL = Ask - StopLoss*Point;
       if( TakeProfit <= StopLevel- Spread)
         double TP = 0;
        else
         TP = Ask + TakeProfit*Point;
       if(!OrderSend(Symbol(), OP_BUY, Lots, Ask, 5, SL, TP, NULL, MagicNumber))
         Print("Не открыт ордер Buy. Ошибка №", GetLastError()); 
       }
    
    // Открытие позиции Sell продажа  
    if( MAF_1 > MAS_1 && MAF_0 < MAS_0)
     if( CheckOrders(OP_BUY))
      {
       if( StopLoss <= StopLevel+ Spread)
         SL = 0;
        else
         SL = Bid + StopLoss*Point;
       if( TakeProfit <= StopLevel- Spread)
         TP = 0;
        else
         TP = Bid - TakeProfit*Point;
       if(!OrderSend(Symbol(), OP_SELL, Lots, Bid, 5, SL, TP, NULL, MagicNumber))
         Print("Не открыт ордер Sell. Ошибка №", GetLastError()); 
       }
//----
   return(0);
  }//+------------------------------------------------------------------+


Brains steamed, steamed and turned off.....

Probably easier to figure out how to get the drunks to dig a trench or organize rubbish collection by bums than..........

In this thread, somewhere in the beginning, a problem similar to mine was raised. Read, read.... I still don't get it, and the conversation was about flags...

The idea is simple. SimpleMA, but it's a little bit modified, but it doesn't matter.

Wh Whose fi should be added IF an EA (to buy) would buy, an order would be triggered by TP and the next order would be put on condition of selling, ie, MACC crossing for selling?

Regardless of whether there is a further condition or not.

 

Perhaps the function https://www.mql5.com/ru/forum/107476/page21 can help.

Function isCloseLastPosByTake().
This function returns a flag to close the last position by Take.

Flag up - True - TakeProfit was triggered.

Flag lowered - False - position was closed due to another reason.


The function itself should be placed at the very end of the code. Add to the Sell condition:

if( isCloseLastPosByTake( NULL, OP_BUY, MagicNumber) ==true) {//продаем



 
xmurik писал(а) >>
On the EUR/USD pair.
//+------------------------------------------------------------------+
//|                                                       скрипт.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   int kolvo_barov = 1000;
   double start_price = iOpen(Symbol(),0, kolvo_barov);
   int handle;
   handle=FileOpen("my_data.csv", FILE_WRITE|FILE_CSV, '\t');
   if( handle>0) {
      while( kolvo_barov>1) {
         if (iHigh(Symbol(),0, kolvo_barov)> start_price + 0.01) {
            FileWrite( handle,"+100");
            start_price = start_price + 0.01;
         }      
         if (iHigh(Symbol(),0, kolvo_barov)< start_price + 0.01) {
            FileWrite( handle,"-100");
            start_price = start_price - 0.01;
         }      kolvo_barov--;
      }
      FileClose( handle);
   }
   return(0);
}
//+------------------------------------------------------------------+
Check it out. Only I didn't check it. There might be errors.
 

Good people. I don't understand (see picture) why Momentum is not Momentum :).


Momentum

Can you please explain why it is above zero?
 
rid писал(а) >>

Here's what I've done. I took another function from I. Kim and changed it a bit.

It works like clockwork:

The START function can be put in for control.


And here is the function itself:

Yes, it works! Thank you very much ! Thank you! >> Good luck to you!

 
warlock писал(а) >>

Help!!! the expert is supposed to open trades at the opening of a new candle, but in addition to opening at the beginning of the candle, he opens "left" ones chaotically...

Plus, after assigning High and Low, it stopped buying... but only sells...

And it was hard to check OrderSend() carefully. One fails by mistake, the other fails.

if ( AllowBUY) 
   tick=OrderSend(Symbol(),OP_SELLSTOP, Lot, price1,3,( price1- SL*Point)* loss,( price1- TP*Point)* profit,"scriptSELLstop",CLR_NONE, expiration);
if ( AllowSELL) 
   tick=OrderSend(Symbol(),OP_SELLSTOP, Lot, price2,3,( price2+ SL*Point)* loss,( price2- TP*Point)* profit,"scriptSELLstop",CLR_NONE, expiration);
 
warlock >> :

Help!!! the expert is supposed to open trades at the opening of a new candle, but in addition to opening at the beginning of the candle, it also opens "left" ones chaotically...

Plus after assigning High and Low, stopped buying... only selling...

Thanks... sat for an hour... I couldn't figure out what was going on... Sometimes you need someone to open your eyes to mistakes...

 
Hello people, can anyone help write an AC indicator advisor?
Reason: