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

 
FoxUA:

maybe i didn't mean exactly, i need the BalansEURUSD variable to show profits or losses in percentages "BalansEURUSD =5%", like this

and so on a few more pairs let's say the pound and the doloraine

one time


this is harder but it can be calculated:

For an SELL order

profit=NormalizeDouble((OrderOpenPrice()-Ask)*MarketInfo("EURUSD",MODE_TICKVALUE)*OrderLots()/Point,2);

margin=NormalizeDouble(AccountFreeMargin()-AccountFreeMarginCheck("EURUSD",OP_SELL,OrderLots(),2);

for BUY:

profit=NormalizeDouble((Bid-OrderOpenPrice())*MarketInfo("EURUSD",MODE_TICKVALUE)*OrderLots()/Point,2);

margin=NormalizeDouble(AccountFreeMargin()-AccountFreeMarginCheck("EURUSD",OP_BUY,OrderLots(),2);

these are full formulas to calculate the profit of the order + margin for this order, the margin should be taken into account, because if the order closes, the released margin will be added to the balance, the money will increase numerically, but the real profit may not have been

 

Guys, please advise how to trigger one pending order and place another ?????? I tried it through order select, but it does not work ........
after
order type == buy, // where buystop was earlier
open pending order // (it does not open)

 
VOLDEMAR:

Can you guys tell me how to trigger one pending order and place another ?????? I tried to do it through order select but it did not work ........
after
order type == buy, // where buy was previously bystop
open a pending order // (does not open)


If there is, it means that the pending order (that was set earlier) has become marketable, then place the next order (another pending order that you need, for example: if the buy order is in the market, then place a bystop, etc.). I recommend to read

on the alpari website - forex training - trader's manual - autotrading MKL4 (left-hand panel) - trading advisors - (orderselect, ordersend, conditional operators, etc.)

http://www.alpari.ru/ru/school/textbook/autotrading/expert_advisors/ - concise and informative...

 

I'm trying to learn how to program. Please tell me, I suspect that the following condition is never satisfied in the Expert Advisor

while (B*Point >zmm)
Comment("Difference value ", B);
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-stoploss*Point,Ask+TakeProfit*Point, "macd sample",16384,0,Green);

How can this be checked? What methods are available? And is it possible when the ticks are not working?

 

Dear Experts! I am learning to write an EA. It works, but not everything. The blocks of modification and closing of orders do not work. I cannot find the reason. I ask for help.

//+------------------------------------------------------------------+
//|                                                Monetny dvor1.mq4 |
//|                                                            fanat |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "fanat"
#property link      "http://www.metaquotes.net"

extern int TakeProfit=484; //
extern int StopLoss=89;    //
extern bool BStop=true;    //Включение безубытка
extern int Stop=90;        //            
//+------------------------------------------------------------
int start()
{//1
   
if(TakeProfit<10){Alert("Ошибка,Take слишком близко");return;}
if(StopLoss<10){Alert("Ошибка,StopLoss слишком близко");return;}
   
bool Buy=false;
bool Sell=false;
if(Close[0]>High[1])Buy=true;
if(Close[0]<Low[1])Sell=true;

int err;
int Order_Count[6];
int OP=-1;
ArrayInitialize(Order_Count,0);                             
         
for(int i=0;i<=OrdersTotal();i++)       //
  {//2                                   // Блок учета ордеров
   if(OrderSelect(i,SELECT_BY_POS)==true)//
    {//3                                 //
     Order_Count[OrderType()]++;         //
     if(OP!=-1)return(Order_Count[OP]);  //
    }//3
  }//2  
     if(OrdersTotal()>0)
      {//2
       if(BStop==true&&OrderOpenPrice()!=OrderStopLoss())                                                //Модификация ордеров
        {//3                                                                                             //
         if((OrderType()==0&&(Ask-OrderOpenPrice())>Stop)||(OrderType()==1&&(OrderOpenPrice()-Bid)>Stop))//
          {//4                                                                                           // 
           int ticket=OrderTicket();                                                                     // 
           double Price=OrderOpenPrice();                                                                //
           double SL=OrderOpenPrice();                                                                   //
           double TP=OrderTakeProfit();                                                                  //
           bool Ans=OrderModify(ticket,Price,SL,TP,0);                                                   //
           
           if(Ans==false){err=GetLastError();Alert(err);Sleep(500);return;}                              //Обработка ошибок
          }//4
        }//3
          
                                                                                                                                                                                                                                                                                                                                       // 
       if(OrderType()==1&&(Buy==true||Ask<OrderTakeProfit()||Bid>OrderStopLoss()))      //Условия закрытия ордеров Sell  
        {//3
         ticket=OrderTicket();                             //Закрытие ордеров Sell                                                                         
         double Lots=OrderLots();                          //
         OrderClose(ticket,Lots,Ask,4);                    //
         
         err=GetLastError();                               //Обработка ошибок 
         if(err>0){Alert(err);Sleep(500);return;}          //                                                                              
        }//3
                                                           
       if(OrderType()==0&&(Sell==true||Bid>OrderTakeProfit()||Ask<OrderStopLoss()))      //Условия закрытие ордеров Buy 
       {//3
         ticket=OrderTicket();                             //Закрытие ордеров Buy                   
         Lots=OrderLots();                                 //  
         OrderClose(ticket,Lots,Bid,4);                    //
          
         err=GetLastError();                               //Обработка ошибок
         if(err>0){Alert(err);Sleep(500);return;}          //
       }//3
      }//2 
                   
   if(Buy==false&&Sell==false)return;
   int Total=1;
   double Lot=0.03;                 
/*  if(AccountBalance()>400)Lot=0.04;          //
   if(AccountBalance()>500)Lot=0.05;          //
   if(AccountBalance()>600)Total=2;           //
   if(AccountBalance()>800)Lot=0.04;Total=2;  // Блок вычисления лота для реала
   if(AccountBalance()>1000)Lot=0.05;Total=2; //
   if(AccountBalance()>1200)Lot=0.04;Total=3; //
   if(AccountBalance()>1500)Lot=0.05;Total=3; //
   if(AccountBalance()>1600)Lot=0.04;Total=4; //
   if(AccountBalance()>1800)Lot=0.03;Total=6;*/ //
   
   Lot=0.1;
   if(AccountBalance()>1600)Lot=0.2;
   if(AccountBalance()>2400)Lot=0.3;
                                                                                      
   if(Order_Count[OP_BUY]<Total&&Order_Count[OP_SELL]==0&&Buy==true)                     //Открытие ордеров Buy
   {//2                                                                                  //
      OrderSend(Symbol(), OP_BUY, Lot, Ask, 4, Ask-StopLoss*Point, Ask+TakeProfit*Point);//
       
      err=GetLastError();                                                                //Обработка ошибок
      if(err>0){Alert(err);Sleep(500);}                                                  //
      return;
   }//2         
           
   if(Order_Count[OP_SELL]<Total&&Order_Count[OP_BUY]==0&&Sell==true)                     //Открытие ордеров Sell 
   {//2                                                                                   //
      OrderSend(Symbol(), OP_SELL, Lot, Bid, 4, Bid+StopLoss*Point, Bid-TakeProfit*Point);//
      
      err=GetLastError();                                                                 //Обработка ошибок
      if(err>0){Alert(err);Sleep(500);}                                                   //
   }//2
  
return;
}//1

I am asking for help.

 
fanat:

Dear Experts! I am learning to write an EA. It works, but not everything. The blocks of modification and closing of orders do not work. I cannot find the reason. I ask for help.

I am asking for help.


Maybe it's time to get familiar with the functions.
 

here's the problem :

MathSrand(TimeLocal());

int periodRandom=period+ MathRand()/10000;
int period2Random=period2+ MathRand()/10000;

Moving1=iMA(Symbol(),0,periodRandom,0,MODE_SMA,price,1) ;

Moving2=iMA(Symbol(),0,period2Random,0,MODE_SMA,price,1);

I decided to change randomly the period of the waving - period plus a random value from 0 to 3.

But in the tester the run shows always the same profit value. Maybe the period doesn't change, What did I save wrong?

 

Good day! The question is simple: is it possible to set the second dimension of a two-dimensional array not via constant?

That is, I should do so: double massiv[5][5], but I want double massiv[5][k], where k is a known integer value set earlier, for example, through extern int k = 5. The first dimension can be changed with ArrayResize function, but the second cannot be changed for some reason...

 
fru1t:

Good afternoon, my question is simple: is it possible to somehow specify the second dimension of a two-dimensional array other than through a constant?

That is, I should do so: double massiv[5][5], but I want double massiv[5][k], where k is a known integer, defined earlier, for example, through extern int k = 5. The first dimension can be changed with ArrayResize function, but the second cannot be changed for some reason...


#define k 5

https://docs.mql4.com/ru/basis/preprosessor/constant

 

Hello, experts.

Please explain how to remove the information from the indicator subwindow at the top left.

It is in the way.

Reason: