Metatrader 4 commission and spread - mt4

my question is because of mt4 doesn't introduce commission on the strategy tester when I do my backtest, but there is an option to change spreads according to your needs , is it safe to just add spreads and commission to the spread value an backtest just like the real environment,
Here is an example:
Some brokers offer tight spreads in there pro or ECN accounts tight as 11 mt4 point , and the commission is 0.07usd per 0.01lots ,
Since I don't have the option to add the commission on my mt4 when I backtest why not just say the spreads are spreads= normal spread + commission = 11points(11*0.01) + 0.07=0.18

Related

Time Dashboard - Calculation/Visualization Question (Level of Detail)

I’m reaching out to see if you can help me get unstuck on a Tableau visualization and calculation.
We are trying to calculate and visualize utilization rate as defined as a numerator (“Projects” + “Initiatives” charged time) divided by denominator (Number of timesheets submitted times 40 hours).
The screenshots below detail what is currently occurring vs what we want to show.
Currently
The denominator is understated because it is identifying unique timesheets times 40 hours separately for “Projects & Initiatives” and “Remaining Time” pie chart pieces.
Results in higher inaccurate utilization rate of 73% (50,584 / 69,400). These red numbers are not what we want.
What we want
First screenshot below shows how we want utilization rate to be calculated to result in 69% (50,584 / 73,080). Bold numbers are what we want. I tried playing around with FIXED and INCLUDE Level of Detail calculations, but couldn’t get it to work as intended.
I included more supporting screenshots below to provide more context.
Any guidance would be truly appreciated!
Summary of Issue
Visual
Tableau Visual
Denominator details
This is what we want to see in Tableau.
Denominator manual details
This is the current denominator calculation.
c.ChargeableHours
Here are some relevant key fields. Note that “Time Charged” is the same as “Time_Logged_Project_Total” (Just renamed). Also, we don’t want to use the 73,097 total below as some individuals charge more than 40 hours in some of their weekly timesheets. We want our calculation to max at 40 as indicated in the screenshot above using unique timesheets.
Key Fields

How to make an Expert advisor to enter a trade at an exact price?

I made an EA, it is to enter trade at a particular price. But I notice it is not entering the trade at the exact price, it is entering the trade at price that is 3-5 fractional pips above the specified price. What I want is that the EA enters the trade at the exact price. Can someone help please?
How to make an Expert advisor to enter a trade at an exact price?
Making a trade is a bilateral contract - it has a side that offers you a price ( mediated by your Broker ) and it has a side ( you, in person or represented by an automated code-driven trading-agent ), who accepts a price. All regulated by Terms and Conditions signed / accepted for doing this business.
// ----------------------------------------------------------------------------
// Rule#0: Prices move faster, than the QUOTE-message ever makes it to your CPU
// --------------------------
RefreshRates(); // A MUST DO AS-LATE-AS-POSSIBLE, before placing a tight slippage XTO
// --------------- // A RE-TEST AS-FAST-AS-POSSIBLE if XTO conditions hold
...
// --------------- // GO / NO-GO XTO, always using Normalized values
ticket = OrderSend( Symbol(),
XTO_OrderTYPE,
NormalizeDouble( XTO_volume, LotDigits ),
NormalizeDouble( XTO_price, Digits() ),
MaxSlippage, //---------------------------- BE CAREFULL ON THIS
0, // [XTO_price_SL]
0, // [XTO_price_TP]
ordername,
MagNumber,
0,
clr
);
Time matters, prices move indeed fast. VPS may avoid, but yet a part
Before we get to the type-of-Contract, which decides, how a trade is being executed on the Broker side ( a spot-Buy-Long uses other price-handling than a pending-BuyStop ), first, let's look at the network latency ( how long does the Top-of-the-Book [ToB] price hold, before it is changed and advertised from market to Broker and from Broker to your computer or to VPS computer ( even the best co-located VPS machines are a few hundred meters "farther" on the cable, and "behind" the Broker's machine, thus a few orders of magnitude slower in receiving ToB-QUOTE-updates, than your Broker Server is ).
The ToB-prices hold for way less than 100 ms in steady markets on FX-Majors, yet there are ofter thousands of wild moves during fundamental events, where each [ms] may contain tens, if not hundreds and sometimes thousands ToB-price changes per [ms].
If you insist on having an exact price for a trade, you may use but pending-contracts, not the immediate-price executed orders ( often called at-Market ).
Your Broker Terms and Conditions define the rules for doing this.
Be aware, that even pending-orders may "acquire" a price-slippage, a difference between an "ordered"-price and actually "executed"-price, so again, Terms and Conditions will rule ( SNB flash-crash event was a Tsunami a few years ago, after many Brokers filed for bankruptcy and KMPG and other court-named supervising bodies were liquidating ashes from uncovered pendin-orders for many many years later ), so due Risk-Management is a must and never believe an optimistic assumption a trade-order will get filled at-an-exact-price. There are both technical and legally supported reasons, why this is not always obeyed even for the pending-orders.

Which reinforcement algorithm to use for binary classification

I am new to machine learning, but I've read a lot about Reinforcement Learning in the past 2 days. I have an application that fetches a list of projects (e.g. from Upwork). There is a moderator that manually accepts or rejects a project (based on some parameters explained below). If a project is accepted, I want to send a project proposal and if it is rejected, I'll ignore it. I am looking to replace that moderator with AI (among other reasons) so I want to know which Reinforcement Algorithm should I use for this.
Parameters:
Some of the parameters that should decide whether the agent accepts or rejects the project are listed below. Assuming I only want to accept projects related to web development (specifically backend/server-side) here is how the parameters should influence the agent.
Sector: If the project is in related to IT sector it should have more chances of being accepted.
Category: If the project is in the Web Development category it should have more chances of being accepted.
Employer Rating: Employers having a rating of over 4 (out of 5) should have more chances of being accepted.
I thought Q-Learning or SARSA would be able to help me out but most of the examples that I saw were related to Cliff Walking problem where the states are dependent on each other which is not applicable in my case since each project is different from the previous one.
Note: I want the agent to be self-learning so that if in the future I start rewarding it for front-end projects too, it should learn that behavior. Therefore, suggesting a "pure" supervised learning algorithm won't work.
Edit 1: I would like to add that I have data (sector, category, title, employer rating etc.) of 3000 projects along with whether that project was accepted or rejected by my moderator.
your problem should easily be able to be solved using Q-learning. It just depends on how you design your problem. Reinforcement learning itself is a very robust algorithm that allows an agent to receive states from an environment, and then perform actions given those states. Depending on those actions, it will get rewarded accordingly. For your problem, the structure will look like this:
State
States: 3 x 1 matrix. [Sector, Category, Employer Rating]
The sector state are all integers, where each integer represents a different sector. For example, 1 = IT Sector, 2 = Energy, 3 = Pharmaceuticals, 4 = Automotives, etc.
The category state can also be all integers, where each integer represents a different category. Ex: 1 = Web Development, 2 = Hardware, 3 = etc.
Employer rating is again all integers between 1 - 5. Where the state represents the rating.
Action
Action: Output is an integer.
The action space would be binary. 1 or 0. 1 = Take the project, 0 = Don't take the project.
Reward
The reward provides feedback to your system. In your case, you would only evaluate the reward if the action = 1, i.e., you took the project. This will then allow your RL to learn how good of a job it did taking the project.
Reward would be a function that looks something like this:
def reward(states):
sector, category, emp_rating = states
rewards = 0
if sector == 1: # The IT sector
rewards += 1
if category == 1: # The web development category
rewards += 1
if emp_rating = 5: # Highest rating
rewards += 2
elif emp_rating = 4: # 2nd highest rating
rewards += 1
return rewards
To enhance this reward function, you can actually give some sectors negative rewards, so the RL will actually receive negative rewards if it took those projects. I avoided that here to avoid the further complexity.
You can also edit the reward function in the future to allow your RL to learn new things. Such as making some sectors better than others, etc.
edit: yes, regards to lejlot's comment, it basically is a multi-armed bandit problem, where there is no sequential decision making. The setup of the bandit problem is basically the same as Q-learning minus the sequential part. All your concerned with is you have a project proposal (state), make a decision (action), and then your reward. It does not matter what happens next in your case.

My EA loses money when I breakeven

I have a very successful EA which is designed to move my stop loss to breakeven when I get 50 pips "in the money". So pretty basic stuff, however, I still lose a small amount of money on the trade that hit the new breakeven price - of course the breakeven price being equal to the OrderOpenPrice.
Granted, I don't lose as much as I would if my price were to hit the original S/L but my net profit on trading position that hit the breakeven price was NIL. I've made no modifications to the EA code.
I'm thinking my broker maybe moved the stopLevel figures so my breakeven price can no longer reach the OrderOpenPrice but I can't be sure.
Does anyone have this issue and how would I go about solving this?
Here is the code. The relevant code starts on line 537 ;
https://github.com/indomtrading/ea/commit/5de74283f02ebee634952d5d204e21749ea25714
To reach a B/E-state, there are two distinct processes to watch:
one is the PriceDOMAIN distance between the XTO OrderOpenPrice() and the "new" value one wishes to set a "future" XTO OrderStopLoss().
the other is the Broker-side accrued sum of all Commissions + Fees + Swaps
While
OrderCommission() + OrderSwap() could be inspected explicitly ( as have been accrued and have been a part of "a-just-theoretical" OrderProfit() ), any additional costs, associated by your Broker's "Terms & Conditions" with an XTO on OrderClose() or on any of materialised { OrderStopLoss() | OrderTakeProfit() } does not show up, until the XTO operation is finished and such costs get visible after such position was terminated.
If the EA does not precisely account for both of these principal P/L-drivers in evaluating BreakEven,
it may systematically move your money into losses.
Check both of these in the EA B/E-driving policies against your Broker "Terms & Conditions" so as to avoid the so far observed losses.
Nota Bene:
while the slippage may appear during a live-trading session, the nature of the slippage-mechanics ought be ( sure, outside of the Fundamental major events ) principally symmetric .. sometimes gaining, sometimes loosing a pip or a few. In case your Broker does not exhibit a symmetrical nature, some investigation is in place, but that does not explain a systematically loosing EA-trade automation.
As discussed, when you move your OrderStopLoss() to OrderOpenPrice() it may close with slippage so loss instead of breakeven. In order to fight with that, OrderModify() your OrderStopLoss()to OrderOpenPrice()+2*Point, if there's a small slippage you will have a tick gain or zero
You need to factor in Swap and Commission.

For a particular pair, how to get a total volume of open Long and Short positions on The Exchage?

In MQL4 ( MT4, MT5 ), how do I get the total volume of open Short and Long positions on the Exchange, for a current pair at the current time?
A thing, you ask to get, is called a Level-3 Depth-of-Market, [L3-DoM].
Fact 1: there is not a common way to aggregate the Global DoM, may expect just a per Exchange ( a local, market-making, island ) Local DoM, so forget about seeing anything near the orders of magnitude of the average Global FX turnover, published to be about USD 5,400,000,000,000.00
Fact 2: even the local market-making body ( FX Trading Venue, LP provider, FX Broker et al ) do not expect to receive the Local DoM automatically, as not all bodies aggregate & provide the Local DoM on some public service-provisioning basis.
Fact 3: given some streaming interfaces can provide a Trader a flow of changes on the DoM, one ought expect using a high-frequency processing tools, to handle more than small/large tens ( hundreds/thousands even tens of thousands in peak hours alike NFP events, etc. ) changes per millisecond to happen. Given a professional trading venue is well oiled with sufficient peering with Prime Banks, Institutional LPs ( and perhaps a few DarkPool LPs ), the majors execute in common a Local DoM in the ranges above USD 50,000,000.00 on each of Long and Short sides.
Fact 4: some older updates of MetaTrader Terminal 4 started an add-on panel, called similarly a DoM, but there were no programmatic ways to communicate with such add-on panel/data. More details on this part of history are here.
Fact 5: The proposal, presented in his fairest belief by Daniel, does not provide DoM per-se, but show just your ( a Trader's ) own inventory of positions, placed on the table, not the real DoM landscape.
If interested in more details, do not hesitate to read more posts on DoM and some other animated latency graphs on Top-of-the-Book Price Lifetime to be able to compare FX Brokers timings against LMAX, Currenex or other LP-providers. For detailed LDG/GDF statistics on speed of changes in the L3-DoM near/during NFP announcement, enjoy the data collected in a Table aggregates from FIX-Protocol Stream Processing, presented in this post.
in mt5 - depends on your terminal, if you select non-hedging then total open position for each Symbol.
in mt4 - use the following code, if you are interested in trades open by some particular EA - then check both Symbol and magic number:
int buys = 0, sells = 0; //number of tickets
double volBuys = 0, volSells = 0; //total volumes
for (int i=OrdersTotal()-1;i>=0;i--){
if(OrderSelect(i,SEL_BY_POS)){
if(OrderSymbol()==Symbol()){
if(OrderType()==OP_BUY){
buys++;
volBuys += OrderLots();
}else if(OrderType()==OP_SELL){
sells++;
volSells += OrderLots();
}
}
}
}

Resources