2025-10-12 09:28:05 -04:00 | | | //+------------------------------------------------------------------+
|
| | | //| 01_R2WM_EA.mq5 |
|
2025-11-09 11:49:58 -05:00 | | | //| Santiago Cruz |
|
2025-10-12 09:28:05 -04:00 | | | //| https://www.mql5.com/en/users/algo-trader/ |
|
| | | //+------------------------------------------------------------------+
|
2025-11-09 11:23:41 -05:00 | | |
|
2025-12-31 07:57:59 -05:00 | | | #property copyright "Santiago Cruz, AlgoNet Inc."
|
2025-10-12 09:28:05 -04:00 | | | #property link "https://www.mql5.com/en/users/algo-trader/"
|
| | | #property version "1.00"
|
| | |
|
| | | #include <Trade\PositionInfo.mqh>
|
| | | #include <Trade\AccountInfo.mqh>
|
| | | #include <Trade\Trade.mqh>
|
2025-12-31 08:02:37 -05:00 | | | #include <NeuralNetwork.mqh>
|
| | | #include <OrderBook.mqh>
|
2025-10-12 09:28:05 -04:00 | | |
|
| | | CTrade trade;
|
| | | CAccountInfo AccInfo;
|
| | | CPositionInfo m_position;
|
2025-12-31 08:02:37 -05:00 | | | OrderBook OB_ASK;
|
| | | OrderBook OB_Bid;
|
2025-10-12 09:28:05 -04:00 | | |
|
| | | input group "=== Trading Inputs ==="
|
| | |
|
| | | input string TradeComment = "WNN Neural Network EA";
|
2025-12-31 08:02:37 -05:00 | | | static input long EA_Magic_Buy = 250206;
|
| | | static input long EA_Magic_Sell = 250207;
|
2025-10-12 09:28:05 -04:00 | | | input double LotSize = 1.05;
|
| | | double pip = _Point*10;
|
| | | input int TPinPips = 5;
|
2025-12-31 08:02:37 -05:00 | | | input int SLinPips = 5;
|
2025-10-12 09:28:05 -04:00 | | | input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1;
|
| | | input int number_of_neurons = 15;
|
2025-12-31 08:02:37 -05:00 | | | input int SlowMA = 100;
|
| | | input int FastMA = 20;
|
| | | input int RSIPeriod = 14;
|
2025-10-12 09:28:05 -04:00 | | |
|
2025-12-31 08:02:37 -05:00 | | | NeuralNetwork NNTrade_Buy(10,28,number_of_neurons,10,.0001,1);
|
| | | NeuralNetwork NNTrade_Sell(10,28,number_of_neurons,10,.0001,1);
|
| | |
|
| | | matrix tempMatrix(10,28);
|
| | | matrix tempMatrixb(10,28);
|
| | |
|
| | | bool Tracker = true;
|
| | | ulong TimeCheck = ulong(TimeCurrent());
|
| | | double tempAsk = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
|
| | |
|
| | | int deltaTick = 0;
|
| | | bool deltaTracker = false;
|
| | | double delta_prev = 0;
|
| | | double deltaDerivative = 0;
|
2025-11-09 11:23:41 -05:00 | | |
|
| | | int OnInit()
|
| | | {
|
2025-12-31 08:02:37 -05:00 | | |
|
2025-11-09 11:23:41 -05:00 | | | return(INIT_SUCCEEDED);
|
| | | }
|
2025-12-31 07:57:59 -05:00 | | |
|
| | | void OnDeinit(const int reason)
|
2025-11-09 11:23:41 -05:00 | | | {
|
| | |
|
| | | }
|
| | |
|
| | | void OnTick()
|
| | | {
|
| | | datetime tm = TimeCurrent();
|
| | | MqlDateTime stm;
|
| | | TimeToStruct(tm,stm);
|
| | |
|
2025-12-31 08:02:37 -05:00 | | | if( (stm.hour == 16 && stm.min >=0) || (stm.hour == 17 && stm.min <= 40) )
|
2025-11-09 11:23:41 -05:00 | | | {
|
| | |
|
2025-12-31 08:02:37 -05:00 | | | for(int i=PositionGetTicket()-1;i>=0;i--)
|
2025-11-09 11:23:41 -05:00 | | | {
|
2025-12-31 08:02:37 -05:00 | | | int ticket = PositionGetTicket(i);
|
| | | m_position.SelectByTicket(ticket);
|
| | | ulong posTime = ulong(m_position.Time());
|
| | |
|
| | | if(1*60 < ulong(TimeCurrent()) - posTime)
|
2025-11-09 11:23:41 -05:00 | | | {
|
2025-12-31 08:02:37 -05:00 | | | int ticket = PositionGetTicket(i);
|
| | | trade.PositionClose(ticket);
|
2025-11-09 11:23:41 -05:00 | | | }
|
| | | }
|
| | |
|
2025-12-31 08:02:37 -05:00 | | | double current_Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
|
| | | double current_Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
|
| | |
|
| | | ulong current_Volume = iTickVolume(_Symbol,PERIOD_M1,0);
|
2025-11-09 11:23:41 -05:00 | | |
|
2025-12-31 08:02:37 -05:00 | | | OB_Ask.Insert(current_Ask,current_Volume);
|
| | | OB_Bid.Insert(current_Bid,current_Volume);
|
| | |
|
| | | double UniqueAsk[];
|
| | | double UniqueNumsAsk[];
|
| | |
|
| | | double UniqueBid[];
|
| | | double UniqueNumsBid[];
|
| | |
|
| | | double UniqueAskSize = OB_Ask.SetArraysWithValues(UniqueNumsAsk,UniqueAsk);
|
| | | double UniqueBidSize = OB_Bid.SetArraysWithValues(UniqueNumsBid,UniqueBid);
|
| | |
|
| | | double deltaAsk = 0;
|
| | | double deltaBid = 0;
|
| | | double delta = 0;
|
| | |
|
| | | if(stm.sec < deltaTick)
|
2025-11-09 11:23:41 -05:00 | | | {
|
2025-12-31 08:02:37 -05:00 | | | for(int i=0;i<UniqueAskSize;i++)
|
2025-11-09 11:23:41 -05:00 | | | {
|
2025-12-31 08:02:37 -05:00 | | | deltaAsk += UniqueNumsAsk[i]*UniqueAsk[i];
|
2025-11-09 11:23:41 -05:00 | | | }
|
2025-12-31 08:02:37 -05:00 | | |
|
| | | for(int i=0;i<UniqueBidSize;i++)
|
2025-11-09 11:23:41 -05:00 | | | {
|
2025-12-31 08:02:37 -05:00 | | | deltaBid += UniqueNumsBid[i]*UniqueBid[i];
|
2025-11-09 11:23:41 -05:00 | | | }
|
2025-12-31 08:02:37 -05:00 | | |
|
| | | delta = deltaAsk - deltaBid;
|
| | | deltaDerivative = (current_Ask - delta) / current_Ask - delta_prev;
|
| | | delta_prev = (current_Ask - delta)/current_Ask;
|
| | |
|
| | | OB_Ask.ClearBook();
|
| | | OB_Bid.ClearBook();
|
2025-11-09 11:23:41 -05:00 | | | }
|
| | |
|
2025-12-31 08:02:37 -05:00 | | | deltaTick = stm.sec;
|
| | |
|
2025-11-09 11:23:41 -05:00 | | | }
|