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

 

Good afternoon, could you please tell me if there is a code


OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);//выбрать последний ордер
if (OrderType()==OP_BUY||OP_SELL)
 {
 if (OrderMagicNumber()==1)
  {
  if (OrderProfit()<0)

   {

which will select the last order in the history with a negative profit.

If there is a situation when 3 orders are closed at the same time, how do I know that the last 3 orders have closed at the same time?

i tried to do the for loop, but it finds all orders closed at a loss, while i need only the last order or the last order depending on how many of them closed at once

 
BruDer:

I did not find an answer in the search

how can i see from the script which indicators are on the chart, what parameters and indicators, in which subwindows they are located?

thanks


No way.
 

vik-777:

how do I know that the last 3 closed at the same time?

OrderCloseTime()
 
vik-777:

Good afternoon, could you please tell me if there is a code


which will select the last order in the history with a negative profit.

If there is a situation when 3 orders are closed at the same time, how do I know that the last 3 orders have closed at the same time?

i tried to do the for loop, but it finds all orders closed at a loss, while i need only the last order or the last order depending on how many of them closed at once




If it is the same, then you compare it with the time of closing of your previous closed order... like this, naturally, it's all in a loop - from the last closed to the first, you go one after another and compare the time of orders closure... Another thing - print the closing time of the last orders you know beforehand, let's say three orders , it may be different, even if you understand it as " simultaneously", i.e. as I understand it, the order closes at any time, i.e. Actually, the time of closing of, say, three orders at once cannot be the same - try to print () and see the values of your three TIME orders - their values of OrderCloseTime() characteristics, i.e., we may have to introduce the concept of TIME of closing, i.e., deviation of closing time of several orders by some small value when we may consider that they have closed simultaneously. Experiment and see for yourselves from here.
 

Taking help from the hall.

How to write a condition in OrderSelect():

if(order opening day != today's day)ticket=OrderTicket();

 
if(TimeDay(OrderOpenTime())!=TimeDay(CurrentTime()))ticket=OrderTicket();
 
ikatsko:

HOW WOULD YOU COUNT THE NUMBER OF PROFITABLE LONG POSITIONS AND THE NUMBER OF PROFITABLE SHORT POSITIONS SEPARATELY?

The strategy is as follows: if the number of profitable long positions since the start of the Expert Advisor (or better - for the entire account history) is greater than the number of short positions, then only long positions should be allowed to be opened. And vice versa.

It is clear how to count these deals, if they are closed by the Expert Advisor: Close - Count. But if a position is closed by TP or SL, then ... ?

Maybe someone has a ready code of the function?

Well, compare in a loop over closed positions their close price and their take and stop prices:

OrderTakeProfit(); OrderStopLoss(); OrderClosePrice();

And it is even easier to select OP_BUY and OP_SELL and write in four separate variables the number of losing and profitable Buy and Sell positions

if (OrderProfit()+OrderSwap()+OrderCommission()>0) { /* position is profitable */ }
else { /* position is losing */ }

 
Thank you!
 

I've looked at everything..., I've done everything... It won't open a position, that's all! It closes properly, but it doesn't open... I don't know what to do! Maybe someone will find a bug in the program?

 
//+------------------------------------------------------------------+
//|                                                     DOKTRADE.mq4 |
//|                                                DOKSTER@YANDEX.RU |
//|                                                DOKSTER@YANDEX.RU |
//+------------------------------------------------------------------+
#property copyright "DOKSTER@YANDEX.RU"
#property link      "DOKSTER@YANDEX.RU"

   extern double LOT = 0.01;   // LOTS
   extern double KOF = 2;
   extern double SAF = 5;
   extern int    FRC = 144;
   extern double STL = 100;
   extern double TPF = 100;
   
   int start()
     
    { 


int CNT;

int DIG;

int TOTAL;
int SPREAD;

double SPR;
double SPRW;

double FRCU;
double FRCD;

double EMAH;
double EMAM;
double EMAL;

double OPEN;
double CLOSE;

double DFB;
double DFS;

double STLW = STL*Point;
double TPFW = TPF*Point;

double SAFW = SAF*Point;

EMAH = iMA(NULL,0,34,8,MODE_SMA,PRICE_HIGH,1);
EMAM = iMA(NULL,0,34,8,MODE_SMA,PRICE_MEDIAN,1);
EMAL = iMA(NULL,0,34,8,MODE_SMA,PRICE_LOW,1);

OPEN = iOpen(NULL,0,1);
CLOSE = iClose(NULL,0,1);

FRCU = High[iHighest(NULL,0,MODE_HIGH,FRC,1)];
FRCD = Low[iLowest(NULL,0,MODE_LOW,FRC,1)];

DFB = (CLOSE-FRCD);
DFS = (FRCU-CLOSE);

SPR = MarketInfo(Symbol(),MODE_SPREAD);
SPRW = (SPR*Point);

DIG = MarketInfo(Symbol(),MODE_DIGITS);

TOTAL = OrdersTotal();


if(TOTAL<1)

 { if (OPEN<EMAH&&CLOSE>EMAH)
   
   OrderSend(Symbol(),OP_BUY,LOT,Ask,3,0,0,"DOKTRADE",15775,0,Green);
  
 
   if (OPEN>EMAL&&CLOSE<EMAL)
 
   OrderSend(Symbol(),OP_SELL,LOT,Bid,3,0,0,"DOKTRADE",15885,0,Red);
  
  return(0);
 
    }
    
           
      
  for(CNT=0;CNT<TOTAL;CNT++)    
  
  {
      
  OrderSelect(CNT,SELECT_BY_POS,MODE_TRADES);
  
  {
  
  if (OrderType()==OP_BUY && OrderSymbol()==Symbol())   
                                             
      {
      
       if (OPEN>EMAL&&CLOSE<EMAL)    
     
        OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
        
         if (OPEN>EMAM&&CLOSE>EMAM)
          
           OrderModify(OrderTicket(),OrderOpenPrice(),FRCD-SAFW,CLOSE+DFB,Green);
        
        return(0);
        
        }
        
  if (OrderType()==OP_SELL && OrderSymbol()==Symbol())
        
      {
       
         if (OPEN<EMAH&&CLOSE>EMAH)
         
         OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue);
         
          if (OPEN<EMAM&&CLOSE<EMAM)
           
           OrderModify(OrderTicket(),OrderOpenPrice(),FRCU+(SAFW+SPRW),CLOSE-DFS,Red);
       
         return(0);
         
         }
          }
           }
            }