Gervis DCA

This commit is contained in:
Nkondog Anselme
2022-01-01 15:32:05 +01:00
parent 0717013a21
commit 2bb0816712
27 changed files with 1777 additions and 2 deletions
+197
View File
@@ -0,0 +1,197 @@
/*
MA Crossover.mq5
Copyright 2013-2020, Orchard Forex
https://www.orchardforex.com
Description:
*/
#property copyright "Copyright 2013-2020, Orchard Forex"
#property link "https://www.orchardforex.com"
#property version "1.00"
#property strict
//
// This is where we pull in the framework
//
#include <Nkanven/Frameworks/GervisFrame.mqh>
//
// Input Section
//
// Fast moving average
input int InpFastPeriods = 10; // Fast periods
input ENUM_MA_METHOD InpFastMethod = MODE_SMA; // Fast method
input ENUM_APPLIED_PRICE InpFastAppliedPrice = PRICE_CLOSE; // Fast price
// Slow moving average
input int InpSlowPeriods = 20; // Slow periods
input ENUM_MA_METHOD InpSlowMethod = MODE_SMA; // Slow method
input ENUM_APPLIED_PRICE InpSlowAppliedPrice = PRICE_CLOSE; // Slow price
// Bar numbers for comparison
//input int InpBar2 = 2; // Base bar number
//input int InpBar1 = 1; // Crossover bar number
//
// Some standard inputs,
// remember to change the default magic for each EA
//
input double InpVolume = 0.01; // Default order size
input string InpComment = __FILE__; // Default trade comment
input int InpMagicNumber = 20200701; // Magic Number
//
// Declare the expert, use the child class name
//
#define CExpert CExpertBase
CExpert *Expert;
//
// Signals, use the child class names if applicable
//
CSignalBase *EntrySignal;
CSignalBase *ExitSignal;
//
// Indicators - use the child class name here
//
CIndicatorMA *FastIndicator;
CIndicatorMA *SlowIndicator;
int OnInit() {
//
// Instantiate the expert
//
Expert = new CExpert();
//
// Assign the default values to the expert
//
Expert.SetVolume(InpVolume);
Expert.SetTradeComment(InpComment);
Expert.SetMagic(InpMagicNumber);
//
// Create the indicators
//
FastIndicator = new CIndicatorMA(InpFastPeriods, 0, InpFastMethod, InpFastAppliedPrice);
SlowIndicator = new CIndicatorMA(InpSlowPeriods, 0, InpSlowMethod, InpSlowAppliedPrice);
//
// Set up the signals
//
EntrySignal = new CSignalCrossover();
EntrySignal.AddIndicator(FastIndicator, 0);
EntrySignal.AddIndicator(SlowIndicator, 0);
//ExitSignal = Not needed, using the same signal as entry
//
// Add the signals to the expert
//
Expert.AddEntrySignal(EntrySignal);
Expert.AddExitSignal(EntrySignal); // Same signal
//
// Finish expert initialisation and check result
//
int result = Expert.OnInit();
return(result);
}
void OnDeinit(const int reason) {
EventKillTimer();
delete Expert;
//delete ExitSignal;
delete EntrySignal;
delete FastIndicator;
delete SlowIndicator;
return;
}
void OnTick() {
Expert.OnTick();
return;
}
void OnTimer() {
Expert.OnTimer();
return;
}
void OnTrade() {
Expert.OnTrade();
return;
}
void OnTradeTransaction(const MqlTradeTransaction& trans,
const MqlTradeRequest& request,
const MqlTradeResult& result) {
Expert.OnTradeTransaction(trans, request, result);
return;
}
double OnTester() {
return(Expert.OnTester());
}
void OnTesterInit() {
Expert.OnTesterInit();
return;
}
void OnTesterPass() {
Expert.OnTesterPass();
return;
}
void OnTesterDeinit() {
Expert.OnTesterDeinit();
return;
}
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam) {
Expert.OnChartEvent(id, lparam, dparam, sparam);
return;
}
void OnBookEvent(const string &symbol) {
Expert.OnBookEvent();
return;
}
Binary file not shown.
+129
View File
@@ -0,0 +1,129 @@
//+------------------------------------------------------------------+
//| Gervis.mq5 |
//| Copyright 2021, Nkondog Anselme Venceslas |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Nkondog Anselme Venceslas"
#property link "https://www.mql5.com"
#property version "1.00"
#include <Indicators/Trend.mqh>
#include <Indicators/Oscilators.mqh>
CiMA* sma;
CiMA* ssma;
#include <Nkanven\Gervis\Parameters.mqh> // Description of variables
#include <DL_ErrorHandling.mqh> // Error library
#include <Nkanven\Gervis\PreChecks.mqh> // Prechecks
#include <Nkanven\Gervis\TradingHour.mqh> //
#include <Trade\Trade.mqh>
#include <Nkanven\Gervis\ScanPositions.mqh> // Scan for opened positions
#include <Nkanven\Gervis\CheckHistory.mqh> //Check transaction history
#include <Nkanven\Gervis\TradeManager.mqh> //Manage trade dynamic open and close conditions
#include <Nkanven\Gervis\EntriesManagerDCA.mqh> // Check buy and sell entries signals and execute them
#include <Nkanven\Gervis\LotSizeCal.mqh> // Lot size calculate
#include <Nkanven\Gervis\ClosePositions.mqh> // Close opened positions
#include <Nkanven\Gervis\HighestPriceLevel.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//sma = new CiMA();
//ssma = new CiMA();
//sma.Create(gSymbol, PERIOD_CURRENT, InpMAPeriods, InpMAAppliedPrice, InpMAMethod, PRICE_CLOSE);
//ssma.Create(gSymbol, PERIOD_CURRENT, 200, InpMAAppliedPrice, InpMAMethod, PRICE_CLOSE);
InitializeVariables();
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
SymbolInfoTick(_Symbol,last_tick);
//sma.Refresh(-1);
//ssma.Refresh(-1);
TimeCurrent(dt);
//gSma = sma.Main(1);
//gSsma = ssma.Main(1);
CheckOperationHours();
gCandleHigh = iHigh(gSymbol, PERIOD_CURRENT, 1);
gCandleLow = iLow(gSymbol, PERIOD_CURRENT, 1);
gCandleOpen = iOpen(gSymbol, PERIOD_CURRENT, 1);
gCandleClose = iClose(gSymbol, PERIOD_CURRENT, 1);
gMinStopLoss =MathAbs(SymbolInfoInteger(gSymbol, SYMBOL_TRADE_STOPS_LEVEL))+20;
//isQualifiedCandle(0);
OrderClose();
ScanPositions();
if(gTotalOpenPositions==0)
gSignalEntry = SIGNAL_ENTRY_BUY;
CheckSpread();
entryConditions();
EvaluateEntry();
drawLine();
ExecuteEntry();
Comment(
"Expert Advisor by Anselme Nkondog (c) 2021\n "+
" Hour " + dt.hour + " Min "+ dt.min+"\n"
" Last Highest Price " + gLastHighestPrice + " Price %change "+ gPriceChange);
}
//+------------------------------------------------------------------+
//Initialize variables
void InitializeVariables()
{
gIsNewCandle=false;
gIsTradedThisBar=false;
gIsOperatingHours=false;
gIsSpreadOK=false;
gLotSize=InpDefaultLotSize;
gTickValue=0;
gTotalOpenBuy=0;
gTotalOpenSell=0;
gSignalEntry=SIGNAL_ENTRY_NEUTRAL;
gSignalExit=SIGNAL_EXIT_NEUTRAL;
Print("Variables intialized");
}
//Check and return if the spread is not too high
void CheckSpread()
{
//Get the current spread in points, the (int) transforms the double coming from MarketInfo into an integer to avoid a warning when compiling
long SpreadCurr=SymbolInfoInteger(gSymbol, SYMBOL_SPREAD);
Print("Spread ", SpreadCurr);
if(SpreadCurr<=InpMaxSpread)
{
gIsSpreadOK=true;
}
else
{
gIsSpreadOK=false;
}
}
//+------------------------------------------------------------------+