Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 328

 
Trader7777:

is this correct? Will this function return the price of the last upper fractal?


Example of a fractal search
 
double GetLastUpperFractalPrice()
{
for (int i = 3; i<=Bars; i++)
{
if (iFractals(Symbol(),PERIOD_M5,MODE_UPPER,i) != 0) return (i);
{
double LastUpperFractalPrice = High [i];
}
}
return (LastUpperFractalPrice);

}

Will this work or not?

 
Trader7777:
double GetLastUpperFractalPrice()
{
for (int i = 3; i<=Bars; i++)
{
if (iFractals(Symbol(),PERIOD_M5,MODE_UPPER,i) != 0)
{
double LastUpperFractalPrice = High [i];
}
}
return (LastUpperFractalPrice;)

}

Will this work or not?


So, for example, it will:

double GetLastUpperFractalPrice()
{
   for (int i = 3; i<=Bars; i++)
   {
      if (iFractals(Symbol(),PERIOD_M5,MODE_UPPER,i) != 0)
      {
         return(High [i]);
      }
   }
   return(EMPTY_VALUE);
}

As you have it, it won't.

 
Trader7777:
double GetLastUpperFractalPrice()
{
for (int i = 3; i<=Bars; i++)
{
if (iFractals(Symbol(),PERIOD_M5,MODE_UPPER,i) != 0) return (i);
{
double LastUpperFractalPrice = High [i];
}
}
return (LastUpperFractalPrice);

}

Will it work or not?


No. Insert the code through the SRC in the panel.

return (ХХХ) will return from the user function - what was entered there will be returned by this function - the value of ХХХ or a result of some calculations functions.

So, when a fractal is found, write return (High [i]) - you don't have to invent anything else.

Well ahead of you))

 

This is an elementary function of placing pending orders, the parameters are not important, but it is important to make the Expert Advisor (it can use the existing loop of pending orders) after receiving a "new price" or to search for it, or to somehow avoid placing orders at the same price. In this case, the loop of placing orders should not stop.

double Dist=10000.0;
string SMB;
double NewPrice;
int i;
int start()
{
RefreshRates();
SMB=Symbol();
{UstanOtlozh();}
}
return(0);
void UstanOtlozh()
{
double OldPrice=WindowPriceOnDropped(); // Here the script is thrown
RefreshRates();
SMB=Symbol();
{
int i=1;
while(i<=OrdersTotal())
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // if there is a
{ // Order analysis:
if (OrderSymbol()!= SMB) continue; // Not our financial instrument.
int Tip=OrderType(); // Order type
if (Tip<2) continue; // Market order
double NewPrice=OrderOpenPrice(); // Order price
{
while(NewPrice<=Ask+200*Point||NewPrice>=Ask+50*Point)
{
NewPrice=NewPrice+50*Point;
OrderSend(SMB,OP_BUYSTOP,0.01,NewPrice,3,0,0,NULL,0,CLR_NONE);
if(NewPrice>Ask+200*Point||NewPrice<Ask+50*Point)
break;
}}}}}}

 
ALXIMIKS:
I have fixed it to compile - and use 555 build of MT4 EDITOR - it really helps to find problems quickly. just read the manual before installing - the first 15 pages.

I never thought I'd be asking about such a simple thing. When compiling, I get a message that the BU() function is not involved. I put it this way (code is given) now everything compiles, but breakeven function does not work. I have seen the same Breakeven function in other EAs.

int start()
  {
   if(Volume[0]>1) return; 
  
   if (CountTrades()==0 && Open[1]>Close[1] && Open[2]<Close[2] && High[1]>High[2] && Low[1]<Low[2])  // продажа
   {
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"Pattern_1",111,0,Red);
      if (OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES))
      {
         TP=NormalizeDouble(Bid - TakeProfit * Point, Digits);
         OrderModify(ticket, OrderOpenPrice(),0,TP,0);
      }
   }
   else
   if (CountTrades()==0 && Open[1]<Close[1] && Open[2]>Close[2] && High[1]>High[2] && Low[1]<Low[2]) // покупка
    {
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"Pattern_1",111,0,Blue);   
      if (OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES))
      {
         TP=NormalizeDouble(Ask + TakeProfit * Point, Digits);
         OrderModify(ticket, OrderOpenPrice(),0,TP,0);
      }
    }
   if (CountTrades()>0)
      {
      otype = FindLastOrderType();
      if (otype == OP_BUY)
         { // ценапоследнего ордера на покупку
         price = FindLastBayPrice();
         
         if ((Bid - price) / Point >= Step)
            {
               ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid,Slippage,0,0,"Pattern_1",111,0,Red);  
            }
         }
      else if (otype == OP_SELL)
         { // цена последнего ордера на продажу
         price = FindLastSellPrice();
         
          if ((price - Ask) / Point >= Step)
            {
               ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask,Slippage,0,0,"Pattern_1",111,0,Blue);  
            }
         }
      }
    BU();  
    return(0);
  }
 
alexey1979621:

I never thought I'd be asking about such a simple thing. When compiling, I get a message that the BU() function is not involved. I put it this way (code is given) now everything compiles, but breakeven function does not work. In other EAs exactly the same breakeven function works.




The only reason is incorrect if(...) operator return; It seems you have only one - at the beginning of the program.
 

Gentlemen!!! What are you people confused about?

iFractals() returns the price, not the bar number of the fractal.

 
tara:

The only reason is an incorrect if(...) operator return; It seems you have one - at the beginning of the program.
This one has been removed. But the problem lies elsewhere - in the normalization. For some reason, my Expert Advisor has read 4 decimal places, and not 5.
extern double  Lots             = 0.1;
extern string Сomment           = "Pattern_1";
extern int TakeProfit           = 10;     
extern int StopLoss             = 0;   
extern int Step                 = 2;   

extern int BULevel              = 2;
extern int   NotBULevel         = 2;         // Уровень безубытка в пунктах

extern int Slippage             = 2; // проскальзывание 
extern int Magic                = 111;



//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
      if (Digits ==5) // для пятизначного брокера
         {
            TakeProfit *= 10;
            StopLoss *= 10;
            Slippage *= 10;
            Step *= 10;
            BULevel *= 10;
            NotBULevel *= 10;
         }
      return(0);
}
How to fix it?
 
alexey1979621:
This has been removed. But the problem lies elsewhere - in normalisation. For some reason the EA sees 4 decimal places instead of 5. How do I fix it?


How many digits does the broker have?
Reason: