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

 
please advise why transactions do not open.... The code seems to make sense, but it just won't open.
 
//+------------------------------------------------------------------+ 
  //| MACD ^^^.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 TP = 100; 
  extern int TS = 100; 
  extern int TF = 1; 
  extern double lots = 0.1; 
  int fast_ema = 5; 
  int slow_ema = 34; 
  int signal_period = 5; 
  int slip = 3; 
  int Magic = 1; 

 int total; 
 int ticket; //объявил тотал и тикет 

 //+------------------------------------------------------------------+ 
  //| expert initialization function | 
  //+------------------------------------------------------------------+ 
  int init() 
    { 
  //---- 

 //---- 
     return(0); 
    } 
  //+------------------------------------------------------------------+ 
  //| expert deinitialization function | 
  //+------------------------------------------------------------------+ 
  int deinit() 
    { 
  //---- 

 //---- 
     return(0); 
    } 
  //+------------------------------------------------------------------+ 
  //| expert start function | 
  //+------------------------------------------------------------------+ 
  int start() 
    { 
  //---- 
  
 CheckTicket();
 bool signal = signal_MACD(); 
 AnalyzeSignal(signal); 

 //---- 
     return(0); 
    } 
  //+------------------------------------------------------------------+ 

 bool signal_MACD() 
  { 
    bool signal_MACD = false; 
    double tmp = iMACD(Symbol(),TF,fast_ema,slow_ema,signal_period,PRICE_CLOSE,MODE_MAIN,0); 
    for(int i=1;i<=5;i++) 
    { 
       if(NormalizeDouble(iMACD(Symbol(),TF,fast_ema,slow_ema,signal_period,PRICE_CLOSE,MODE_MAIN,0)*tmp,4)<0.0) 
       { 
          signal_MACD = true; 
          break; 
       } 
    } 
  } 

 void AnalyzeSignal(bool signal) 
  { 
    double MACD = iMACD(Symbol(),TF,fast_ema,slow_ema,signal_period,PRICE_CLOSE,MODE_MAIN,0);
    total = OrdersTotal();
    if(total < 0)
    {
      if(signal == true)
      {
         if(MACD > 0)
         {
                ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slip,Bid-TS*Point,Bid+TP*Point,"покупаем",Magic,0,Green); 
                if(ticket>0) 
                { 
                    OrderSelect(ticket,SELECT_BY_TICKET); 
                    Print("открылись на покупку по цене:", OrderOpenPrice()); 
                } 
                else 
                { 
                    Print("открыться не удалось по причине:", GetLastError()); 
                    return(0); 
                } 
         }
         if(MACD < 0)
         {
               ticket = OrderSend(Symbol(),OP_SELL,lots,Bid,slip,Ask+TS*Point,Ask-TP*Point,"Продаем",Magic,0,Green); 
               if(ticket>0) 
               { 
                   OrderSelect(ticket,SELECT_BY_TICKET); 
                   Print("открылись на продажу по цене:", OrderOpenPrice()); 
               } 
               else 
               { 
                   Print("открыться не удалось по причине:", GetLastError()); 
                   return(0); 
               } 
         }
         else
            return(0);
      }
    }
  }
  
void CheckTicket()
{
   if(OrderSelect(ticket,SELECT_BY_TICKET))
   {
      if(OrderCloseTime()>0)
      {
         ticket = 0;
      }
   }   
}
 

This is a point I can't put together, help me create:

I need to define a profit point zero for two or more orders opened in one direction, e.g. buy.

and add take profit to this point and assign it to all open buy orders.

And take profit should be shown on the chart, i.e. it should be visible.

For example, at the price of 1500 we open the first Buy order

at 1600 we open the second buy order.

their zero point is at 1550 + (Take Profit = 20)

and here the first and the second order are given a take profit of 1570, when the price reaches this level, both orders will be closed,

and if the price passes (jumps) this level, it will follow and close the orders.

It is very important to keep records of buy and sell orders simultaneously and not to interfere with each other. You should set take profit separately for buy and take profit separately for sell, and only when two or more orders are opened in one direction at the same time.

 
CLAIN:
please advise why transactions do not open.... The code seems to make sense, but it just won't open.
Because OrdesTotal() never returns a negative value.
 
Thanks, good point.... corrected... but the trades still won't open.... what to do?
 
CLAIN:
Thanks, good point.... corrected... but the trades still won't open.... what to do?


Probably correct the signal_MACD() function.

Well, that she'd still be giving something back.

 

Hello.

Can you please tell me if I have written the conditions correctly? ( Fractal_point_up_buy and Fractal_point_down_buy parameters are normalized.)

Thank you in advance.

      Fractal_point_up_buy=TF1B;
      Flow_differential_buy=Fractal_point_up_buy-Bid;
      if (timf1s>timf2b && timf2s>timf2b && timf3s>timf2b && timf3s<timf1b)
       {
        Fractal_point_down_buy=TF3S;   
       }
      else
       {
        if (timf1s>timf2b && timf2s>timf2b && timf3s<timf2b && timf2s<timf1b)
         {
          Fractal_point_down_buy=TF2S;   
         }
        else
         {
          if (timf1s>timf2b && timf2s<timf2b && timf3s<timf2b && timf1s<timf1b)
          Fractal_point_down_buy=TF1S; 
         }     
       }
      Fractal_fibo_buy=100*Flow_differential_buy/(Fractal_point_up_buy-Fractal_point_down_buy);
 
belck:

This is a point I can't put together, help me create:

I need to define a profit point zero for two or more orders opened in one direction, e.g. buy.

and add take profit to this point and assign it to all open buy orders.

And take profit should be shown on the chart, i.e. it should be visible.

For example, at the price of 1500 we open the first Buy order

at 1600 we open the second buy order.

their zero point is at 1550 + (Take Profit = 20)

and here the first and the second order are given a take profit of 1570, when the price reaches this level, both orders will be closed,

and if the price passes (jumps) this level, it will follow and close the orders.

It is very important to keep records of buy and sell orders simultaneously and not to interfere with each other. You should set take profit separately for buy and take profit separately for sell, and only when two or more orders are opened in one direction at the same time.


For a position open at 1500, a Take at 1570 would be fine (if you don't take StopLevel into account), but for a position open at 1600, a Take at 1570 would cause an Error 130 - wrong stops. After all, a Take cannot be lower than the opening price for a Buy. This is already a StopLoss.
For two positions you have defined your breakeven point, but for three-four-five?
You should first define the breakeven formula for unidirectional positions, and then you can create a logic.
 
nemo811:

Hello.

Can you please tell me if I have written the conditions correctly? (Fractal_point_up_buy and Fractal_point_down_buy parameters are normalized.)

Thank you in advance.

Hello.

If all variables are declared, I don't see errors in MQL4 syntax...

What's the problem?

 
,
artmedia70:
For a position open at 1500, a take at 1570 would be fine (if you don't take StopLevel into account), but for a position open at 1600, a take at 1570 would cause a 130 error - wrong stops. After all, a Take cannot be lower than the opening price for a Buy. This is already a StopLoss.
For two positions you have defined your breakeven point, but for three-four-five?
You should first define the Breakeven formula for unidirectional positions, and then you can work out the logic.

It all depends on when we set or change Take Profit. It is based on the current price.
Reason: