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

 

Hello. Can you please tell me if there is an EA that would mark entry and exit points on the chart, like in the strategy tester?

 

And manually - what's wrong with that? Pull trades from the Account History with the mouse to the chart and they will be indicated there!

Or use the script - http://www.kimiv.ru/index.php?option=com_remository&Itemid=13&func=fileinfo&id=32

 
TheXpert >> :

ShellExecute, command "open", e.g.


Thank you
 
rid >> :

It should be placed on the outside. Not inside any function - but as a separate, independent function.

You can go like this:


I'm not sure if the EA will work under these conditions. Because the very first position will not be able to open...

The function isCloseLastPosByTake() should be removed from a Buy or Sell condition.

Then it works.

the code of an EA with corrections according to the recommendation of rid only the start

//+------------------------------------------------------------------+
//| 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( isCloseLastPosByTake( NULL, OP_SELL, MagicNumber) ==true) {
     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);
  }//+----------КОНЕЦ ФУНКЦИИ СТАРТ -------------------+

//ЖЖЖЖЖЖЖ Другие вызываемые пользовательские функции ЖЖЖЖЖЖ
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.05.2008                                                     |
//|  Описание : Возвращает флаг закрытия           |
//|  последней позиции по тейку.                                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
bool isCloseLastPosByTake(string sy="", int op=-1, int mn=-1) {
  datetime t;
  double   ocp, otp;
  int      dg, i, j=-1, k=OrdersHistoryTotal();

  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 ( t<OrderCloseTime()) {
                t=OrderCloseTime();
                j= i;
              }} }}}}}

  if (OrderSelect( j, SELECT_BY_POS, MODE_HISTORY)) {
    dg=MarketInfo( sy, MODE_DIGITS);
    if ( dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
    ocp=NormalizeDouble(OrderClosePrice(), dg);
    otp=NormalizeDouble(OrderTakeProfit(), dg);
    if ( ocp== otp) return( True);
  }
  return( False);
}
 

I got an error when I compiled it.

2;73;C:\Program Files\MetaTrader - Alpari\experts\SimpleMA22333.mq4;103:3;'}' - unbalanced parentheses

this place is marked * help the good people.....

   return(0);
 * }//+----------КОНЕЦ ФУНКЦИИ СТАРТ -------------------+
 
igrok2008 писал(а) >>

I got an error when I compiled it.

this place is marked * help the good people.....

The number of curly braces is different in the start function

//+------------------------------------------------------------------+
//| 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( isCloseLastPosByTake( NULL, OP_SELL, MagicNumber) ==true) {
            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( isCloseLastPosByTake( NULL, OP_BUY, MagicNumber) ==true) {
            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);
}//+----------КОНЕЦ ФУНКЦИИ СТАРТ -------------------+
Something like that must have happened. Didn't go into the logic
 
igrok2008 >> :

here is the code of Expert Advisor with corrections upon the recommendation of rid


Remove the extra curly bracket from the Salesbox. I told you that the number of opening brackets must be equal to the number of closing brackets. And you have two brackets open and three closed !

And of course there will be a compilation error.

 
rid >> :

Remove the extra curly bracket from the Salesbox. I told you that the number of opening brackets must be equal to the number of closing brackets. But you have two brackets open and three closed!

And of course there will be a compilation error.

And the opening parentheses are what????


aaaaaaaaahhhh,I got it,it's {.........-!!!!!!!!!!!!!!} :-)))))))

I'll be testing........ If anything, don't judge, I'll try to ask questions.

 
igrok2008 писал(а) >>

And the opening brackets are what????

aaaaaaaaaaaaand it's {.........-!!!!!!!!!!!!!! :-)))))))

I'll be testing......... If anything, don't blame me, I'll ask questions.

I thought I made a revision.

 

Such a fix will not work. It will not be able to open the very first trade. Because the condition for opening the very first trade in your variant is to close any previous trade at take or stop!

I.e. - a vicious circle.

Reason: