Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions MtApi5/MtApi5Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,30 @@ public void TesterStop()
SendCommand<object>(ExecutorHandle, Mt5CommandType.TesterStop);
}

///<summary>
///Deposits money to the account of the tested Expert Advisor.
///Works only in the strategy tester (see IsTesting); fails with an error when the Expert Advisor runs on a live chart.
///</summary>
///<param name="money">Deposited sum of money.</param>
///<returns>true if successful, otherwise false.</returns>
public bool TesterDeposit(double money)
{
Dictionary<string, object> cmdParams = new() { { "Money", money } };
return SendCommand<bool>(ExecutorHandle, Mt5CommandType.TesterDeposit, cmdParams);
}

///<summary>
///Withdraws money from the account of the tested Expert Advisor.
///Works only in the strategy tester (see IsTesting); fails with an error when the Expert Advisor runs on a live chart.
///</summary>
///<param name="money">Withdrawn sum of money.</param>
///<returns>true if successful, otherwise false.</returns>
public bool TesterWithdrawal(double money)
{
Dictionary<string, object> cmdParams = new() { { "Money", money } };
return SendCommand<bool>(ExecutorHandle, Mt5CommandType.TesterWithdrawal, cmdParams);
}

#endregion // Common Functions

#region Object Functions
Expand Down
5 changes: 4 additions & 1 deletion MtApi5/MtProtocol/Mt5CommandType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ internal enum Mt5CommandType
OrderCheck = 303,
Buy = 304,
Sell = 305,
GetSymbols = 306
GetSymbols = 306,

TesterDeposit = 370,
TesterWithdrawal = 371
}
}
2 changes: 2 additions & 0 deletions TestClients/MtApi5TestClient/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@
<Button Command="{Binding GetLastErrorCommand}" Content="GetLastError" Margin="2"/>
<Button Command="{Binding ResetLastErrorCommand}" Content="ResetLastError" Margin="2"/>
<Button Command="{Binding TesterStopCommand}" Content="TesterStop" Margin="2"/>
<Button Command="{Binding TesterDepositCommand}" Content="TesterDeposit" Margin="2"/>
<Button Command="{Binding TesterWithdrawalCommand}" Content="TesterWithdrawal" Margin="2"/>
</WrapPanel>

<Button Grid.Row="1" Content="UnlockTicks" HorizontalAlignment="Left" Margin="5" Command="{Binding UnlockTicksCommand}"/>
Expand Down
18 changes: 18 additions & 0 deletions TestClients/MtApi5TestClient/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class ViewModel : INotifyPropertyChanged
public DelegateCommand PrintCommand { get; private set; }
public DelegateCommand AlertCommand { get; private set; }
public DelegateCommand TesterStopCommand { get; private set; }
public DelegateCommand TesterDepositCommand { get; private set; }
public DelegateCommand TesterWithdrawalCommand { get; private set; }

public DelegateCommand TimeCurrentCommand { get; private set; }

Expand Down Expand Up @@ -456,6 +458,8 @@ private void InitCommands()
GetLastErrorCommand = new DelegateCommand(ExecuteGetLastError);
ResetLastErrorCommand = new DelegateCommand(ExecuteResetLastError);
TesterStopCommand = new DelegateCommand(ExecuteTesterStop);
TesterDepositCommand = new DelegateCommand(ExecuteTesterDeposit);
TesterWithdrawalCommand = new DelegateCommand(ExecuteTesterWithdrawal);

ChartOpenCommand = new DelegateCommand(ExecuteChartOpen);
ChartTimePriceToXYCommand = new DelegateCommand(ExecuteChartTimePriceToXY);
Expand Down Expand Up @@ -1336,6 +1340,20 @@ private void ExecuteTesterStop(object obj)
AddLog("TesterStop: executed.");
}

private async void ExecuteTesterDeposit(object obj)
{
const double money = 1000;
var retVal = await Execute(() => _mtApiClient.TesterDeposit(money));
AddLog($"TesterDeposit: money = {money}; result = {retVal}");
}

private async void ExecuteTesterWithdrawal(object obj)
{
const double money = 1000;
var retVal = await Execute(() => _mtApiClient.TesterWithdrawal(money));
AddLog($"TesterWithdrawal: money = {money}; result = {retVal}");
}

private async void ExecuteTimeCurrent(object o)
{
var retVal = await Execute(() => _mtApiClient.TimeCurrent());
Expand Down
Binary file modified mq5/MtApi5.ex5
Binary file not shown.
35 changes: 34 additions & 1 deletion mq5/MtApi5.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ int preinit()
ADD_EXECUTOR(304, Buy);
ADD_EXECUTOR(305, Sell);
ADD_EXECUTOR(306, GetSymbols);


ADD_EXECUTOR(370, TesterDeposit);
ADD_EXECUTOR(371, TesterWithdrawal);

return (0);
}

Expand Down Expand Up @@ -2982,6 +2985,36 @@ string Execute_TesterStop()
return CreateSuccessResponse();
}

string Execute_TesterDeposit()
{
if (!IsTesting())
{
Print("WARNING: function TesterDeposit can be used only for backtesting");
return CreateErrorResponse(-1, "TesterDeposit can be used only for backtesting");
}

GET_JSON_PAYLOAD(jo);
GET_DOUBLE_JSON_VALUE(jo, "Money", money);

bool retVal = TesterDeposit(money);
return CreateSuccessResponse(new JSONBool(retVal));
}

string Execute_TesterWithdrawal()
{
if (!IsTesting())
{
Print("WARNING: function TesterWithdrawal can be used only for backtesting");
return CreateErrorResponse(-1, "TesterWithdrawal can be used only for backtesting");
}

GET_JSON_PAYLOAD(jo);
GET_DOUBLE_JSON_VALUE(jo, "Money", money);

bool retVal = TesterWithdrawal(money);
return CreateSuccessResponse(new JSONBool(retVal));
}

string Execute_TerminalInfoInteger()
{
GET_JSON_PAYLOAD(jo);
Expand Down