112 lines
4 KiB
MQL5
112 lines
4 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Dumb1.mq5 |
|
|
//| AK47 |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "AK47"
|
|
#property link "https://www.mql5.com"
|
|
#property version "1.00"
|
|
|
|
#include <Trade\Trade.mqh>
|
|
#include <Trade\AccountInfo.mqh>
|
|
#include <Trade\PositionInfo.mqh>
|
|
|
|
input double FixedLot=0.1; // Fixed Lot
|
|
|
|
CTrade trade;
|
|
CPositionInfo PosInfo;
|
|
CAccountInfo Account;
|
|
|
|
int MAHandle;
|
|
|
|
double ask, bid, StartingBalance;
|
|
double opens[], closes[],highs[],lows[],MA[];
|
|
input ENUM_TIMEFRAMES timeframe = PERIOD_M30;
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
MAHandle = iMA(_Symbol,timeframe,PERIOD_M30,0,MODE_EMA,PRICE_CLOSE);
|
|
|
|
ArraySetAsSeries(opens,true);
|
|
ArraySetAsSeries(highs,true);
|
|
ArraySetAsSeries(lows,true);
|
|
ArraySetAsSeries(closes,true);
|
|
|
|
//---
|
|
//---
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
MqlDateTime dt;
|
|
datetime gmtTime = TimeGMT(dt);
|
|
|
|
int totalBars = 15;
|
|
|
|
CopyHigh(_Symbol, timeframe, 0, totalBars, highs);
|
|
CopyLow(_Symbol, timeframe, 0, totalBars, lows);
|
|
CopyBuffer(MAHandle,0,0,4,MA);
|
|
|
|
double asianhigh = highs[ArrayMaximum(highs)];
|
|
double asianlow = lows[ArrayMinimum(lows)];
|
|
|
|
bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
|
|
ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
|
|
|
|
|
|
double averagehighlow = NormalizeDouble((asianhigh+asianlow)/2,5);
|
|
|
|
//datetime currentTime = TimeCurrent();
|
|
//asianStart = currentTime - (currentTime % 86400) + ASIAN_START_HOUR * 3600;
|
|
//asianEnd = currentTime - (currentTime % 86400) + ASIAN_END_HOUR * 3600;
|
|
//londonStart = currentTime - (currentTime % 86400) + LONDON_START_HOUR * 3600;
|
|
//londonEnd = currentTime - (currentTime % 86400) + LONDON_END_HOUR * 3600;
|
|
//nyStart = currentTime - (currentTime % 86400) + NY_START_HOUR * 3600;
|
|
//nyEnd = currentTime - (currentTime % 86400) + NY_END_HOUR * 3600;
|
|
|
|
|
|
|
|
if(dt.hour == 8 && PositionsTotal()<1 && ask < averagehighlow && ask > MA[0])
|
|
{
|
|
if(PositionsTotal()<1)
|
|
trade.Buy(FixedLot,_Symbol,0, NormalizeDouble(ask - (asianhigh - ask)/2,5),asianhigh,"init trades");
|
|
if(OrdersTotal()<1)
|
|
trade.BuyLimit(FixedLot,asianlow,_Symbol, NormalizeDouble(asianlow -(asianhigh - asianlow)/2,5),asianhigh);
|
|
|
|
}
|
|
if(dt.hour == 8 && ask > averagehighlow && ask > averagehighlow && ask < MA[0])
|
|
{
|
|
if(PositionsTotal()<1)
|
|
trade.Sell(FixedLot,_Symbol,0, NormalizeDouble((ask + (ask - asianlow)/2),5),asianlow,"init trades");
|
|
if(OrdersTotal()<1)
|
|
trade.SellLimit(FixedLot,asianhigh,_Symbol, NormalizeDouble(asianhigh + (asianlow - asianhigh)/2,5),asianlow);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
////////////////CLOSE RULE////////////////////////////
|
|
void CloseAllPositions()
|
|
{
|
|
for(int i = PositionsTotal() - 1; i >= 0; i--) // loop all Open Positions
|
|
if(PosInfo.SelectByIndex(i)) // select a position
|
|
{
|
|
trade.PositionClose(PosInfo.Ticket());
|
|
}
|
|
}
|
|
//+------------------------------------------------------------------+
|