工作已完成
![](https://c.mql5.com/i/avatar/avatar_na2.png)
指定
The strategy is quite simple as It uses two charts. The first 'Slow candle history' chart determines a trend, and the other
'Fast candle chart' chart is used for moving average to enter in a market when the MA crosses a calculated signal price. if a close rate of
previous candle from 'slow candle history' chart is closed above the open price of the candle, then the market is bullish. If a close rate of
previous candle from 'slow candle history' chart is closed below the open price of the candle, then the market is bearish.
The strategy calculates a size of previous candle from 'slow candle history' chart. After that the strategy takes the percentage
part of that size and subtracts it from the open rate of the candle. As a result the strategy gets a signal price.
When the moving average crosses the signal price the strategy will open a position. If the signal price is crossed from top to bottom the strategy
will open a buy position. And vise versa if the signal price is crossed from bottom to top, the strategy will open a sell position.
Maximum currently opened positions are no more then one
The strategy settings:
'% of Slow Previous Bar Size' - percentage part of the previous candle from 'slow candle history' chart.
The strategy uses the following formula:
diff = previous_close_price - previous_open_price (from 'slow candle history' chart) ;
a = diff * Percentage_part;
signal_price = today_open_price - a;
there are defined s/l n t/p and prevention of opening more than one position at a time in below existing ActTrader script
i would like to add some advanced features regarding money preservation and runing profit optimisation instead of as now fixed s/l t/p. this can be done in a second step as i do have some code tht othewise works well
ACTTRADER SCRIPT WORKING:
const
StrategyName = 'super_combat';
StrategyVersion = '1.0';
var
SlowHistory, FastHistory: TCandleHistory;
Account: TAccount;
Amount, Amount_sell, Percent: Double;
MA:TIndicatorScript;
MA_set:TMovingAverage;
Stop, Limit, TraderRange:integer;
//////////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnCreate;
begin
Settings.AddCandleHistory(@SlowHistory, 'Slow Candle History', '', CI_1_Day, 10);
Settings.AddCandleHistory(@FastHistory, 'Fast Candle History', '', CI_1_Hour, 100);
FastHistory.OnNewCandleEvent:= @OnNewCandle;
FastHistory.OnNewRateEvent:= @OnNewRate;
Settings.AddAccount(@Account, 'Account', '');
Settings.AddFloat(@Amount, 'Buy Amount (lots)', 1);
Settings.SetFloatRestrictions(@Amount, 0, 10000, 1);
Settings.AddFloat(@Amount_sell, 'Sell Amount (lots)', 1);
Settings.SetFloatRestrictions(@Amount_sell, 0, 10000, 1);
Settings.AddFloat(@Percent, '% of Slow Previous Bar Size', 25);
Settings.SetFloatRestrictions(@Amount, 0, 100, 1);
Settings.AddInteger(@Stop, 'Stop (pips)', 20);
Settings.SetIntegerRestrictions(@Stop, 0, 10000, 1);
Settings.AddInteger(@Limit, 'Limit (pips)', 60);
Settings.SetIntegerRestrictions(@Limit, 0, 10000, 1);
Settings.AddInteger(@TraderRange, 'Trader Range', 2);
Settings.SetIntegerRestrictions(@TraderRange, 0, 10000, 1);
MA:= TIndicatorScript.Create(FastHistory, 'Moving Average', 'Moving Average');
MA_set:= MA.VariableValue('MA');
MA_set.Period := 1;
MA_set.AverageType := makSimple;
MA_set.CalculationType := cbClose;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnNewRate;
var signal_rate:double;
begin
signal_rate:= SlowHistory.Last(0).Open - ((SlowHistory.Last(1).Close - SlowHistory.Last(1).Open) * (Percent / 100));
if (MA.GetGraph(0).Last(1) > signal_rate) and (MA.GetGraph(0).Last(0) < signal_rate) and (NoPositions(bsBuy)) then begin
CreateOrder(FastHistory.Instrument, Account, Amount, bsBuy,
FastHistory.Instrument.Sell - Stop * FastHistory.Instrument.PointSize,
FastHistory.Instrument.Sell + Limit * FastHistory.Instrument.PointSize, TraderRange, StrategyName);
log('buy signal rate = ' + FloatToStr(signal_rate));
end;
if (MA.GetGraph(0).Last(1) < signal_rate) and (MA.GetGraph(0).Last(0) > signal_rate) and (NoPositions(bsSell)) then begin
CreateOrder(FastHistory.Instrument, Account, Amount_sell, bsSell,
FastHistory.Instrument.Buy + Stop * FastHistory.Instrument.PointSize,
FastHistory.Instrument.Buy - Limit * FastHistory.Instrument.PointSize, TraderRange, StrategyName);
log('sell signal rate = ' + FloatToStr(signal_rate));
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Defines is there any open Sell/Buy positions, opened by this strategy
function NoPositions(pos:TBuySell): boolean;
var i:integer;
begin
result:= true;
for i:= TradeList.Count-1 downto 0 do
if (TradeList.Get(i).Tag = StrategyName) and (TradeList.Get(i).BuySell = pos) then
result:= false;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////