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

 
yan720:

Then do you think this function won't work? I haven't tested it, but it seems to me to be part of a working code (this Ilan was obviously rebuilt from something debugged at best). Or is it still a crummy code?




Use it:

void Modify_orders (double AverPrice, double SLoss, double TProfit){
   double Stoplevel =  MarketInfo(Symbol(),MODE_STOPLEVEL);
   datetime GTCount_1 = 0;
   datetime GTCount_2 = 0;
   int ppos = 0;
   if ((AverPrice != 0) == TRUE){
      for (ppos = OrdersTotal() - 1; ppos >= 0; ppos--){
          if (OrderSelect(ppos, SELECT_BY_POS, MODE_TRADES) == TRUE){
            if ((OrderSymbol() != Symbol() || OrderMagicNumber() != Magic || OrderType() >= 2) == TRUE) continue;
            if ((OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) == TRUE){ 
            if ((OrderType() == 0) == TRUE){ 
               if(Bid - SLoss < Stoplevel * Point){ SLoss = ND(Bid - Stoplevel * Point);}
               if(TProfit - Ask < Stoplevel * Point){ TProfit = ND(Ask + Stoplevel * Point);}
            }else if ((OrderType() == 1) == TRUE){ 
               if(SLoss - Ask < Stoplevel * Point){ SLoss = ND(Ask + Stoplevel * Point);}
               if(Bid - TProfit < Stoplevel * Point){ TProfit = ND(Bid - Stoplevel * Point);}
               }
                  GTCount_1 = GetTickCount();           
                  OrderModify(OrderTicket(), AverPrice, SLoss, TProfit, 0, Yellow);  
                  GTCount_2 = GetTickCount() - GTCount_1;
                   // Print("Modify time(ms):   ", GTCount_2, "   /  Ticket: ", OrderTicket()," /  Time: ", TimeToStr (TimeCurrent(), TIME_SECONDS), " /  Average price: ",AverPrice, " /  SL: ",SLoss, " /  TP: ",TProfit); 
                Sleep(33);                
                }
            }
        } 
    }
}
double ND(double value){
   return(NormalizeDouble(value, Digits));
}
 
digits:


You are using:

Your function does not handle trade server errors. The OrderModify() function should be designed as a separate full-fledged function with error handling and adequate error response.

And again, what for?

if ((OrderSymbol() != Symbol() || OrderMagicNumber() != Magic || OrderType() >= 2) == TRUE) continue;
if ((OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) == TRUE){

What's the oil for?

 
digits:


Use:


No, we do not use this kind of g.
 

It would be strange to buy bread at 20, come home and change the purchase price to 5 roubles, and then see in your wallet the arrival of 15 roubles of difference... Fantastic... ;)

You could resell the bread for 35 roubles (15 roubles profit) but the broker wouldn't give you a commission :=)

 

Good afternoon. Started studying MQL a couple of days ago, reread the site but can't find the answer. (Don't judge a newbie)

If i had already tried that, i would have seen that many orders are now closed. Here is a simple code which should close an order when crossing a MA(5) and MA(21)

Here is the code to close the order by crossing MA(5) and MA(21). Thank you.

double ma50;

double ma51;

double ma210;

double ma211;

double ma550;

double Stoh;

int start()

{

//Open Orders--------------------------------------------------------------------------------

{

ma50=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);

ma51=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1);

ma210=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,0);

ma211=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,1);

ma550=iMA(NULL,0,55,0,MODE_EMA,PRICE_CLOSE,0);

Stoh=iStochastic(Symbol(),5,5,3,3,MODE_SMA,1,MODE_MAIN,0);

if(OrdersTotal()==0 && ma50 > ma51 && ma50 > ma210 && ma51 < ma211 && ma210 > ma550 )

OrderSend(Symbol(),OP_BUY,Lots,Ask,0,0,0,"BUY",123,0,Red);

}

//Close Orders--------------------------------------------------------------------------------

{

if(OrdersTotal()==1 && ma50 < ma210 )

if(OrderSelect(10,SELECT_BY_POS)==true)

OrderClose(OrderMagicNumber(),Lots,Bid,1,CLR_NONE);

}

}


 
AlexCY:

Good afternoon. Started studying MQL a couple of days ago, re-read the website, but can't find the answer. (Don't judge a newbie)

If i had already tried that, i would have seen that many orders are now closed. Here is a simple code which should close an order when crossing a MA(5) and MA(21)

Thank you.

Whether the code is correct or not depends directly on what you, and nobody else, mean by this term.

Here you are trying to open an order with a similar but slightly more incorrect attempt to close it.

The only thing I can advise you on is to go and study the language further, there is no hurry, because too small a base is the main reason for misunderstanding.

The parameters in OrderClose are not correct . + If you have one order OrderSelect is taken with number 0. + are you sure that after the next tick or two "ma50 < ma210" will not be executed by eating your spread?

and the code is inserted through the button SRC on the toolbar.

 

Good afternoon.

In the code of the indicator we need to catch the moment when a new trend appears on the chart, and get the name of this trend.

Besides tracking the list of all objects on every tick, fixing the moment of change in the number of objects and then going through the entire list in the hope to find the object that has just been applied... Is there any other, less expensive way? If so, how can this be implemented more easily?

 
satorifx:

Good afternoon.

In the code of the indicator we need to catch the moment when a new trend appears on the chart, and get the name of this trend.

Besides tracking the list of all objects on every tick, fixing the moment of change in the number of objects and then going through the entire list in the hope to find the object that has just been applied... Is there any other, less expensive way? If so, how can this be implemented more easily?


and in the part where the object is directly applied, add a link to the block with the processing of the above?
 
ALXIMIKS:

and in the part where the object is directly applied, add a link to the block with the processing of the above?
So what part are we talking about? I have 2 ways of creating trends: with my own script (I can add anything I like there) and with the standard trend created by means of MT4 (I cannot add anything here). The task is to trace the trend by any method.
 
Can you please tell me where I can find the compiled EA .exe file?