[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 140

 
valeryk:

bool NewBar()
{static datetime newbar;
bool res=false;
if(newbar==0)newbar=Time[0];
if(newbar!=Time[0]){res=true;newbar=Time[0];}
return(res);
}

New bar presence .

I understood that the symbol is put at open price of the bar. And I need it to be at closing price.
I never managed to insert your code because I'm not a programmer. It especially frowns upon this bool NewBar()
 
supernyb:
I understand that the icon is set at the open price of the bar. I need it to be at the closing price.
I failed to insert your code because I'm not a programmer. It especially frowns upon this bool NewBar()
Note the time of quotation and time of bar setting: 15 minutes. Do you think Close[0] may change during this time?
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(NevBar()) 
     {
     //в этом блоке размещайте ваш код
     }    
//----
   return(0);
  }
//-----------------------------------------------------------------------------+
// Функция контроля нового бара                                                |
//-----------------------------------------------------------------------------+
bool NevBar(){
   static int PrevTime=0;
   if (PrevTime==Time[0]) return(false);
   PrevTime=Time[0];
   return(true);} 
 

One more time, please. Hello, I took the script from S. Kovalev's tutorial as the basis. I want to make an Expert Advisor to open a trade, put a stop loss, take profit, and then wait for the trade to close (i.e. the stop loss or profit), and only then reopen the trade. I tried with cycle and cycle interruptions. Please advise how to do this. I thought it may be easier not to set stop-loss and take-profit at once, and for the price to close when it approaches a certain level. But I don't want to do it that way because I'm afraid of slippage, and every point is important to me. I have understood that I opened one deal or sometimes a couple at once (is it wrong as well?) but I cannot open new deals after the deal is closed. Or advise how to prescribe, so that the program was waiting for performance stop-loss or tekaprofit, and ONLY then went on?

//+------------------------------------------------------------------+
int start() //---- function start
{
double //---- declare variables
x,
y;
//+------------------------------------------------------------------+
OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-15*Point,Ask+15*Point); //---- market order to buy and put a stop and profit 15 points from the opening price
//+------------------------------------------------------------------+
while(x!=Ask-15*Point||y!=Ask+15*Point) //---- of the condition I want the trade to be closed until the previous trade is closed, i.e.е. it is possible to
{//----- keep ONLY one trade open
continue;//---- interrupt the condition and go to the next step
}
//+------------------------------------------------------------------+
return;//---- function return
}
//+------------------------------------------------------------------+

 

If you don't care whether you have a stop or a take, why not just check if there are open orders or not?

if(OrdersTotal()< 1)

 

Can you tell me what can be done in this situation? I have an indicator. I have to draw a vertical line in the chart, then call properties, copy the number and then enter it in the indicator.

It would be good if the indicator will be placed where you click with your mouse.

Or, at least, it would be possible to move it with the mouse on the chart.


Files:
indicator.mq4  3 kb
 
Begemot7:

One more time, please. Hello, I took the script from S. Kovalev's tutorial as the basis. I want to make an Expert Advisor to open a trade, put a stop loss, take profit, and then wait for the trade to close (i.e. the stop loss or profit), and only then reopen the trade. I tried with cycle and cycle interruptions. Please advise how to do this. I thought it may be easier not to set stop-loss and take-profit at once, and for the price to close when it approaches a certain level. But I don't want to do it that way because I'm afraid of slippage, and every point is important to me. I have understood that I opened one deal or sometimes a couple at once (is it wrong as well?) but I cannot open new deals after the deal is closed. Or advise how to prescribe, so that the program was waiting for performance stop-loss or tekaprofit, and ONLY then went further?

int ticket=-1;
int start()       //---- функеция старт            
  {
  double     //---- объявляю переменные 
  x,
  y;
  bool sel;
  //+------------------------------------------------------------------+
  sel=false;
  if(ticket>=0)
   {
    sel=OrderSelect(ticket,SELECT_BY_TICKET);if(!sel) ticket=-1;
   }
  if(ticket<0 || (sel && ticket>=0 && OrderCloseTime()>0)) ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-15*Point,Ask+15*Point);
   return;                                                          //---- функция return 
    }

Or better like this (in case of restarting the Expert Advisor):

int ticket=-1;
int init()
 {
  if(GlobalVariableCheck("TICKET")) ticket=GlobalVariableGet("TICKET");
  else ticket=-1;
 }
int start()          
 {
  bool sel;
  sel=false;
  if(ticket>0)
   {
    sel=OrderSelect(ticket,SELECT_BY_TICKET);if(!sel) ticket=-1;
   }
  if(ticket<=0 || (sel && ticket>0 && OrderCloseTime()>0))
   {
    ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-15*Point,Ask+15*Point);
    if(ticket>0) GlobalVariableSet("TICKET",ticket);
   }
   return; 
  }
 
r772ra:
Note the quote time, and the time the icon was set, 15 minutes, do you think Close[0] can change during this time


Thank you this is just what I needed! I have done as you have said and everything has worked! I have also put Close[1] instead of Close[0] in Star Price and it has turned out that my mark has been drawn at closing prices. It does not wait for one bar like I thought it would.
 
001:

I would like the indicator to be placed where you click with the mouse.

To get the coordinates of the point, where the indicator was thrown, you can use functions:

WindowXOnDropped()

WindowYOnDropped()

Price and time:

WindowPriceOnDropped()

WindowTimeOnDropped()

 
valeryk:

bool NewBar()
{static datetime newbar;
The bool res=false;
if(newbar==0)newbar=Time[0];
if(newbar!=Time[0]){res=true;newbar=Time[0];}
return(res);
}

Availability of a new bar .


Here's what the guru said about your code!

In your version, the static datetime newbar is not initialised with zero , and this is incorrect.

 
Sepulca:

Better like this (in case the EA is restarted):

IMHO - better to search for your order and see if it is in the market or closed, and how it closed, by take, stop or manually. From here we will start dancing in different directions.

Then everything will be accurate. And global variables can be lost...

Reason: