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

 
MaxZ:

I must be missing something:



NewOrder has been dealt with thanks, now the step works
 
SeALALex:

I've implemented NewOrder, thanks, now the order works.

Be careful with this code. It was written on the fly and has not been tested! :)))

And I only wrote one way of solving your problem.


By the way, you gave the following code earlier:

Болк открытия на бай
if(Buy==true) 
  {Buy=false;

   ticket=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask, Digits),5,SL,TP,Order,070177,0,Orange);
   if(ticket>0)
    { 
     if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
      {Print("BUY order opened : ",OrderOpenPrice());
       Alert("Buy Order for ",Symbol());
       SendMail("Buy Order "+Symbol()+" "+Ask,SL);     
       }
     }
     else Print("Error opening BUY order : ",GetLastError()); 
     return(0); 
   }

What if there is a requote, for example? Then the BUY order won't be opened, while the signal might be correct. And in a couple of hours you will see that the price has moved far upwards, but the BUY order hasn't opened because of the requote...

 
MaxZ:

Be careful with this code. It was written on the fly and has not been tested! :)))

And I only wrote one way of solving your problem.


By the way, you cited the following code earlier:

What if there is a requote, for example? Then the BUY order will not be opened, while the signal might be correct. And you will see that the price has moved far upwards in a couple of hours, but the BUY order hasn't opened due to the requote...


And how do you insure against it?

 
SeALALex:


and how do you hedge against it?

The most basic way is to rewrite the code differently:

Болк открытия на бай
if(Buy==true) 
  {ticket=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask, Digits),5,SL,TP,Order,070177,0,Orange);
   if(ticket>0)
    { 
     if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
      {Buy=false;
       Print("BUY order opened : ",OrderOpenPrice());
       Alert("Buy Order for ",Symbol());
       SendMail("Buy Order "+Symbol()+" "+Ask,SL);     
       }
     }
     else Print("Error opening BUY order : ",GetLastError()); 
     return(0); 
   }

As long as the order does not open, the signal to open a long Buy position will hang in the True state.

 
MaxZ:

The most elementary way is to rewrite the code differently:

Until the order opens, the signal to open a long Buy position will hang in a True state.


Thanks a lot! And thanks a lot to Roman!

I need to increase the lot in a series of open buy orders without margin (because margin sometimes affects us in such a way that it reduces the lot, and I don't need it), I need a strict increase by a certain size in a series of orders. I.e. if there is a trend according to one criterion a buy signal, then according to the second criterion an additional buy signal appears and an order is opened; after the first criterion is still a buy signal and according to the second one, after a small correction an additional buy signal appears and another order is opened, but with a larger order (the size is set in the initial parameters); after all buy orders are closed there appears a sell signal and then everything starts again with the initial size of the lot.

Please, what piece of code should be shown?

 
SeALALex:


Thank you very much! And thanks a lot to Roman!

But i still can't get it to increase a lot by a certain step, i need to increase a lot in a series of open buy orders without margin (because margin sometimes decreases a lot, and i don't need it), i need a strict increase by a certain size in a series of orders.

If you're not using margin in lot calculations and operate only with constant parameters specified, for example, in extern-variables, the lots will correspondingly increase only with constant values. The principle, by which the code can be written I gave above.

SeALALex:


I.e. if there is a trend according to one criterion a buy signal, then according to the second criterion an additional buy signal appears - an order is opened, then according to the first criterion the buy signal still remains and according to the second one, after a small correction the buy signal appears again and one more order is opened, but with a larger size (the size is set in the initial parameters) and after all buy orders are closed an sell signal appears and then everything starts from the initial size of the lot again.

Please, what piece of code do you need to show?

You have variables Lots, LotsInitial and LotsStep. When the trend changes, you reset Lots to zero and assign an initial value to LotsInitial. If the trend is still going on and a signal has already been sent to open a new order, you increase the variable Lots with the step LotsStep and open an order.

You seem to understand all the logic, but you somehow cannot turn it into if statements. Why, I do not know.

Maybe this may help:

extern LotsInitial = 0.5;
extern LotsStep    = 0.1;
       Lots;

int start()
{
   ...

   if ((Тренд окончен) && (Все ордера закрыты) && (Пришёл сигнал о возможном начале нового тренда))
      Lots = LotsInitial;
 
   if ((Тренд подтверждён) && (Коррекция) && (Пришёл ещё сигнал открыться по тренду))
      Lots += LotsStep;
  
   ...
}
 
MaxZ:

If you are not using margin in lot calculations and operate only with constant parameters, set for example in extern variables, the lots will accordingly be increased only by constant values. The principle, according to which the code can be written I gave above.

You have the variables Lots and LotsStep. When the trend changes, you reset Lots to zero and assign an initial value. If the trend is still going on and a signal has already been sent to open a new order, you increase the Lots variable in increments of LotsStep and open an order.

You see that you understand the whole logic, but for some reason you can't turn it into if statements... Why, I don't know.


Can I put part of the code as a file responsible for opening as a file and you look... I did, but it looks like there's something wrong with the code I posted, it opens one step more, but not quite.
Files:
 
SeALALex:

Can I paste a part of the code responsible for opening as a file and you look at it... pasted but it looks like there is something wrong with the code as I posted it opens one step more but by a long shot.

You would have fixed all the errors first. Why would you add something to your EA if it doesn't work without it? Although, this code does not look like a fully functional EA. You must have cut out parts of it and now you want me to fix the errors. :)))

For example, init() is not closed... And obscure variable: LastOrder...

Please fix these errors.

 
MaxZ:

You'd better fix all errors first. Why would you add something to the Expert Advisor if it will not work without it? The code does not seem to have the full functionality of the Expert Advisor. You must have cut out parts of it and now you want me to fix the errors. :)))

For example, init() is not closed... And obscure variable: LastOrder...

Please fix the errors.


Yes I assembled it as a construction set seems to work, now will certainly try to more or less lead to a normal form and will lay out
 
splxgf:


It's not about ND. point is the point size, multiply it by zero five it would be for example 0.00005, I see no point in comparing this number with OrderClosePrice()-OrderTakeProfit(). TP does not guarantee exactly the same closing price. Plus the check conditions will be different for Bais and Selves.

This design is more reliable.



Thank you!!! Reading. Plus there will be different testing conditions for the bai and the selves-Awesome truth!!!
Reason: