مطلوب تغيير اعدادات لاستراتيجية الماكد بحيث يسوي امر بيع اذا تحقق الشرط للاكسبيرت الاول
ولاكسبيرت الثاني يسوي امر شراء
اي ان المطلوب اكسبيرتين ... اي خانه يتم تعديلها
//================================================== ================================================== ===
// Please do not edit this script. In order to make any changes, clone it and save it under a new name
//================================================== ================================================== ===
//================================================== ========================================
// This strategy uses the MACD indicator. It opens a Buy position when the MACD rises above
// its Signal line, and a Sell position, when the MACD falls below its Signal line.
// It also outputs a message into the log when a position is opened.
//================================================== ========================================
const
StrategyName = 'MACD Strategy';
var //declaration of the variables
History: TCandleHistory;
Account: TAccount;
Amount, Point: Double;
Stop, Limit, TraderRange: Integer;
MACD: TIndicatorMACD;
procedure OnCreate;
begin
AddCandleHistorySetting(@History, 'History', '', CI_30_Minutes, 100); //setting up the chart history
History.OnNewCandleEvent := @OnNewCandle; //indicating the procedure to run when a new candle opens
AddAccountSetting(@Account, 'Account', ''); //the account number
AddFloatSetting(@Amount, 'Amount(Lots)', 1); //the number of lots
AddIntegerSetting(@Stop, 'Stop', 20); //setting up stop in pips
AddIntegerSetting(@Limit, 'Limit', 30); //setting up limit in pips
AddIntegerSetting(@TraderRange, 'Trader Range', 0); //setting up the trader range in pips
MACD := TIndicatorMACD.Create(History, 'MACD'); //creating the MACD indicator
MACD.PeriodShorterEMA := 12;
MACD.PeriodLongerEMA := 26;
MACD.PeriodForSignal := 9; //setting up the MACD indicator periods
end;
// this procedure runs when a new candle opens
procedure OnNewCandle;
begin
Point := History.Instrument.PointSize;
// if the MACD rises above its Signal line
if (MACD.Graph.Last(1) > MACD.SignalGraph.Last(1))
and (MACD.Graph.Last(2) < MACD.SignalGraph.Last(2)) then
begin
// output the message into the log
log ('The MACD crossed the Signal line bottom-up. A Buy position opened.');
// open a Buy position
CreateOrder(History.Instrument, Account, Amount, bsBuy,
History.Instrument.Sell - Point*Stop,
History.Instrument.Sell + Point*Limit, TraderRange, 'MACDTrade');
end;
// if the MACD falls below its Signal line
if (MACD.Graph.Last(1) < MACD.SignalGraph.Last(1))
and (MACD.Graph.Last(2) > MACD.SignalGraph.Last(2)) then
begin
// output the message into the log
log ('The MACD crossed the Signal line top-down. A Sell position opened.');
// open a Sell position
CreateOrder(History.Instrument, Account, Amount, bsSell,
History.Instrument.Buy + Point*Stop,
History.Instrument.Buy - Point*Limit, TraderRange, 'MACDTrade');
end;
end;
// this procedure runs when some changes occur in the Open Positions list
procedure OnTradeChange(const Action: TDataModificationType; const Trade: TTrade);
begin
// if a new trade opened
if Action=dmtInsert then
begin
// output the trade information into the log
log('Instrument: ' +Trade.Instrument.Name);
log('Account: ' +Trade.Account.Id);
log('Amount: ' +FloatToStr(Trade.Amount));
log('Open rate: ' +FloatToStr(Trade.OpenRate));
end;
end;

