[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 995

 
Hi all, advise if it is possible (if the price goes up, the order remains open, but if the price has fallen in 2 points, close the order) advise how to do it correctly
if (iMomentum(NULL,0,-2,PRICE_HIGH,0)) 
      {
      OrderClose(OrderTicket(),OrderLots(),0,Bid,Violet);
 
artmedia70:

I can't figure it out... Why do you need to calculate the average spread over n-number of bars of history in the function of defining trading criteria?

If you're going to use functions from the UK textbook, then it would make more sense to do it in the Events() function.

That's just it, look at how SK suggests to track the change in the broker's StopLevel. What prevents you from exactly the same way to track the change of spread and, if there is one, enter the next value in the array. Well, and when filling the array calculate its "average temperature in the hospital" (c) SK ...

The idea is that at different times of the day there are different spreads and sometimes my trading system will trade successfully at an average spread of say 12 points, and at spread of 6 points it will be losing and vice versa, if I adjust it to spread 6, it will lose at spread 12, i.e. the levels of pending orders depends on this parameter, I'll post all my ideas later, but now I have to do something stepwise, and I also faced with Freeze level for the first time today, so what does it mean? if i opened an order with a take and a stop and it is in the market, it is in the plus by 100 pips in five-digits and the take was originally at 150 pips, but now it is in the plus, i can't stop loss or take profit if i set stop-loss and take-take and if the price is near the zone i cannot stop loss or take profit. as a result, the system worked out correctly, I gave a reversal command, but the terminal failed and the price went down without taking a Sell position and without taking a Buy position

How do you fight it?

 
ex_kalibur:

The idea is that at different times of the day the spread is different, and it may happen that with an average spread, my trading system will trade successfully at a spread of, say, 12 points, and at a spread of 6 points it will lose money. If I adjust the spread for 6 then at 12 points it will lose money, Ie this parameter depends on the levels of pending orders, I'll post the entire plan later, but now I have to do something stepwise, and today I also faced with Freeze level for the first time, if i opened an order with a take and a stop and it is in the market, it is in the plus by 100 pips in five-digits and the take was originally at 150 pips, but now it is in the plus, i can't stop loss or take profit if i set stop-loss and take-take and if price is near the profit zone, i cannot close it by market and fix it. as a result, the system worked out correctly, I gave a reversal command, but the terminal failed and the price went down without taking a Sell position and without taking a Buy position

How may I fight it?

Sounds like you're in the right place...
 
I've only been programming for three days, I can't figure out how to write the trailing stop part of the program.

The problem is that everything works, BUT! it moves the stop loss both to one side and to the other, what should I add so that it moves the stop loss only to the side of the open trade!?

Here is basically mine:

if (Ticket> 0)
{
if (Opn_B == true)
{
SL = Ask - TS*Point;
Ticket= OrderModify(Ticket,Price,SL,TP,0);
}
if (Opn_S == true)
{
SL = Ask + TS*Point;
Ticket= OrderModify(Ticket,Price,SL,TP,0);
}
}
 

ex_kalibur thanks for the inbox, I'll email you sometime.

 
ZahvatkiN:

ex_kalibur thanks for the inbox, I'll email you sometime.

Excuse me?
 

Good evening!

Can you tell me how I can export data from a chart(indicator values) from Metatrader 4 to Exel?

I would be glad to get help and tips :)

 
Print will help you :)
 

Dear artmedia70, I am very grateful that you are actively helping in this thread, the following writings are mainly addressed to you, but if there are more professionals, please do not go by and help, it turned out as in a fairy tale the further into the woods the more firewood, as a result of winding up I hit a wall, and I really need help, I hope this strategy will be implemented and many beginners will gain experience in a consistent and effective programming

the problem is this:

1. Find the Low and High variables (the process of finding each of them remains different)

2. it is necessary to calculate the average spread for the last N ticks (the variable N in the external one)

3. Assuming High - Low > than average spread in k parts of the channel width (e.g. 2/3 or minimum 1/3 of the channel width)

4. Once these conditions are met, pending orders are placed:

- above the line High - Sell

- below the line Low - Bay

Orders are placed to both sides using the grid:

*The closest Sell order will be the minimum volume, and is placed if possible at the level of High,

* The next order will be placed at a distance of High + a certain number of points (for example: High + (High - Low))

* The total number of orders should be set in an external variable, in this case each order does not have an equal volume (for example the first 0.1, the second 0.2, the third 0.3 etc. Here we assume different methods of increasing the volumes in arithmetic progression or in geometric progression, we will decide here later, respectively, this block should be set in a separate function)

* StopLoss is exposed as follows: in external settings we specify the desired SL, then on the first (it is the smallest) SL equals StopLoss (from settings), each subsequent StopLoss will be equal to the same value as on the first one (for 0,1 = 60 points, for 0,2 = 40 points) i.e. in case of a trigger of a StopLoss on the smallest order all orders will be closed at once

* Take Profit is equal to (High -Low)* Point + Open Price

*Market closing conditions:

open Bay-

If the order is in profit, the High level has changed and become lower than the previous value, Bid>= High, StopLewel allows closing the order, then all the open orders of the Bay type are closed, starting from the largest volume of our instrument

*Conditions for opening according to the market:

if Bay ==0, and at the same time Bid < Low and at the same time Ask < High + average spread, then we open with the minimum allowed volume and delete the pending order of this type with the minimum volume (if conditions allow)

if during the trade, a new pending order opens with a bigger value than the very first one, and closes at the same close price, we open a new pending order with the same volume, at the same price that was closed (if conditions allow) and if placing a pending order is impossible, and after the last order closes, the price crosses again the open price of the last closed order then

we go back to the market with the same volume and at the same price with + slippage

* After the first order (it is the order with the minimum volume) is closed, all the pending buy orders will be deleted, it is assumed that there should be no more open orders, then the order is recalculated and the grid is being thrown again.

* All the time open orders are being calculated for the opposite order type and respectively a grid with the opposite order type is being thrown.

* Opening of opposite orders is not allowed while the first order (with the minimum volume) is open.

5. calculation of the lot volume, allowed either fixed or percentage in the settings:

If all orders have a fixed volume - all orders with one fixed volume

-with fixed - the total volume of all orders in case of closing the grid (series) by a stop loss, should not exceed the loss in % permitted.

accordingly, the volumes are calculated in the order that the maximal one is the farthest to the current price and with the minimum stoploss and the ones closest to the price are the minimal ones (

Example series 0.1\0.2\0.3\0.4\0.5 look like this - if we have enough money and the % allows to open in this order

series 0.1\0.1\0.1\0.2\0.3 - in this case we have not enough money for the whole series

6. block of minimum deposit calculation

*here occurs calculation of possible maximum loss is calculated on the basis of values of variables High,Low it is considered that all pending orders will be opened, and will be closed on Stop Loss, accordingly the given loss should make some percentage of the deposit, about what after calculations the trader receives a message:

"with the chosen risk %, if orders are closed by a stop loss, you will incur a loss of ...",

or "there is not enough money to implement one stop series, Expert Advisor is not working".

7. I have only one function: Keeping track of events, informational, I would like to see errors as if they were in a book.

8. and probably the last, some "button" or a special function that when you click on it (or change settings), all pending orders of the opposite type from the open (if the market is buy, then all are removed) are deleted, and the expert works until the series is closed

i would like to ask you to write a program according to the book structure https://book.mql4.com/ru/build/index.

to do this in this post, I will attach all the files from the book, and in each of these files will begin work, after completion of each individual file will be saved and also attached to the public, on completion of the coding program will also be posted on this forum

i warn you right away that this idea is solely cognitive, educational nature, and does not guarantee that on completion of the expert will be profitable, it concerns all polyps who spend days and hours looking for grails, and want to crush another's ass a hedgehog ))))

My personal goal on completion of programming is to learn to code in this structure, I mean with all the rules: comments, individual functions, external files, work with the libraries and stuff like that.

 

The 1st stage is very important, I think it's even basic, it's a correctly formulated terms of reference, accessible, so that the programmer understands what is needed from him

So I'm waiting for comments on my outline, let's write a correct ToR and then we'll start