İş tamamlandı
![](https://c.mql5.com/i/avatar/avatar_na2.png)
![](https://c.mql5.com/i/avatar/avatar_na2.png)
İş Gereklilikleri
1) Idea
Based on all of the most recent x (e.g. 30) number of bars, (x = input variable)
Calculate at start of each bar:
MaxOpenClose = the maximum of ( maximum of Open, maximum of Close) of all of most recent x bars
MinOpenClose = the minimum of ( minimum of Open, minimum of Close) of all of most recent x bars
Level_1 = ( MaxOpenClose - MinOpenClose ) * Ratio_1
Level_2 = ( MaxOpenClose - MinOpenClose ) * Ratio_2
LevelCounter_1 = Number of times, in the most recent x number of bars, the High was >= Level_1
LevelCounter_2 = Number of times, in the most recent x number of bars, the Low was <= Level_2
Trading is done based on the ratio of LevelCounter_1 and LevelCounter_2
LevelCounter_1 and LevelCounter_2 will always be >= 0 and <= x
Output all these values to the journal window with each bar.
"most recent" excludes the current "in progress" bar
2) Trading signals:
if LevelCounter_1 > LevelCounter_2 ; buy signal
if LevelCounter_1 <= LevelCounter_2 ; sell signal
3) Positions are opened at the market price; subject to that there are no more open positions as specified by the MaxOpenBuyOrders input parameter for Buys
and MaxOpenSellOrders for sell orders.
A buy position is opened if LevelCounter_1 > LevelCounter_2 for lot size = LotSize ( LotSize = input parameter)
A sell position is opened if LevelCounter_1 < LevelCounter_2 for lot size = LotSize ( LotSize = input parameter)
If the order cannot be executed successfully for whatever reason, try again in each tick, for the next 10 ticks, to do again.
4) Additional filter for position opened
Minimum average volume of last x number of bars >= MinAvgVolumeToOpen (input parameter)
5) Positions are closed when
a) StopLoss (input parameter) is reached.
or b) ProfitTarget (input parameter) is reached.
6) Position management
TrailingStop is used; while the price move in the profit direction, the stop loss should trail at the StopLoss (input parameter) value.
The Stop Loss is never moved towards the loss direction.
The robot should work on any forex pair, any time frame.
Inputs:
x // Number of most recent bars to take into consideration,e.g. 10
Ratio_1 // Used in calculation
Ratio_2 // Used in calculation
MaxOpenBuyOrders // e.g. 5
MaxOpenSellOrders // e.g. 5
LotSize // e.g. 0.01
StopLoss // e.g. 30
ProfitTarget // e.g. 100
MinAvgVolumeToOpen // e.g. 40