Hello, dear readers. Today we get acquainted with the operators of cycles. And write a new expert.
3.1. General information about the cycles
The cycle - it is the operator who repeats the fragment program, a prisoner in the body of the cycle until the work is not a condition set by the user. Cycles are often used for working with arrays, arrays vnashem case of quotations or the value of indicators.
(c [0] + c [1] + c [2]) / 3 - is a simple average of the three prices, or simply moving average with a period averaging 3. But things are much harder, if you want to take a simple average of the period 30, it is much easier to use design types:
for i = 0 to 30
(sr = sr + c [i];);
sr = sr/30;
Also, the cycles will allow you to select the desired item from a large array of data. For example, often need to find the maximum or minimum High Low, over the last few bars, to be placed stoplossa.
Find the minimum Low, to install stoplossa to Long. Search will be from the last 10 bars (formed).
MinL = L [1];
For i = 1 to 10
(If L [i]
Now, while it is necessary to address in detail the cycles of vMQLII.
3.2. For Cycle
Cycle For ensures compliance with regulations, prisoners in the body of a user defined cycle, the number of times.
for i = 1 to 10 begin
/ / Body cycle
end;
I - this is a variable, which will increase by one, at each iteration cycle.
In this example, the initial value of the variable equal to 1, the final 10, that is, the cycle will be 10 times the body to perform the cycle. Initial and final value can be any, but of course there must be more. If you want to be a cycle otschityval variable in the other side (to reduce), instead of the keyword you want to use To Downto.
for i = 10 downto 1 begin
/ / Body cycle
end;
This cycle is also executed 10 times, only variable will be reduced from 10 to 1.
3.3. While Cycle
This cycle is different from the For the fact that the number of iterations is not known in advance. The body of the cycle is done until the condition cycle.
while a> b begin
/ / body cycle
end;
a> b - this is the cycle.
3.4. Instruction Break
Instruction Break prematurely terminates execution cycle For or While. This is true if the cycle is used to search for any item, and it was found. This instruction can only be used in the body of the cycle. If several cycles of investment in each other, it was suspended next cycle (a cycle in which the body of instruction attached directly).
for i = 1 to 100
(If l [i]> l [i +1] and l [i +1]
Instructions Continue prematurely terminates the current iteration and starts doing the cycle again. This instruction applies, for example, is already clear that at this stage of the desired item and no need to go further, not executing some instructions in the body of the cycle.
3.6. Expert
Today we will write an expert for the game at turning candlelight
Stoplossy rasstavlyaem for long tenyam plus the specified number of points.
/ * [[
Name: = Expert3
Author: = Fxtest.ru
Link: = forextimes.ru
Lots: = 1.00
Stop Loss: = 20
Take Profit: = 40
Trailing Stop: = 0
]] * /
defines: tenmax1 (10), tenmin1 (5), telodo1 (5); var: tenmax (0), tenmin (0), telodo (0);
/ / domnozhaem all the variables are not the price of the item
tenmax = tenmax1 * point; / / long shadow
tenmin = tenmin1 * point; / / short shadow
telodo = telodo1 * point; / / body of the bar before turning candles
if TotalTrades = 1 then exit; / / exit if there is an open position
if ((o [4]-c [4])> telodo and (o [3]-c [3])> telodo)) or (o [3]-c [3])> 2 * telodo then (
/ / 2, or an average of 2 times the requirement for the purchase of the existence of nizhodyaschego trend
/ / 2 are not short of candles, or last longer bear
if o [2] = c [2] and (h [2]-o [2])
(SetOrder (op_buy, 1, ask, 3, l [2]-StopLoss * point, bid + takeprofit * point, green););
);
if ((c [4]-o [4])> telodo and (c [3]-o [3])> telodo) or ((c [3]-o [3])> telodo * 3) then (
/ / condition for the sale of the existence of 2 vozhodyaschego trend is not short of candles, or last long bull
if o [2] = c [2] and (o [2]-l [2])
Halhalyan Arthur
fxtest.ru artur@fxtest.ru
fxtest.ru artur@fxtest.ru
No comments:
Post a Comment