[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 148

 
Konstebl:

Please tell me why the EA does not open trades Error 130.Stop Loss = 55 pips (4 digits of quotes)


I modified your EA a little bit. I put protection from wrong opening price.

 extern int PeriodLWMA=14;
 extern int tp=55;
 extern int sl=55;
 extern double MaxRisk=10;
 extern double Lot=0.1;
 bool NewBar()
  {
       static datetime lastbar = 0;
       datetime curbar = iTime(Symbol(), 0, 0);
       if(lastbar!=curbar)
       {
             lastbar=curbar;
             return (true);
       }
       return(false);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
    int ticket;
    double price,takeprofit,stoploss,Lots;
//----
    double frUP = iFractals(NULL,0,MODE_UPPER,3);
    double frLOW = iFractals(NULL,0,MODE_LOWER,3);
    double lwma = iMA(NULL,0,PeriodLWMA,0,MODE_LWMA,PRICE_CLOSE,0);
    frUP = iFractals(NULL,0,MODE_UPPER,3);
    frLOW = iFractals(NULL,0,MODE_LOWER,3);
       double MaxLot = MarketInfo(Symbol(),MODE_MAXLOT);
       double MinLot = MarketInfo(Symbol(),MODE_MINLOT);
       Lots = NormalizeDouble(AccountFreeMargin()/10*MaxRisk/1000,2);
    if(Lots>MaxLot)
       Lots = MaxLot;
    else Lots=Lot;
    if(Lots<MinLot)
       Lots = Lot;
//----
    static bool flag = true;
    if(NewBar())
      flag = true;
      if(Ask>lwma && frUP>Ask && frUP != EMPTY_VALUE && flag)
         {
         price = NormalizeDouble(frUP+(Ask-Bid)+30*Point,Digits);
         takeprofit = NormalizeDouble(price+tp*Point,Digits); 
         stoploss = NormalizeDouble(price-sl*Point,Digits);
         ticket = OrderSend(Symbol(),OP_BUYSTOP,Lots,price,5,stoploss,takeprofit,"Fractal",123,0,Blue);
         if(ticket>0 && GetLastError()==0)
            flag = false;
// Печатаем ошибку только в том случае, если она действительно случилась
         else Print("Ошибка № ",GetLastError()," OP_BUYSTOP Ask=",DoubleToStr(Ask,8)," Bid=",DoubleToStr(Bid,8)," OpenPrice=",DoubleToStr(price,8)," sl=",DoubleToStr(stoploss,8)," tp=",DoubleToStr(takeprofit,8));
            return(ticket);
         }
//-------------------------------------------------------------------
    if(NewBar())
      flag = true;
      if(Bid<lwma && frLOW<Bid && frLOW>0 && frLOW!=EMPTY_VALUE && flag)
         {
         price = NormalizeDouble(frLOW-30*Point,Digits);
         takeprofit = NormalizeDouble(price-tp*Point,Digits);
         stoploss = NormalizeDouble(price+sl*Point,Digits);
         ticket = OrderSend(Symbol(),OP_SELLSTOP,Lots,price,5,stoploss,takeprofit,"Fractal",123,0,Red);
         if(ticket>0 && GetLastError()==0)
            flag = false;
// Печатаем ошибку только в том случае, если она действительно случилась
          else Print("Ошибка № ",GetLastError()," OP_SELLSTOP Ask=",DoubleToStr(Ask,8)," Bid=",DoubleToStr(Bid,8)," OpenPrice=",DoubleToStr(price,8)," sl=",DoubleToStr(stoploss,8)," tp=",DoubleToStr(takeprofit,8));
            return(ticket);
         }
  }
 
Vinin:

And this option is not suitable. It's not the best.


I looked it up, but unfortunately it's not the right one. I would like to paint the candle exactly as it is.
 
Thank you!
 
Vinin:

It will work, but the result will be different. Not what you're expecting.

Can you tell me what's wrong? It's still difficult for me to navigate this programme with unfamiliar functions.


Thank you in advance!

 
arabon:

Can you tell me what's wrong? I'm still having a hard time navigating this programme with unfamiliar functions.


Thank you in advance!


double CalculateProfit_last() {//прибыль от последенй сделки
   double Profit = 0;
   int cnt;
   if(OrdersTotal()!=0)
   {
     cnt = OrdersTotal() - 1;
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
           if (OrderType() == OP_BUY || OrderType() == OP_SELL) Profit = OrderProfit();
   }
   Profit=0.0;  // Зачем вести расчеты, если потом их обнулить
   Print(Profit);
   return (Profit);
}
And what order are we talking about? We are talking about the last open or last closed order. If it's the only one, the question disappears.
 
Vinin:

And which order are we talking about? The last open order or the last closed order. If it is the only one, then the question disappears.

I need to calculate the profit of the last closed order, of course it is not the only one.


P.S. I don't even know why I blurted it out =)

   }
   Profit=0.0;  // Зачем вести расчеты, если потом их обнулить
   Print(Profit);
   return (Profit);
}
 


Hello. This code is a test one. The first question is how to make line numbering appear?

And more to the point: in the above code"ca[1]=Low[100]; Only this variant is reassigned" thedata inthe array is only reassignedinside the loop. Perhaps if an array is assigned to display chart data, it can only be reassigned once?

int start(){
int i=0 ;int k=0 ;
 while(i<=5000) 
   { 
  k=0 ;
  ca[i]=0;
 volume[i]=0;
 while(k<=10)
 {ca[i]= ca[i]+Volume[i+k]*(High[i+k]+Low[i+k])/2;
  volume[i]=volume[i]+Volume[i+k];
   k=k+1; } ca[i]=ca[i]/volume[i];
    i=i+1;//ca[1]=Low[100]; Переобозначение происходит только в этом варианте  
  }
  ca[1]=Low[100];//Переобозначение не происходит программа не видит  
  int a1=1;
  while(a1==1)//Переобозначение не происходит программа не видит
  {ca[1]=Low[100];
  a1=a1+1;}
  return(0);
  }
 
That's how it works. Apparently I've answered my own question.
int start(){
int i=0 ;int k=0 ;
 while(i<=500) 
   { 
  k=0 ;
  ca1[i]=0;
 volume[i]=0;
 while(k<=10)
 {ca1[i]= ca1[i]+Volume[i+k]*(High[i+k]+Low[i+k])/2;
  volume[i]=volume[i]+Volume[i+k];
   k=k+1; } ca1[i]=ca1[i]/volume[i];
    i=i+1;
  }
 ca1[0]=Low[100];//Переобозначение  происходит программа  Видит
  //Цикл заполнения массива для отображения значений функции 
   i=0;
    while(i<=500)//Переобозначение происходит программа  Видит
     {ca[i]=ca1[i];
      i=i+1;}
  return(0);
  }
 
T-G:
Can you tell me how Funds (AccountEquity() ) and Collateral (AccountMargin() ) are separate for Buy and Sell positions?

See if you can find these fi ndings in I. Kim's custom fi ndings: https://www.mql5.com/ru/forum/131859

С

 
Sorry.
leonid553:

See if you can find these fi ndings in I. Kim's custom fi ndings: https://www.mql5.com/ru/forum/131859

С


Unfortunately, I couldn't find any.