The sizing formula divides by the full entry-price value, not the stop distance. RiskPercent=100 is not a conventional 100%-at-stop risk calculation; sizing needs explicit review.
Reversal Tuesday
A calendar-based long setup entered below a daily moving average, with a next-day timed exit.
How the source is structured
- After Monday 22:55 server time, check whether bid is below the daily SMA.
- Calculate a volume from account balance, symbol price and tick properties, then attempt a long with a percentage stop.
- Attempt to close the stored ticket after Tuesday 22:55.
Default inputs
| Open / close | Monday 22:55 / Tuesday 22:55 |
|---|---|
| MA filter | D1 / SMA 20 |
| RiskPercent input | 100 (see sizing note) |
| Stop | 5% |
| Evaluation period | M1 |
Source-review notes
These observations come from reading this uploaded version. They are not compiler output or a complete code audit. The download retains the source as supplied.
IsMafilter is declared but not used to switch the filter off. The price-versus-MA condition is always applied.
The ticket used for the timed close exists only in memory and is not recovered after a restart.
Dependencies
Built-in moving average; MetaTrader 5 standard Trade library.
Source & attribution
No author or license declaration appears in the supplied source.
Included in the Edge Quant source collection with existing notices preserved. Free download does not imply a new license grant.
Inspect the original source
The browser preview is decoded for reading; the download keeps the original file bytes.
Expand full MQL5 source · 101 lines
#include <Trade/Trade.mqh>//input variables that can be changed by the userinput int DigitsAfterDecimalPoint = 1;input ENUM_TIMEFRAMES Timeframe = PERIOD_M1;input double RiskPercent = 100;input double SlPercent = 5;input int DayOpen = 1;input int TimeOpenHour = 22;input int TimeOpenMin = 55;input int DayClose = 2;input int TimeCloseHour = 22;input int TimeCloseMin = 55;input bool IsMafilter = true;input ENUM_TIMEFRAMES MaTimeframe = PERIOD_D1;input int MaPeriods = 20;input ENUM_MA_METHOD MaMethod = MODE_SMA;input ENUM_APPLIED_PRICE MaAppPrice = PRICE_CLOSE;//global variables that can be used in every functionint barsTotal;int lastDay;int handleMa;ulong posTicket;CTrade trade;int OnInit(){ //create a handle for the moving average indicator //a handle is a description for a specific indicator handleMa = iMA(_Symbol,MaTimeframe,MaPeriods,0,MaMethod,MaAppPrice); return(INIT_SUCCEEDED);}void OnDeinit(const int reason){}void OnTick(){//check for a new bar int bars = iBars(_Symbol,Timeframe); if(barsTotal !=bars){ barsTotal = bars; //get the moving average indicator value for the currend bar and store it in the ma array double ma[]; CopyBuffer(handleMa,MAIN_LINE,0,1,ma); //create a dt structure MqlDateTime dt; TimeCurrent(dt); dt.sec = 0; //update the dt structure variables so it will indicate the opening time for the current day dt.hour = TimeOpenHour; dt.min = TimeOpenMin; //convert the dt structure to a simple datetime variable to make time comparisons easy datetime timeOpen = StructToTime(dt); //update the dt structure variable so it will indicate the closing time for the current day dt.hour = TimeCloseHour; dt.min = TimeCloseMin; //convert the dt structure to a simple datetime variable to make time coparisons easy datetime timeClose = StructToTime(dt); if(TimeCurrent() >= timeClose && dt.day_of_week == DayClose){ if(posTicket > 0){ if(trade.PositionClose(posTicket)){ posTicket = 0; } } } //check if we reached the opening time on a the opening day if(lastDay != dt.day_of_year && TimeCurrent() >= timeOpen && dt.day_of_week == DayOpen){ if(SymbolInfoDouble(_Symbol,SYMBOL_BID) < ma[0]){ //send buy order double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); double sl = ask - ask * SlPercent / 100; double ticksize = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE); double tickvalue = SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE); double lotstep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP); int ticks = (int)(ask / ticksize); double riskPerLotstep = ticks * tickvalue *lotstep; double risk = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100; double lots = risk / riskPerLotstep * lotstep; lots = NormalizeDouble(lots,DigitsAfterDecimalPoint); if(trade.Buy(lots,_Symbol,ask,sl,0,"tt")){ posTicket = trade.ResultOrder(); } lastDay = dt.day_of_year; } } }}Educational source material, not investment advice. No profitability, execution quality or live-readiness claim is made for this upload.