[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 3

 

oops :-)

thank you!

 

Hello connoisseurs!

Here's an EA. it opens a position on a fractal up/down. How do I make the stop 5 pips higher (if BUY) and 5 pips lower (if SELL) from the top of the fractal?

P_up0=iCustom(0,0,"Ценовой канал", Chperiod,0,0);
   P_down0=iCustom(0,0,"Ценовой канал", Chperiod,1,0);
   P_up1=iCustom(0,0,"Ценовой канал", Chperiod,0,1);
   P_down1=iCustom(0,0,"Ценовой канал", Chperiod,1,1);
   Up=iCustom(0,0,"olyakish_fractals_02(для Skonti)",15,150,"Процент для отсеивания по объему",110,1,3);
   Down=iCustom(0,0,"olyakish_fractals_02(для Skonti)",15,150,"Процент для отсеивания по объему",110,3,3);
//задали все данные 

   total=OrdersTotal();
   if( total<1) 
     {
      // Проверка свободной маржи
      if(AccountFreeMargin()<(1000* Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // Условие открытие позиции BUY
      if( Up> Down)
        {
         Lots= GetSizeLot();
         ticket=OrderSend(Symbol(),OP_BUY, Lots,Ask,3,0,0,"",16384,0,Green);
         if( ticket>0)
           {
            if(OrderSelect( ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // Условие открытие позиции SELL
      if( Up< Down)
        {
         Lots= GetSizeLot();
         ticket=OrderSend(Symbol(),OP_SELL, Lots,Bid,3,0,0,"",16384,0,Red);
         if( ticket>0)
           {
            if(OrderSelect( ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
    
   for( cnt=0; cnt< total; cnt++)
     {
      OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol())  
        {
         if(OrderType()==OP_BUY)   // длинная позиция открыта
           {
            // условие закрытие длинной позиции
            if( P_down1> P_down0|| Up< Down)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
                 return(0); 
                }
            if( TrailingStop>0)  
              {                  
               if(Bid-OrderOpenPrice()>Point* TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point* TrailingStop && OrderStopLoss()!=OrderOpenPrice()+ X*Point)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+ X*Point,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
            // условие закрытия короткой позиции
            if( P_up1< P_up0|| Up> Down)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); 
               return(0); 
              }
            if( TrailingStop>0)  
              {               
               if((OrderOpenPrice()-Ask)>(Point* TrailingStop))
                 {
                  if(NormalizeDouble(OrderStopLoss(),Digits) != NormalizeDouble(OrderOpenPrice()- X*Point,Digits))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()- X*Point,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }

I have used the Price Channel here.

// условие закрытия короткой позиции
            if( P_up1< P_up0|| Up> Down)
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); 
               return(0); 
              }
и
// условие закрытие длинной позиции
            if( P_down1> P_down0|| Up< Down)
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
                 return(0); 
                }

I'm having trouble identifying the L or H of the fractal at which the position was opened!

roughly like this!!!?

if (NormalizeDouble (MathAbs (High [ i]-5),Digits) < Price)
 
which instrument price is=5?
if (NormalizeDouble (MathAbs (High [ i]-5),Digits) < Price)

so multiply by the price of the lowermost digit

5*Point
 

This is where I made a mistake. Thanks.

On how to set the top of the fractal on which the position was opened????

 
All questions are resolved by experiment - write a script, run it,
- we see the following differences of the standard iFractals()
1. the indicator by the fractal index is exactly equal to High/Low
2. non-existing value of the fractal ==0
int i;
   double f;
   for( i=0; i<50; i++) { f=iFractals(NULL,0,MODE_UPPER, i); if( f!=0) break;}
 Alert(f,"  ",High[i]," i=",i);
P.S. look back from the position by this cycle, at the moment of position opening, remember
datetime timeFractalOnOpenPos=Time[i]
 
I don't understand how to display this in the EA. when opening a position, remember this fractal. then how to call it in the close condition?
 
it is unclear what it means to call,
in the global variables of the program
-Remember the time of a bar fractal to open a position. Using the time of the bar, we know the bar number through iBars()
-remember the fractal price
remember the fractal price - remember up / down
and then what to do once again?
 
Maybe I didn't put it that way. I just have no idea how to code it.
 
how many orders and which ones to each side?
 

above all blocks

double UfractalBuy,LfractalBuy;

write the nearest fractal when opening a buy order

int i; double f;

     if( ticket>0)
           {
            if(OrderSelect( ticket, SELECT_BY_TICKET, MODE_TRADES)) 
            {
            Print("BUY order opened : ",OrderOpenPrice());
  
   for( i=0; i<50; i++) { f=iFractals(NULL,0,MODE_UPPER, i); if( f!=0) break;}
   UfractalBuy=High[ i];
   for( i=0; i<50; i++) { f=iFractals(NULL,0,MODE_LOWER, i); if( f!=0) break;}
   LfractalBuy=Low[ i];
            }
           }

enter another condition for the buy order

if(P_down1>P_down0||Up<Down||Close[0]+5*Point<LfractalBuy)