What's wrong with that? - page 4

 
sss2019:
What else is it going to be?

and this you will check for yourself and you will know.
 
sergeev:

and this you will check for yourself and you will know.
Why are you just handing him over like that, you didn't even ask his last name. It's a joker, you don't even have to open a warrant, just peck silently in your pocket.
 
A scrapple, though! That's it, yeah, yeah.
 

Why doesn't this order open, what is the error?

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

extern int MaFastPeriod = 30;
extern int MaSlowPeriod = 90;
extern int StopLoss = 25;
extern int TakeProfit = 50;

int init()
  {

  }



int deinit()
  {

  }



int start()
  {
double MaFast = iMA(Symbol(),0,MaFastPeriod,0,MODE_EMA,PRICE_CLOSE,0);
double MaSlow = iMA(Symbol(),0,MaSlowPeriod,0,MODE_EMA,PRICE_CLOSE,0);
   
   if(OrdersTotal() == 0 && MaFast > MaSlow)
   {
   OrderSend(Symbol(),0,0.1,Ask,3,Ask+TakeProfit*Point,Ask-StopLoss*Point,"CommentA",0,0,Green);
   }else
   {
      if(GetLastError() != 0)
         {
         Alert("Ошибка", GetLastError());
         }
   }
   
   return(0);
  }
 
How can I implement opening a deal only on the signal bar?

For example, one moving average has crossed another one, one trade opens, but if you close this trade, another one will open, even after several bars from the signal bar.
 
sss2019:
How to open a deal only on the signal bar?

For example, one moving average has crossed another one, one trade opens, but if you close this trade, another one will open, even after several bars from the signal bar.
You are definitely banned from google, and from our FAQ too.
First of all, HOW do you get the signal of crossover of two MAs?

Then google something like open only one order site:mql4.com
 

Yes, I know how to open one order, but the problem is that if you open one order and it closes after a couple of hours and all conditions for opening are still intact, then another order is opened, even if you have already gone far from the signal bar.

I will have a look at your link, thanks.

 
sss2019:

Yes, I know how to open one order, but the problem is that if you open one order and it closes after a couple of hours and all conditions for opening are still intact, another order is opened, even if you have already gone far from the signal bar.

I will look at your link, thank you.


We set a flag to allow orders to be opened. A signal comes in and the flag allows. We open the position and immediately remove the flag. The pose is closed after some time. The Expert Advisor sees that there is a signal, but the flag is removed (it is forbidden to place orders) - as a result, the order is not set.

Next. If there is no signal, we set a flag (allow opening of positions). Or, as soon as there is a new signal, we set a flag. But in the second case, the Expert Advisor should be able to distinguish a new signal from the old one.

 

drknn:



Set a flag to allow the opening of orders. A signal comes in and the flag allows. We open the position and immediately remove the flag. The pose is closed after some time. The Expert Advisor sees that there is a signal but the flag has been removed (it is forbidden to set orders) and, as a result, no order is set.

Next. If there is no signal, we set the flag (allow opening positions). Or, as soon as there is a new signal, we set the flag. But in the second case, the Expert Advisor should be able to distinguish a new signal from the old one.


Thanks a lot, I think this way is more universal.

By the way, how can we announce in our EA that the order has been opened? Maybe this can be implemented by using OrderSelect?

 

Well please take a look at something I've messed up there and now the order won't open.

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

extern int MaFastPeriod = 30;
extern int MaSlowPeriod = 90;
extern int StopLoss = 25;
extern int TakeProfit = 50;

int init()
  {

  }



int deinit()
  {

  }



int start()
  {
  double MyPoint = Point;
   if(Digits == 3 || Digits == 5)
      {
      MyPoint = Point * 10;
      }
      
double MaFast = iMA(Symbol(),0,MaFastPeriod,0,MODE_EMA,PRICE_CLOSE,0);
double MaSlow = iMA(Symbol(),0,MaSlowPeriod,0,MODE_EMA,PRICE_CLOSE,0);

   for(int SelectedOrder = 0; SelectedOrder < OrdersTotal(); SelectedOrder++)
      {
         bool Flag = false;
         if(OrderSelect(SelectedOrder,SELECT_BY_POS,MODE_TRADES)==True)
            {
            Flag = false;
            }
      }
   return(Flag);
   
   if(OrdersTotal() == 0 && MaFast > MaSlow && Flag == false)
      {
      OrderSend(Symbol(),0,0.1,Ask,30,Ask-StopLoss*MyPoint,Ask+TakeProfit*MyPoint,"CommentA",0,0,Green);
      }
   
   return(0);
  }
Reason: