I will write an advisor free of charge - page 166

 
Hello, I would like to ask your advice. Can you please advise how to change my Expert Advisor so that it trades not against the trend, but on the contrary, follows the trend? I opened new positions with increasing lot by trend.

Ilan 2.0

 
kammann659 #:
Hello, I would like to ask your advice. Can you please advise how to change my Expert Advisor so that it trades not against the trend, but on the contrary, follows the trend? I opened new positions with increasing lot by trend.

Ilan 2.0

Hello, it is possible.

 

Good afternoon. I trade with pending orders (sellstops, bystops). I want to ask to write a part of the code where the condition is fulfilled - all pending orders that are at a distance (x) from the current price are deleted. That is, a "small set" of pending orders will constantly "follow" the current price.

Of course, this idea can be implemented in some other way, for example, to control the amount of Sell and Buy stops and at the same time trawl them so that the longest ones are moved closer to the current price.


It seems to me to be the same, but I like the first variant. For the first case, the distance x should be variable in the condition.

I understand that this is not much code. I have tried to understand what and how it should be described, I've looked and studied similar EAs, but I don't have enough brains for that.

Thanks.

 

Hello,@Andrey Kuharev.

Are you looking for an MT5 or MT4?

 
Yuriy Bykov #:

Hello,@Andrey Kuharev.

Are you looking for an MT5 or MT4?

MT4
 

I reread your description again and realised that I probably don't understand exactly what needs to be done. It looks like you need the following:

  • A script that you will manually run on the chart when needed, or a function that you can insert into your code (or is it an EA that runs all the time and removes unnecessary orders?).
  • It has one parameter X - the number of pips (an integer)
  • It will delete the pending orders (only BuyStop and SellStop?) on the symbol of the chart to which it is applied (or on all symbols? In this case, the X should be set for each symbol?)
  • A pending order for the necessary symbol of the required type will be deleted if the distance between its open price and the current price is greater than X
  • It is not its task to place orders

Correct me if I am wrong.

 
Yuriy Bykov #:

I reread your description again and realised that I probably don't understand exactly what needs to be done. It looks like you need the following:

  • A script that you will manually run on the chart when needed, or a function that you can insert into your code (or is it an EA that runs all the time and removes unnecessary orders?).
  • It has one parameter X - the number of pips (an integer)
  • It will delete the pending orders (only BuyStop and SellStop?) on the symbol of the chart to which it is applied (or on all symbols? In this case, the X should be set for each symbol?)
  • A pending order for the necessary symbol of the required type will be deleted if the distance between its open price and the current price is greater than X
  • It is not its task to place orders

Correct me if I'm wrong.

If i see a different order, then it needs to be placed again, in exactly the same way i see a different order with different line of profit/loss. I will do it myself, not to distract clever people with my nonsense. For better understanding, here is the code of the "Expert Advisor" in which I want to insert the function of deletion. In my EA, I marked the X parameter as extern double v_util = 50; // distance from the current price to a pending order to be deleted

//+------------------------------------------------------------------+
//|Pending orders.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link"https://www.mql5.com"
#property version "1.00"
#property strict
//------- External EA parameters -----------------------------------------+
extern double delitel_Equity_lots = 1400000; // Divider to determine work lot.
extern double schag = 2; // step of pending order opening from the current price
extern double v_util = 50;// distance from the current price to the deleted pending orders
extern int StopLoss = 10000;
extern int TakeProfit = 5;
extern int MagicBuy = 1111111; // MagicNumber for BUY orders
extern int MagicSell = 2222222; // MagicNumber for SELL orders
// //+------------------------------------------------------------------+
void OnTick()

{double Lots = NormalizeDouble(AccountBalance()/delitel_Equity_lots, 2); // Position volume.

OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(Ask+schag*_Point,_Digits) ,0,NormalizeDouble(Ask-(StopLoss-schag)*_Point,_Digits),
NormalizeDouble(Ask+(TakeProfit+schag)*_Point,_Digits),MagicBuy); // Open BuyStop
Print (GetLastError()); // Error message
OrderSend(Symbol(),OP_SELLSTOP,Lots,NormalizeDouble(Bid-schag*_Point,_Digits),0,NormalizeDouble(Bid+(StopLoss-schag)*_Point,_Digits),
NormalizeDouble(Bid-(TakeProfit+schag)*_Point,_Digits),MagicSell;)// Open SellStop
Print (GetLastError()); // Error message
}
//+------------------------------------------------------------------+

Everything is simple, no intricacies. I understand that you have to pay for all sorts of contrivances, no one will invent super strategies and super codes for free. I want to test the work in this direction for now and ask to do a simple removal, nothing more...the only thing is, if it is not too long and not too difficult, you could add a parameter - the distance between the stopper, then it would be perfect. But I understand that all this work and time...so at least the removal. Thank you!

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.04.13
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
This is what came out. I hope this helps to test the operation.
Files:
Pending.mq4  10 kb
 
Yuriy Bykov #:
This is what we got. I hope this helps to test the operation.

Please advise, and plus 10 here:

double minOpenPriceBuy = 1e+10;
double maxOpenPriceBuy = 0;
double minOpenPriceSell = 1e+10;
double maxOpenPriceSell = 0;

, this is the ten that extern int delta = 10;

 

No, it's a different form of writing the number 10000000000, so you don't have to write it that way

double minOpenPriceBuy = 10000000000;

...

Reason: