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

 

or how to get rid of this error


 
remjte:
Gentlemen! Can you tell me the code that will stop testing an EA when there is not enough margin to open a position?
Thank you!
If AccountFreeMarginCheck() is less than a certain value (e.g. less than 50% of AccountFreeMargin) - exit trading function, test ends quickly because empty loops are almost unloadable.
 
evillive:
If AccountFreeMarginCheck() is less than a certain value (for example, less than 50% of AccountFreeMargin) - exit from trade function, test quickly ends, because empty loops are almost not loading.

Honestly, still very green, found this piece of code can you tell me how to correct

if (AccountFreeMarginCheck(Symbol(), a_cmd_0, l_lots_4) <= 0.0) return (-1);
if(GetLastError() == 134/* NOT_ENOUGH_MONEY */) return (-2);
return (l_lots_4);

 
In simpler words: How do I write this condition - Do not modify an open order until a new candle appears?
 
zhezheria:
Let me write in a simpler way: how to write this condition - Do not modify an open order until a new candlestick appears
Work on opening a new bar in a corresponding timeframe. A lot of code examples
 
remjte:

Honestly, still very green, found this piece of code can you tell me how to correct

if (AccountFreeMarginCheck(Symbol(), a_cmd_0, l_lots_4) <= 0.0) return (-1);
if (GetLastError() == 134/* NOT_ENOUGH_MONEY */) return (-2);
return (l_lots_4);

You needn't edit it, it will do just fine. Unless you just replace the variables with your own names.

But if we need less risk, then if (AccountFreeMarginCheck(Symbol(), a_cmd_0, l_lots_4) <= AccountFreeMargin()*0.5) return (-1); - in this case, if 50% or less free money remains after the position is opened with the specified lot, then return (-1)

 
Can you give me a hint, please? I need to write a part of code where the second order in the list will be selected and then deleted (pending). Returns 4051 when OrderSelect(1, SELECT_BY_POS, MODE_TRADES)
 
remjte:
Gentlemen! Can you tell me the code that will stop testing an EA when there is not enough margin to open a position?
Thank you!
      // проверяем доступность свободных средств
      if(AccountFreeMarginCheck(Symbol(),OP_BUY,OpenLot)<=0 || GetLastError()==134)
            {
               Print("It is impossible to open the order Buy, not enough money.");
               return(0);
            }
      // проверяем доступность свободных средств
      if(AccountFreeMarginCheck(Symbol(),OP_SELL,OpenLot)<=0 || GetLastError()==134)
            {
               Print("It is impossible to open the order Sell, not enough money.");
               return(0);
            }
doube OpenLot; // Лот который вы хотите открыть.
Insert this before opening a market order.
 
Pomid:
Can you give me a hint, please? I need to write a part of code where the second order in the list will be selected and then deleted (pending). Returns 4051 when OrderSelect(1, SELECT_BY_POS, MODE_TRADES)
The order count starts from 0. Try, OrderSelect(0, SELECT_BY_POS, MODE_TRADES)
 

Here we need to place pending orders and calculate their prices relative to the previous bar close price. BUYSTOP is placed, while SELLSTOP returns error 130. Is there an error in this code? Or in another function.

void SetOrders() {

double ldStop=0, ldTake=0;
int spr=MarketInfo(Symbol(), MODE_SPREAD);
double PredBar=iClose(NULL,PERIOD_M5,1);
double pAsk=PredBar+(DistanceSet+spr)*Point;
double pBid=PredBar-(DistanceSet+spr)*Point;

if (!ExistOrder(1)) {
if (StopLoss!=0) ldStop=pAsk-StopLoss*Point;
if (TakeProfit!=0) ldTake=pAsk+TakeProfit*Point;
SetOrder(OP_BUYSTOP, pAsk, ldStop, ldTake, 1);
}
if (!ExistOrder(2)) {
if (StopLoss!=0) ldStop=PredBar+(StopLoss*Point);
if (TakeProfit!=0) ldTake=pBid-TakeProfit*Point;
SetOrder(OP_SELLSTOP, pBid, ldStop, ldTake, 2);
}
}
Reason: