[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 317

 
enya:

.

in inserted. problems with the cycle and restoring initial values after exiting the cycle

Here's the function that will answer whether the last trade was profitable or unprofitable:

 double LastOrderProfit()
 {
   double Profit=0;
   int ticket; 
   for(int i=0; i<OrdersHistoryTotal(); i++){
     if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))continue;
      if(OrderSymbol()!=Symbol())continue;
     if(OrderMagicNumber()!=Magic)continue;
     if(OrderType()>1)continue;
     if(ticket<OrderTicket()){
        ticket=OrderTicket();
        Profit=OrderProfit()+OrderSwap()+OrderCommission();
     } 
   }     
 return(Profit);
 } 

Then, by comparing its answer to zero, you decide whether to leave TP/SL the same or change them.

 if(LastOrderProfit()>0) newTPSL=false; else  newTPSL=true;
if(newTPSL)OrderModify(.......newSL,newTP...);
 

Hi all. I am interested in the IN10TION NewsReader indicator. I want to attach it to my EA.

If a red line appears (Market.TdOpen) and Market.Price.DOWN(red) then sell

If a red line appears (Market.TdOpen) and Market.Price.UP(green) then buy

What actions can I take? I have tried iCustom but it does not work!


extern bool Market.TdOpen = TRUE;
extern color Market.TdOpen.Color = Red;
extern bool Market.TdFibo = TRUE;
extern color Market.TdFibo.Color = C'0x00,0x32,0x00';
extern color Market.Price.UP = Lime;
extern color Market.Price.DOWN = Red;
extern bool Market.Price.Guide = TRUE;

Attached files:
_yIN10TIONfNewsReaderov09.99kblite.ex4 (115.59 KB) delete

 

Apologies to the admins for repeating myself, but no one has said half a word to me yet. The idea is to output messages stored in logs, i.e. those which cannot be fixed correctly by IsConnected() function - connection failures, reqests. Otherwise it is not clear why the EA is not doing anything at the moment.


Please suggest the code below to read the log file. Automatically reads the current log file by date and outputs it to the printer.

Where:

while (result>0) {

A file is being assembled from parts. But I don't need the whole file, just the last line. Help to correct it, please.

void ReadWrite() {
   string tekTime=TimeStr1(CurTime(),1);
   string path=TerminalPath()+"\\logs\\"+tekTime+".log";
   string title="Чтение из файла";
   string msg;
   int result;
   int handle=_lopen(path,4);
   if (handle<0) {
      msg="Ошибка открытия файла";
      Print(msg);
      return;
   }
   result=_llseek (handle,0,0);
   string buffer="";
   //string char="x                      ";
   string char="x                                                                                                                                                                                                                                                         ";
   int count=0;
   result=_lread (handle,char,250);
   while (result>0) {
      buffer=buffer+char;
      char="x                                                                                                                                                                                                                                                         ";
      count++;
      result=_lread (handle,char,250);
   }
   result=_lclose (handle);
   msg=StringTrimRight(buffer);
   Print(msg);
}

//------------------расчет времени----------------
string TimeStr1(int taim,int tip)
{
   string sTaim;
   string sTaim1,sTaim2,sTaim3;
   if (tip==1) 
   {
      int GD=TimeYear(taim);                  
      int MN=TimeMonth(taim);                  
      int DD=TimeDay(taim);  
      
      sTaim1 = DoubleToStr(GD,0);
      if (MN<10) sTaim2 = StringConcatenate(sTaim2,"0"+DoubleToStr(MN,0));
      else sTaim2 = StringConcatenate(sTaim2,DoubleToStr(MN,0));
      if (DD<10) sTaim3 = StringConcatenate("0",DoubleToStr(DD,0));
      else sTaim3 = DoubleToStr(DD,0);
      sTaim=sTaim1+sTaim2+sTaim3;
   }
   return(sTaim);
}
 

Need help changing an EA

The Expert Advisor should trade on the reverse.

Instead of sell limit orders buy

and buy limit orders sell

Files:
tke.mq4  18 kb
 
mersi:

Here is the function that will answer whether the last trade was profitable or unprofitable:

Then, by comparing its answer to zero, you decide whether to leave TP/SL the same or change them.

Is your function sure to return the last order? Or will it return the first order which was not losing? Why is there a check on the ticket?

I would do it this way:

//+----------------------------------------------------------------------------+
double LastOrderProfit() {
   double Profit=0;
   datetime t;
   int i, j;
   for (i=0; i<OrdersHistoryTotal(); i++) {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      if (OrderMagicNumber()!=Magic)                  continue;
      if (OrderSymbol()!=Symbol())                    continue;
      if (OrderType()>1)                              continue;
      if (t<OrderCloseTime()) {
         t=OrderCloseTime();
         j=i;
         }
      }
   if (OrderSelect(j,SELECT_BY_POS,MODE_HISTORY)
      Profit=OrderProfit()+OrderSwap()+OrderCommission();
   return(Profit);
} 
//+----------------------------------------------------------------------------+

This is a redesign of your function to find exactly the last closed order.

It has the disadvantage that if there were no orders closed at all, it will return zero. Thus, using it, it is impossible to know for sure if there are or are not any closed orders in the history. After all, the returned zero does not indicate that there is no order at all, but that it is closed at zero.

 

Please advise:

is interested in rendering of indicator value only for last (current) bar. However, when opening a new bar, the old values remain on the chart.... How can I forcefully remove this rubbish? Is it possible to specify the condition that for the bar [0] the indicator values are calculated and shown, and for the bars from [1] to [Bar-1] these values are reset?

double Buffer [1];            

int init()
  {

   IndicatorBuffers(1);
  
   SetIndexStyle(0,DRAW_ARROW);
   .........
 
   return(0);
  }

int deinit()
  {
   return(0);
  }

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) counted_bars=0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
       for(int i=limit;i>=0;i--) 
     {
         Buffer [0] = ............;
     }
   return(0);
  }        
 

artmedia70:

It has the disadvantage that if no orders have been closed at all, it will return zero. Thus, using it, it is impossible to know for sure if there are or there are no closed orders in the history. After all, the null returned does not mean that there is no order at all, but it shows that it was closed at zero.

Thank you! Although you didn't reply to me, you answered my previous question about the correct calculation of profit:

Profit=OrderProfit()+OrderSwap()+OrderCommission();
 
Azerus:

Please advise:

is interested in rendering of indicator value only for last (current) bar. However, when opening a new bar, the old values remain on the chart.... How can I forcefully remove this rubbish? Is it possible to specify the condition that for the bar [0] the indicator values are calculated and shown, and for the bars from [1] to [Bar-1] these values are reset?

At the start of Start(), initialise the buffer with the value EMPTY_VALUE. That is, do it with the appearance of a new bar, check the open time of the zero bar and do your garbage-clearing logic.

 
artmedia70:

Is your function sure to return the last order? Or the first one encountered is not unprofitable? Why is there a check on the ticket?

I would do it this way:

This is a conversion of your function to find exactly the last closed order.

It has a disadvantage - if there were no closed orders at all, it will return zero. Thus, when using it, we cannot know for sure if there are any closed orders or not in the history. The null returned does not indicate the absence of the order at all, but it does indicate that it was closed at zero.

1. The function finds the order with the largest ticker in the history, which means the last closed order (unless, of course, we take some exceptional case, for which your variant with the maximum time of closing is preferable).

2. According to the conditions , the first order is opened with the specified TP/SL and only the second order may be opened with the new TP/SL, which means that the function can return zero only if the first trade was zero, but not if there are no closed orders in the history.

One last thing. In your variant the use of j and another SELECT in the function is redundant.

it is enough:

 if (t<OrderCloseTime()) {
         t=OrderCloseTime();
      Profit=OrderProfit()+OrderSwap()+OrderCommission();
  }
   return(Profit);
 
snail09:
At the beginning of Start() initialise the buffer with value EMPTY_VALUE.


How is this? I have this in the indicator line settings after int init()

   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,165);                     
   SetIndexBuffer(0,Buffer);
   SetIndexEmptyValue(0,0.0);
Reason: