Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1618

 
Vitaly Muzichenko #:

You can do it this way, without using libraries

Thank you!

 
MakarFX #:
The market is now closed, TimeCurrent() does not change. Check on crypto, it works on weekends

Why make it tick-dependent? The button should not depend on them.

 

Hello.

I want to test some strategies, no one has them for more than 2 months.

I understand the volumes are big, that's why brokers don't allow to download. Only basic pairs.

Maybe someone has some left in the folders on the server? At least for 1 year.

 
The issue is resolved.
 
Hello! Decided to write here ... maybe someone will respond!!! In CodeBase ... long ago it was ... was laid out the indicator ... neither the name do not remember ... nor the author. The essence of it was this ... Manually set the horizontal line ... and it shows how many times the price crossed the line in one and other directions ... and shows statistics on this price ... Piped twice 66 pages but could not find it ... can anyone remember or have any!!! PLEASE need it badly!!!
 
Sinax #:
Hello! Decided to write here ... maybe someone will respond!!! In CodeBase ... long ago it was ... was laid out the indicator ... neither the name do not remember ... nor the author. The essence of it was this ... Manually set the horizontal line ... and it shows how many times the price crossed the line in one and other directions ... and shows statistics on this price ... Piped twice 66 pages but could not find it ... can anyone remember or have any!!! PLEASE need it badly !!!
Not this:
?

 
Sergey Gridnev #:
Not that one:
?

No it isn't...the one for MT4 was...Thank you)))

 

Good day to all!!!!

Can you please help me write code for grid EA, the principle of closing the grid is simple all orders with a profit on all orders with a loss plus a profit from the breakeven price.

I am trying to realize an idea to average and close only min and max orders in the grid at a certain drawdown level, thus reducing the drawdown level.

Here is a part of the code for opening group orders:

if (CountTrade() < MaxOrders)

{

int order_type = FindLastOrderType();

if (order_type == OP_BUY)

{

price = FindLastOrderPrice(OP_BUY);

if(Ask<= price - (NormalizeDouble(ATR/ DivisorVolatility/Point, 0)*Point))

{

lastlot = NormalizeDouble(Lots()*MathPow( MultiplierParameter, OrdersTotal()), 2);

ticket = OrderSend(Symbol(), OP_BUY, lastlot, Ask, slip, 0, 0, "Group Order", Magic, 0, Blue);

if (ticket < 1)

Print ("Buy order error");

ModifyOrders(OP_BUY);

}

}

if (order_type == OP_SELL)

{

price = FindLastOrderPrice(OP_SELL);

if(Bid>= price + (NormalizeDouble(ATR/ DivisorVolatility/Point, 0)*Point))

{

lastlot = NormalizeDouble(Lots()*MathPow( MultiplierParameter, OrdersTotal()), 2);

ticket = OrderSend(Symbol(), OP_SELL, lastlot, Bid, slip, 0, 0, "Group Order", Magic, 0, Red);

if (ticket < 1)

Print ("Sell order error!");

ModifyOrders(OP_SELL);

}

}

}

Here's the part of the code where the command to modify orders comes in. Here I've crossed the modification of orders by "All orders with profit and all orders with loss" and "Averaging min and max orders".

//+----------------------------------------------------------------------------+

//| Order modification |

//+----------------------------------------------------------------------------+

void ModifyOrders(int otype)

{

double

BuyPriceMax = 0, BuyPriceMin = 0, BuyPriceMaxLot = 0, BuyPriceMinLot = 0,

SelPriceMin = 0, SelPriceMax = 0, SelPriceMinLot = 0, SelPriceMaxLot = 0;


int

BuyPriceMaxTic = 0, BuyPriceMinTic = 0, SelPriceMaxTic = 0, SelPriceMinTic = 0;


double

op = 0, lt = 0, order_lots = 0;


int

tk = 0, b = 0, s = 0;

price = 0;tp = 0;


for(int i = OrdersTotal() - 1; i >= 0; i--)

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

if(OrderMagicNumber() == Magic)

if(OrderSymbol() == Symbol() && OrderType() == otype)

{

op = NormalizeDouble(OrderOpenPrice(), Digits())

lt = NormalizeDouble(OrderLots(), 2);

tk = OrderTicket();

if(otype == OP_BUY)

{

b++;

if(op > BuyPriceMax || BuyPriceMax == 0)

{

BuyPriceMax = op;

BuyPriceMaxLot = lt;

BuyPriceMaxTic = tk;

}

if(op < BuyPriceMin || BuyPriceMin == 0)

{

BuyPriceMin = op;

BuyPriceMinLot = lt;

BuyPriceMinTic = tk;

}

}

if(otype == OP_SELL)

{

s++;

if(op > SelPriceMax || SelPriceMax == 0)

{

SelPriceMax = op;

SelPriceMaxLot = lt;

SelPriceMaxTic = tk;

}

if(op < SelPriceMin || SelPriceMin == 0)

{

SelPriceMin = op;

SelPriceMinLot = lt;

SelPriceMinTic = tk;

}

}

if (otype == OP_BUY || otype == OP_SELL)

{

price += OrderOpenPrice() * OrderLots();

order_lots += OrderLots();

}

}

//*************************************************************//

double AwerageBuyPrice = 0, AwerageSelPrice = 0, avg_price = 0;

if(b >= 2 && Drawdown >= DrawdownClosingMinMaxOrder)

AwerageBuyPrice = NormalizeDouble((BuyPriceMax*BuyPriceMaxLot + BuyPriceMin*BuyPriceMinLot)/

(BuyPriceMaxLot + BuyPriceMinLot) + TakeProfitMinMaxOrder* Point(), Digits());

if(s >= 2 && Drawdown >= DrawdownClosingMinMaxOrder)

AwerageSelPrice = NormalizeDouble((SelPriceMax * SelPriceMaxLot + SelPriceMin * SelPriceMinLot)/

(SelPriceMaxLot + SelPriceMinLot) - TakeProfitMinMaxOrder* Point(), Digits());

if (Drawdown < DrawdownClosingMinMaxOrder)

avg_price = NormalizeDouble(price / order_lots, Digits);

//*************************************************************//

for(int i = OrdersTotal() - 1; i >= 0; i--)

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

if(OrderMagicNumber() == Magic)

if(OrderSymbol() == Symbol())

{

op = NormalizeDouble(OrderOpenPrice(), Digits())

tp = NormalizeDouble(OrderTakeProfit(), Digits())

lt = NormalizeDouble(OrderLots(), 2);

tk = OrderTicket();


if(otype == OP_BUY && b >= 2 && Drawdown >= DrawdownClosingMinMaxOrder)

{

if(tk == BuyPriceMaxTic || tk == BuyPriceMinTic)

if(Bid < AwerageBuyPrice && tp != AwerageBuyPrice)

if(!OrderModify(tk, op, OrderStopLoss(), AwerageBuyPrice, 0, clrRed))

Print("OrderModify error #", GetLastError());


if(tk != BuyPriceMaxTic && tk != BuyPriceMinTic && tp != 0)

if(!OrderModify(tk, op, 0, 0, 0, clrRed))

Print("OrderModify error #", GetLastError())

}

if(otype == OP_SELL && s >= 2 && Drawdown >= DrawdownClosingMinMaxOrder)

{

if(tk == SelPriceMaxTic || tk == SelPriceMinTic)

if(Ask > AwerageSelPrice && tp != AwerageSelPrice)

if(!OrderModify(tk, op, OrderStopLoss(), AwerageSelPrice, 0, clrRed))

Print("OrderModify error #", GetLastError());


if(tk != SelPriceMaxTic && tk != SelPriceMinTic && tp != 0)

if(!OrderModify(tk, op, 0, 0, 0, clrRed))

Print("OrderModify error #", GetLastError());

}

if (Drawdown < DrawdownClosingMinMaxOrder)

if (otype == OP_BUY) tp = NormalizeDouble (avg_price + TakeProfitGroupOrder*Point, Digits);

if (otype == OP_SELL) tp = NormalizeDouble (avg_price - TakeProfitGroupOrder*Point, Digits);

{

if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0))

Print("Orders modified successfully!");

else Print("Order modification error!");

}

}

}

The result is as follows: modification of group orders up to the allowable drawdown level is done in a normal way and after the allowable drawdown level they are averaged and close min and max as expected,

But when the drawdown has decreased, the new TakeProfit does not want to be set.

Here is the log with error codes.

If you do not know what to do with this error, don't worry, I will help you!

 
EVGENII SHELIPOV #:

Good day to all!!!!

Use

 
MakarFX #:

Use

Can you be more specific?

Reason: