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

 
Vinin:


if (c % 2==0) //even


I wouldn't check double for equality to anything.
 
Can you please tell me how to run a for loop on already closed loss-making orders? Or maybe someone already has a function: when a loss trade is closed, multiply the lot?
 
tara:

I wouldn't check double for equality with anything.


I thought I wrote before that only for integers. Or don't you read it well?

Vinin 18.09.2011 03:14 am | delete
NickXXX:

Question for a puzzle).

How to determine programmatically whether a number is even or odd?

For example:

int a, b, c;

a=2;

b=3;

c=a+b

c is even or odd?



If the numbers are integers, check for the remainder of division by 2.

if (c % 2==0) //четное

 

clarify code errors


avatar
2
Qwuyt 18.09.2011 11:56

Good afternoon!

Please who is not lazy to look at the code and advise what my errors are. I got a bunch of errors on compilation. This is my first EA, I have just started to understand it. The idea of the Expert Advisor is as follows: on Monday at a given time we place pending orders in both directions at a distance of X points from the previous week's close. On Friday, at a given time we will close the market orders and delete the pending ones. That's all.

//+------------------------------------------------------------------+
//|                                                         Week.mq4 |
//|                                          Copyright © 2011, Qwuyt |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Qwuyt"
#property link      ""

//--- input parameters
extern double    lot=0.01;                                                 //размер лота 
extern int       tp=200;                                                   //тейк профит
extern int       sl=50;                                                    //стоплосс
extern int       move=100;                                                 //движение цены 
extern int       hc=22;                                                    //час закрытия 
extern int       ho=4;                                                     //час закрытия
double BP;                                                                 //цена открытия бай
double SP;                                                                 //цена открытия селл
int Ticket;                                                                
int Tip;                                                                   //тип ордера
int Curday;                                                                //день недели
bool Ans = false;                                                          //ответ сервера после закрытия ордера
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()                               
  {
  int Curday = DayOfWeek                                    
  double BP = iClose(NULL,10080,1)+NormalizeDouble(move*Point,Digits);     //      
  double SP = iClose(NULL,10080,1)-NormalizeDouble(move*Point,Digits);
    if (ho >= Hour && Curday=1)                                            //4 утра понедельника - открытие бай
    {
    OrderSend (Symbol(),OP_BUYSTOP,lot,BP,3,sl,tp,NULL,0,0,Red)
    }
    if (ho >= Hour && Curday=1)                                            //4 утра понедельника - открытие селл
    {
    OrderSend (Symbol(),OP_SELLSTOP,lot,SP,3,sl,tp,NULL,0,0,Red)
    }
    while(true)                                                           //цикл закрытия орд.
     {
      if (Tip==0 && hc >= Hour && Curday=6)                               // Открыт ордер Buy, 22 часа пятницы закрыть
        {                                                                 //
         RefreshRates();                                                  // Обновление данных
         Ans=OrderClose(Ticket,lot,Bid,3);                                // Закрытие Buy
         return;                                                          // Выход из start()
        }
      if (Tip==1 && hc >= Hour && Curday=6)                               // Открыт ордер Sell, 22 часа пятницы закрыть
        {                                                                 //

         RefreshRates();                                                   // Обновление данных
         Ans=OrderClose(Ticket,lot,Bid,3);
         return;                                                          // Выход из start()
        }
      if (Tip==4||Tip==5 && hc >= Hour && Curday=6)                               // Открыт ордер Buy, 22 часа пятницы закрыть
        {                                                                 //
         RefreshRates();                                                  // Обновление данных
         Ans=OrderDelete(Ticket,CLR_NONE);                                // Закрытие Buy
         return;                                                          // Выход из start()
        }
      break;                                                               // Выход из while
     }
     Tip = OrderType();
return();
  }
Attachment files:
Week_1.mq4 (4.52 KB)



929
abolk 18.09.2011 12:00 am correct | delete

to begin with:

1) put ; at the end of each operator

2) use correct functions, for example Hour()

 
Falmera:
Can you please tell me how to run a for loop on already closed loss-making orders? Or maybe someone already has a function: when a loss trade is closed, multiply the lot?

any tips?
 
Falmera:

suggest a tip!


Show me your own attempts to implement this function - the "newbie help" thread.

or search for "search for the last closed order" or similar - the topic has been around for a long time

 
Falmera:

Well, give me a hint.

See the owls of the Avalanche branch.
 

I'm learning a programming language, and I'm having trouble understanding the behaviour of the programme. I have written an EA based on the textbook, but I have twisted it to a slightly different principle of operation.

The Expert Advisor is based on 2 muwings averaging. The idea is simple, moving averages cross, order is closed and opposite one is opened. I wrote an EA and it works fine. Of course it is at a slight disadvantage, but in accordance with the idea. The entire problem is as follows (in bold):

A=iMA(NULL,0,Period_MA_1,0,MODE_SMA, PRICE_CLOSE,1); // A

B=iMA(NULL,0,Period_MA_2,0,MODE_SMA,PRICE_CLOSE,1); // B

C=iMA(NULL,0,Period_MA_1,0,MODE_SMA,PRICE_CLOSE,2); // C

D=iMA(NULL,0,Period_MA_2,0,MODE_SMA,PRICE_CLOSE,2); // D

If I change the way of calculating moving averages (it can show plus sign) and put exponential method( MODE_SMA) instead of simple one (MODE_EEMA ) and one more(MODE_SMMA), so called smoothed method, everything goes wrong. The working principle becomes even more amusing (in the strategy tester) as the EA opens an order at the very beginning of the period set and closes it at the end. I.e., for a year it opens one single trade at the beginning of the period, and closes it at the end. As a result, the Expert Advisor has shown me a plus, but I do not need such a plus. I can flip a coin myself and open either Buy or Sell order and look, whether I'm winning or losing in a year. By the way, if I set MODE_SMA to MODE_LWMA (Linear Weighted Moving Average), the programme works fine.

Please, advise me, what is wrong? The principle is the same, but the way of calculation of moving averages has just been changed a bit.

The entire code is in attached file.


I have had replies here, but they are not competent and not on the merits. Allegedly I use 4 moving averages. This is not true, there are two moving averages, but for each moving average taken values for two bars (a total of 4 array calls, A, B, C, D):1 and 2 . In addition, they wrote that when an order is closed, we should lower the number of Total orders, but there is no need in this because the orders are counted using the Odertotal function and if I close an order, the order total itself changes its value at the next iteration. They also suggest using the so-called magic numbers to keep track of orders but I haven't got to that part of the manual yet. I should repeat that the program works when MODE_SMA and MODE_LWMA are used but not when MODE_EMA and MODE_SMMA are used. Who knows why, write me an answer please.

 
Falmera:

Please give me a hint.
go to the avalanche topic, there are enough advisors there with any lot increment... Search the forum at the top right or google.
 
neisseria:

I'm learning a programming language, and I'm having trouble understanding the behaviour of the programme. I have written an EA based on the textbook, but I've twisted it to a slightly different principle of operation.

The Expert Advisor is based on 2 muwings averaging. The idea is simple, moving averages cross, order is closed and opposite one is opened. I have written an EA and it works fine. Of course it is at a slight disadvantage, but in accordance with the idea. The entire problem is as follows (in bold):

A=iMA(NULL,0,Period_MA_1,0,MODE_SMA, PRICE_CLOSE,1); // A

B=iMA(NULL,0,Period_MA_2,0,MODE_SMA,PRICE_CLOSE,1); // B

C=iMA(NULL,0,Period_MA_1,0,MODE_SMA,PRICE_CLOSE,2); // C

D=iMA(NULL,0,Period_MA_2,0,MODE_SMA,PRICE_CLOSE,2); // D

If I change the way of calculating moving averages (it can show plus sign) and put exponential method( MODE_SMA) instead of simple one (MODE_EEMA ) and one more(MODE_SMMA), so called smoothed method, everything goes wrong. The working principle becomes even more amusing (in the strategy tester) as the EA opens an order at the very beginning of the period set and closes it at the end. I.e., for a year it opens one single trade at the beginning of the period, and closes it at the end. As a result, the Expert Advisor has shown me a plus, but I do not need such a plus. I can flip a coin myself and open either Buy or Sell order and look, whether I'm winning or losing in a year. By the way, if I set MODE_SMA to MODE_LWMA (Linear Weighted Moving Average), the programme works fine.

Please, advise me, what is wrong? The principle is the same, but the way of calculation of moving averages has just been changed a bit.

The entire code is in attached file.


I have had replies here, but they are not competent and not on the merits. Allegedly I use 4 moving averages. This is not true, there are two moving averages, but for each moving average taken values for two bars (a total of 4 array calls, A, B, C, D):1 and 2 . In addition, they wrote that when an order is closed, we should lower the number of Total orders, but there is no need in this because the orders are counted using the Odertotal function and if I close an order, the order total itself changes its value at the next iteration. They also suggest using the so-called magic numbers to keep track of orders but I haven't got to that part of the manual yet. I should repeat that the program works when MODE_SMA and MODE_LWMA are used but not when MODE_EMA and MODE_SMMA are used. Who knows why, write me an answer please.


I would also double-check conditions. There may be a problem there