MnQInvestmentDevelopment/MnQInvestment/03_PilotProjects/MovingAverageMiracle.mq5
super.admin cff55d2704 convert
2025-05-30 15:08:44 +02:00

100 lines
2.8 KiB
MQL5

#property copyright "Copyright 2023, M & Q Investment Group"
#property link "https://www.mql5.com"
#property version "1.00"
#include <trade/trade.mqh>
CTrade trade;
input int MovingAvPeriodSlow = 200;
input int MovingAvShiftSlow = 0;
input int MovingAvPeriodFast = 20;
input int MovingAvShiftFast = 0;
input double TPBuy = 0.0001;
input double SLBuy = 0.0001;
input double TPSell = 0.0001;
input double SLSell = 0.0001;
input double Lotsize = 1.0;
double accountbalancebeginning;
int OnInit()
{
accountbalancebeginning = AccountInfoDouble(ACCOUNT_BALANCE);
return(INIT_SUCCEEDED);
}
void OnTick()
{
static datetime timestamp;
datetime time = iTime(_Symbol,PERIOD_CURRENT,0);
if(timestamp != time)
{
timestamp = time;
static int handleSlowMa = iMA(_Symbol,PERIOD_CURRENT,MovingAvPeriodSlow, MovingAvShiftSlow,MODE_SMA,PRICE_CLOSE);
double slowMaArray[];
CopyBuffer(handleSlowMa,0,1,2,slowMaArray);
ArraySetAsSeries(slowMaArray,true);
static int handleFastMa = iMA(_Symbol,PERIOD_CURRENT,MovingAvPeriodFast, MovingAvShiftFast,MODE_SMA,PRICE_CLOSE);
double FastMaArray[];
CopyBuffer(handleFastMa,0,1,2,FastMaArray);
ArraySetAsSeries(FastMaArray,true);
if(FastMaArray[0] > slowMaArray[0] && FastMaArray[1] < slowMaArray[1])
{
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double tpbuyx = ask + TPBuy;
double slbuyx = ask - SLBuy;
trade.Buy(Lotsize,_Symbol,ask,slbuyx,tpbuyx,"BUYTRADE");
}
if(FastMaArray[0] < slowMaArray[0] && FastMaArray[1] > slowMaArray[1])
{
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double tpsellx = ask + TPSell;
double slsellx = ask - SLSell;
trade.Sell(Lotsize,_Symbol,ask,slsellx,tpsellx,"SELLTRADE");
}
}
//STATISTICS
double accountbalance = AccountInfoDouble(ACCOUNT_BALANCE);
double accountprofit = AccountInfoDouble(ACCOUNT_PROFIT);
double accountequity = AccountInfoDouble(ACCOUNT_EQUITY);
accountprofit = accountequity - accountbalancebeginning;
accountprofit = NormalizeDouble(accountprofit,2);
// DISPLAY OF VALUES ON CHART
Comment("\nServertime: ", TimeCurrent(),
"\nCurrenttime: ",TimeCurrent(),
"\nProfit: ",accountprofit,
"\nEquity: ",accountequity);
}//END ON TICK