MyGridBasket
- Библиотеки
-
Ahmad Aan Isnain Shofwan
About Me – Ahmad Aan Isnaini
“I don’t code to sell. I code to survive.”
In a marketplace flooded with rented hype and quick-profit illusions, I chose a different path:
Resilience over glamour. Discipline over noise. - Версия: 1.0
Read-only basket analytics library for grid and averaging EAs. Real breakeven, what-if, stress test and stop-out distance. Sends no orders.
What it is
A library that reads your open positions and tells you the real state of a grid or averaging basket.
It does not trade. It sends no orders. It has no entry logic.
You call it from your own EA.
What it tells you
- Breakeven of the basket, with swap and commission counted
- The price where the basket nets a money amount you choose
- Where the average and the breakeven move if you add one more level
- How many lots bring the average to a price you choose
- Equity and margin level if price moves against the basket
- The same, with a grid that keeps adding levels
- How many points are left until stop-out
How to use
1. Put MyGridBasket.ex5 in MQL5/Libraries.
2. Add the import block below to your EA.
3. Create a basket handle, refresh it, read the numbers.
4. Destroy the handle in OnDeinit.
Example
int hBuy=-1;
int OnInit()
{
hBuy=MyGB_Create(_Symbol,MagicNumber,MYGB_BUY); // magic -1 = every magic
return (hBuy>=0) ? INIT_SUCCEEDED : INIT_FAILED;
}
void OnDeinit(const int reason)
{
MyGB_Destroy(hBuy);
}
void OnTick()
{
MyGB_Refresh(hBuy);
double be = MyGB_Breakeven(hBuy);
double tp = MyGB_TargetPrice(hBuy,50.0); // net +50 in account currency
double so = MyGB_StopOutDistance(hBuy); // points to stop-out
}
Conventions
Invalid handle or failed calculation: double returns EMPTY_VALUE, int returns -2, bool returns false.
Margin level is in percent. -1 means no margin is used.
Stop-out distance is in points. -1 means not reached in range, -2 means unknown.
Import block
#define MYGB_BUY 0
#define MYGB_SELL 1
#import "MyGridBasket.ex5"
int MyGB_Create(string symbol,long magic,int side);
void MyGB_Destroy(int h);
bool MyGB_Refresh(int h);
string MyGB_Version();
bool MyGB_IsHedging(int h);
string MyGB_Warning(int h);
string MyGB_Summary(int h);
int MyGB_Positions(int h);
double MyGB_Lots(int h);
double MyGB_AvgPrice(int h);
double MyGB_Breakeven(int h);
double MyGB_ClosePrice(int h);
double MyGB_DistToBreakevenPoints(int h);
double MyGB_Floating(int h);
double MyGB_Swap(int h);
double MyGB_EntryCommission(int h);
double MyGB_ExitCommission(int h);
bool MyGB_ExitCommissionKnown(int h);
double MyGB_NetResult(int h);
double MyGB_WorstPositionProfit(int h);
double MyGB_BestPositionProfit(int h);
double MyGB_LayerSpanPoints(int h);
void MyGB_SetExitCommissionPerLot(int h,double rate_per_lot);
void MyGB_ClearExitCommissionOverride(int h);
double MyGB_TargetPrice(int h,double target_money);
double MyGB_MoneyAtPrice(int h,double price);
double MyGB_LotsForTargetAverage(int h,double price,double target_avg);
double MyGB_WhatIfNewAverage(int h,double lot,double price);
double MyGB_WhatIfNewBreakeven(int h,double lot,double price);
double MyGB_WhatIfMarginLevel(int h,double lot,double price);
double MyGB_StressEquity(int h,double adverse_points);
double MyGB_StressMarginLevel(int h,double adverse_points);
int MyGB_StressStopOut(int h,double adverse_points);
double MyGB_GridStressEquity(int h,double adverse_points,double step_points,double first_lot,double lot_mult,double step_mult,int max_levels);
double MyGB_GridStressMarginLevel(int h,double adverse_points,double step_points,double first_lot,double lot_mult,double step_mult,int max_levels);
double MyGB_GridStressLots(int h,double adverse_points,double step_points,double first_lot,double lot_mult,double step_mult,int max_levels);
int MyGB_GridStressLevels(int h,double adverse_points,double step_points,double first_lot,double lot_mult,double step_mult,int max_levels);
int MyGB_GridStressStopOut(int h,double adverse_points,double step_points,double first_lot,double lot_mult,double step_mult,int max_levels);
double MyGB_StopOutDistance(int h);
double MyGB_StopOutDistanceGrid(int h,double step_points,double first_lot,double lot_mult,double step_mult,int max_levels);
double MyGB_NetLots(string symbol,long magic);
#import
Know the limits
- Made for hedging accounts. On netting accounts there is one position per symbol, so the basket is that position. A warning is set.
- Stop-out is evaluated only when your broker uses stop-out in percent. In money mode the result is unknown.
- Margin of simulated levels does not credit hedge offset between opposite positions. This errs on the safe side.
- Simulated levels fill exactly at their price. Spread, slippage and execution delay are not modelled.
- Exit commission is estimated from your own past closing deals on the symbol. If there are none it is counted as 0 and the library tells you.
- Other positions on the account are assumed unchanged during a stress test.
- A stress test is arithmetic. It is not a forecast. Real fills in a fast market are worse.
- Test it on a demo account with your broker's symbols before you rely on it.
Free. No account or symbol restrictions. No warranty.
Version 1.00 is the first release.
