Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ee4a0d0cec | |||
| 419ea51fca |
Binary file not shown.
+91
-32
@@ -1,17 +1,20 @@
|
||||
#property copyright "Copyright 2017-2021, Artur Zas"
|
||||
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
|
||||
#property link "https://www.az-invest.eu"
|
||||
#property version "1.17"
|
||||
#define VERSION "1.20"
|
||||
#property version VERSION
|
||||
#property description "Example EA: Trading based on 2 moving average crossover."
|
||||
#property description "MA1 & MA2 need to be enabled on the inicator creating the chart."
|
||||
#property description "MA1 && MA2 need to be enabled on the inicator creating the chart."
|
||||
#property description "MA1 - Fast moving average"
|
||||
#property description "MA2 - Slow moving average"
|
||||
#property description " "
|
||||
#property description "GNU General Public License v3.0"
|
||||
|
||||
//#define RANGEBAR_LICENSE // uncomment when used on a Tick & Volume bar chart from https://www.az-invest.eu/rangebars-for-metatrader-5
|
||||
//#define ULTIMATE_RENKO_LICENSE // uncomment when used on Ultimate Renko chart from https://www.az-invest.eu/ultimate-renko-indicator-generator-for-metatrader-5
|
||||
//#define VOLUMECHART_LICENSE // uncomment when used on a Tick & Volume bar chart from https://www.az-invest.eu/Tick-chart-and-volume-chart-for-mt5
|
||||
//#define RANGEBAR_LICENSE // uncomment when used on a Tick & Volume bar chart from https://www.az-invest.eu/rangebars-for-metatrader-5
|
||||
//#define SECONDSCHART_LICENSE // uncomment when used on a Seconds TF bar chart from https://www.az-invest.eu/seconds-timeframe-chart-for-metatrader-5
|
||||
//#define LINEBREAKCHART_LICENSE // uncomment when used on a Line Break chart from https://www.az-invest.eu
|
||||
//#define LINEBREAKCHART_LICENSE // uncomment when used on a Line Break chart from https://www.az-invest.eu/linebreak-chart-for-metatrader-5
|
||||
//
|
||||
// Uncomment only ONE of the 5 directives listed below and recompile
|
||||
// -----------------------------------------------------------------
|
||||
@@ -21,14 +24,14 @@
|
||||
//#define EA_ON_XTICK_CHART // Use EA on XTick Chart (obsolete)
|
||||
//#define EA_ON_TICK_VOLUME_CHART // Use EA on Tick & Volume Bar Chart
|
||||
//#define EA_ON_SECONDS_CHART // Use EA on Seconds Interval chart
|
||||
//#define EA_ON_LINEBREAK_CHART // Use EA on LineBreak charts
|
||||
//#define EA_ON_LINEBREAK_CHART // Use EA on LineBreak charts
|
||||
|
||||
//#define DEVELOPER_VERSION // used when I develop ;) should always be commented out
|
||||
|
||||
// Uncomment the directive below and recompile if EA is used with P-Renko BR Ultimate
|
||||
// ----------------------------------------------------------------------------------
|
||||
//
|
||||
// #define P_RENKO_BR_PRO // Use in P-Renko BR Ultimate version
|
||||
//#define P_RENKO_BR_PRO // Use in P-Renko BR Ultimate version
|
||||
|
||||
//
|
||||
// Uncomment the directive below and recompile for use in a backtest only
|
||||
@@ -65,6 +68,7 @@
|
||||
|
||||
#include <AZ-INVEST/SDK/TimeControl.mqh>
|
||||
#include <AZ-INVEST/SDK/TradeFunctions.mqh>
|
||||
#include <AZ-INVEST/SDK/TradeManager.mqh>
|
||||
|
||||
enum ENUM_TRADE_DIRECTION
|
||||
{
|
||||
@@ -74,22 +78,30 @@ enum ENUM_TRADE_DIRECTION
|
||||
};
|
||||
|
||||
#ifdef SHOW_INDICATOR_INPUTS
|
||||
input group "EA parameters"
|
||||
input group "### EA parameters"
|
||||
#endif
|
||||
input double Lots = 0.1; // Traded lots
|
||||
input uint StopLoss = 100; // Stop Loss (in points)
|
||||
input uint TakeProfit = 250; // Take profit (in points)
|
||||
input uint TakeProfit = 300; // Take profit (in points)
|
||||
input ENUM_TRADE_DIRECTION ValidTradeDirection = TRADE_DIRECTION_ALL; // Valid trading type
|
||||
input bool ForceSR = false; // Force Stop & Reverse
|
||||
input bool ReverseOnMACrossInsideGap = true; // Reverse trade if MA cross inside a gap
|
||||
input bool CloseTradeAfterTradingHours = true; // Close trade after trading hours
|
||||
input ulong DeviationPoints = 0; // Maximum defiation (in points)
|
||||
input double ManualTickSize = 0.000; // Tick Size (0 = auto detect)
|
||||
input group "### Trading schedule (Non stop if start = 0 & end = 0)"
|
||||
input string Start="9:00"; // Start trading at
|
||||
input string End="17:55"; // End trading at
|
||||
input bool CloseTradeAfterTradingHours = false; // Close trade after trading hours
|
||||
input group "### Trade management";
|
||||
input int InpBEPoints = 0; // BreakEven (Points) [ 0 = OFF ]
|
||||
input int InpTrailByPoints = 0; // Trail by (Points) [ 0 = OFF ]
|
||||
input int InpTrailStartPoints = 150; // Start trailing after (Points)
|
||||
input int InpPartialCloseAtProfitPoints = 0; // Partial close at (Points) [ 0 = OFF ]
|
||||
input int InpPartialClosePercentage = 50; // Partial close %
|
||||
input group "### Misc";
|
||||
input ulong MagicNumber=5150; // Assign trade ID
|
||||
input ulong DeviationPoints = 0; // Maximum deviation (in points)
|
||||
input double ManualTickSize = 0.000; // Tick Size (0 = auto detect)
|
||||
input int NumberOfRetries = 50; // Maximum number of retries
|
||||
input int BusyTimeout_ms = 1000; // Wait [ms] before retry on bussy errors
|
||||
input int BusyTimeout_ms = 1000; // Wait [ms] before retry on busy errors
|
||||
input int RequoteTimeout_ms = 250; // Wait [ms] before retry on requotes
|
||||
|
||||
// Global data buffers
|
||||
@@ -106,8 +118,10 @@ int numberOfBars = 3;
|
||||
|
||||
CMarketOrder *marketOrder = NULL;
|
||||
CTimeControl *timeControl = NULL;
|
||||
CTradeManager *tradeManager = NULL;
|
||||
|
||||
ulong currentTicket;
|
||||
CTradeManagerState tradeManagerState;
|
||||
ENUM_POSITION_TYPE currentPositionType;
|
||||
ENUM_POSITION_TYPE signal;
|
||||
ENUM_POSITION_TYPE validation;
|
||||
@@ -191,7 +205,25 @@ int OnInit()
|
||||
|
||||
timeControl.SetValidTraingHours(Start,End);
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
//
|
||||
// Init TradeManager
|
||||
//
|
||||
|
||||
CTradeManagerParameters params2;
|
||||
{
|
||||
params2.BEPoints = InpBEPoints;
|
||||
params2.TrailByPoints = InpTrailByPoints;
|
||||
params2.TrailStartPoints = InpTrailStartPoints;
|
||||
params2.PartialCloseAtProfitPoints = InpPartialCloseAtProfitPoints;
|
||||
params2.PartialClosePercentage = InpPartialClosePercentage;
|
||||
}
|
||||
|
||||
if(tradeManager == NULL)
|
||||
{
|
||||
tradeManager = new CTradeManager(params2, marketOrder);
|
||||
}
|
||||
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
@@ -223,7 +255,13 @@ void OnDeinit(const int reason)
|
||||
delete customBars;
|
||||
customBars = NULL;
|
||||
}
|
||||
|
||||
|
||||
if(tradeManager != NULL)
|
||||
{
|
||||
delete tradeManager;
|
||||
tradeManager = NULL;
|
||||
}
|
||||
|
||||
Comment("");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -231,20 +269,15 @@ void OnDeinit(const int reason)
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
if(marketOrder == NULL || customBars == NULL || timeControl == NULL)
|
||||
if(marketOrder == NULL || customBars == NULL || timeControl == NULL || tradeManager == NULL)
|
||||
return;
|
||||
|
||||
if(customBars.IsNewBar())
|
||||
// trade management
|
||||
|
||||
if(marketOrder.IsOpen(currentTicket, _Symbol, MagicNumber))
|
||||
{
|
||||
if(timeControl.IsScheduleEnabled())
|
||||
{
|
||||
Comment("EA trading schedule ON ("+Start+" to "+End+") | trading enabled = "+(string)timeControl.IsTradingTimeValid());
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment("EA trading schedule OFF");
|
||||
}
|
||||
|
||||
// checks done on every tick
|
||||
|
||||
if(!timeControl.IsTradingTimeValid())
|
||||
{
|
||||
if(marketOrder.IsOpen(currentTicket,_Symbol,MagicNumber))
|
||||
@@ -258,6 +291,22 @@ void OnTick()
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
tradeManager.Manage(currentTicket, tradeManagerState);
|
||||
}
|
||||
|
||||
// Signal handler
|
||||
|
||||
if(customBars.IsNewBar())
|
||||
{
|
||||
if(timeControl.IsScheduleEnabled())
|
||||
{
|
||||
Comment("EA trading schedule ON ("+Start+" to "+End+") | trading enabled = "+(string)timeControl.IsTradingTimeValid());
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment("EA trading schedule OFF");
|
||||
}
|
||||
|
||||
//
|
||||
// Get moving average values for current, last completed bar and the bar before that...
|
||||
@@ -280,19 +329,21 @@ void OnTick()
|
||||
if(timeControl.IsScheduleEnabled())
|
||||
{
|
||||
Comment("EA trading schedule ("+Start+" to "+End+") | trading enabled = "+(string)timeControl.IsTradingTimeValid()+
|
||||
"\n MA1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
"\n MA2 [2]: "+DoubleToString(MA2[2],_Digits)+" [1]: "+DoubleToString(MA2[1],_Digits)+
|
||||
// "\n MA1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
// "\n MA2 [2]: "+DoubleToString(MA2[2],_Digits)+" [1]: "+DoubleToString(MA2[1],_Digits)+
|
||||
"\n MA cross signal = "+marketOrder.PositionTypeToString(signal)+
|
||||
"\n MA validation = "+marketOrder.PositionTypeToString(validation)+
|
||||
"\n Trade manager: "+tradeManager.ToString()+
|
||||
"\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment("EA trading schedule not used. Trading is enabled."+
|
||||
"\n MA1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
"\n MA2 [2]: "+DoubleToString(MA2[2],_Digits)+" [1]: "+DoubleToString(MA2[1],_Digits)+
|
||||
// "\n MA1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
// "\n MA2 [2]: "+DoubleToString(MA2[2],_Digits)+" [1]: "+DoubleToString(MA2[1],_Digits)+
|
||||
"\n MA cross signal = "+marketOrder.PositionTypeToString(signal)+
|
||||
"\n MA validation = "+marketOrder.PositionTypeToString(validation)+
|
||||
"\n Trade manager: "+tradeManager.ToString()+
|
||||
"\n");
|
||||
}
|
||||
|
||||
@@ -306,6 +357,7 @@ void OnTick()
|
||||
{
|
||||
PrintFormat("Reversing %s position on Stop&Reverse condition (ticket:%d)", _Symbol, currentTicket);
|
||||
marketOrder.Reverse(currentTicket,Lots,StopLoss,TakeProfit);
|
||||
tradeManagerState.Clear();
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -313,8 +365,10 @@ void OnTick()
|
||||
else if(!marketOrder.IsOpen(_Symbol,POSITION_TYPE_BUY,MagicNumber))
|
||||
{
|
||||
if(IsTradeDirectionValid(POSITION_TYPE_BUY))
|
||||
{
|
||||
marketOrder.Long(_Symbol,Lots,StopLoss,TakeProfit);
|
||||
|
||||
tradeManagerState.Clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -328,6 +382,7 @@ void OnTick()
|
||||
{
|
||||
PrintFormat("Reversing %s position on Stop&Reverse condition (ticket:%d)", _Symbol, currentTicket);
|
||||
marketOrder.Reverse(currentTicket,Lots,StopLoss,TakeProfit);
|
||||
tradeManagerState.Clear();
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -335,8 +390,10 @@ void OnTick()
|
||||
else if(!marketOrder.IsOpen(_Symbol,POSITION_TYPE_SELL,MagicNumber))
|
||||
{
|
||||
if(IsTradeDirectionValid(POSITION_TYPE_SELL))
|
||||
{
|
||||
tradeManagerState.Clear();
|
||||
marketOrder.Short(_Symbol,Lots,StopLoss,TakeProfit);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -357,18 +414,20 @@ void OnTick()
|
||||
// reverse position on signal change inside gap.
|
||||
PrintFormat("Reversing %s position on signal change inside gap (ticket:%d)", _Symbol, currentTicket);
|
||||
marketOrder.Reverse(currentTicket,Lots,StopLoss,TakeProfit);
|
||||
tradeManagerState.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
// close position on signal change inside gap.
|
||||
PrintFormat("Closing %s position on signal change inside gap (ticket:%d)", _Symbol, currentTicket);
|
||||
marketOrder.Close(currentTicket);
|
||||
tradeManagerState.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Binary file not shown.
+83
-30
@@ -1,15 +1,18 @@
|
||||
#property copyright "Copyright 2017-2021, Artur Zas"
|
||||
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
|
||||
#property link "https://www.az-invest.eu"
|
||||
#property version "1.09"
|
||||
#property description "Example EA: Trading based on moving average & price crossover."
|
||||
#define VERSION "1.10"
|
||||
#property version VERSION
|
||||
#property description "Example EA: Trading based on moving average && price crossover."
|
||||
#property description "MA1 needs to be enabled on the inicator creating the chart."
|
||||
#property description " "
|
||||
#property description "GNU General Public License v3.0"
|
||||
|
||||
//#define RANGEBAR_LICENSE // uncomment when used on a Tick & Volume bar chart from https://www.az-invest.eu/rangebars-for-metatrader-5
|
||||
//#define ULTIMATE_RENKO_LICENSE // uncomment when used on Ultimate Renko chart from https://www.az-invest.eu/ultimate-renko-indicator-generator-for-metatrader-5
|
||||
//#define VOLUMECHART_LICENSE // uncomment when used on a Tick & Volume bar chart from https://www.az-invest.eu/Tick-chart-and-volume-chart-for-mt5
|
||||
//#define RANGEBAR_LICENSE // uncomment when used on a Tick & Volume bar chart from https://www.az-invest.eu/rangebars-for-metatrader-5
|
||||
//#define SECONDSCHART_LICENSE // uncomment when used on a Seconds TF bar chart from https://www.az-invest.eu/seconds-timeframe-chart-for-metatrader-5
|
||||
//#define LINEBREAKCHART_LICENSE // uncomment when used on a Line Break chart from https://www.az-invest.eu
|
||||
//#define LINEBREAKCHART_LICENSE // uncomment when used on a Line Break chart from https://www.az-invest.eu/linebreak-chart-for-metatrader-5
|
||||
|
||||
//
|
||||
// Uncomment only ONE of the 5 directives listed below and recompile
|
||||
@@ -20,14 +23,14 @@
|
||||
//#define EA_ON_XTICK_CHART // Use EA on XTick Chart (obsolete)
|
||||
//#define EA_ON_TICK_VOLUME_CHART // Use EA on Tick & Volume Bar Chart
|
||||
//#define EA_ON_SECONDS_CHART // Use EA on Seconds Interval chart
|
||||
//#define EA_ON_LINEBREAK_CHART // Use EA on LineBreak charts
|
||||
//#define EA_ON_LINEBREAK_CHART // Use EA on LineBreak charts
|
||||
|
||||
//#define DEVELOPER_VERSION // used when I develop ;) should always be commented out
|
||||
|
||||
// Uncomment the directive below and recompile if EA is used with P-Renko BR Ultimate
|
||||
// ----------------------------------------------------------------------------------
|
||||
//
|
||||
// #define P_RENKO_BR_PRO // Use in P-Renko BR Ultimate version
|
||||
//#define P_RENKO_BR_PRO // Use in P-Renko BR Ultimate version
|
||||
|
||||
//
|
||||
// Uncomment the directive below and recompile for use in a backtest only
|
||||
@@ -64,6 +67,7 @@
|
||||
|
||||
#include <AZ-INVEST/SDK/TimeControl.mqh>
|
||||
#include <AZ-INVEST/SDK/TradeFunctions.mqh>
|
||||
#include <AZ-INVEST/SDK/TradeManager.mqh>
|
||||
|
||||
enum ENUM_TRADE_DIRECTION
|
||||
{
|
||||
@@ -79,18 +83,26 @@ input double Lots = 0.1; // Trade
|
||||
input uint StopLoss = 0; // Stop Loss
|
||||
input uint TakeProfit = 0; // Take profit
|
||||
input int ConfirmationBars = 1; // Signal confirmation bars
|
||||
input int PrevSignalBars = 1; // Prev signal confirmation bars
|
||||
input int PrevSignalBars = 1; // Prev. signal confirmation bars
|
||||
input ENUM_TRADE_DIRECTION ValidTradeDirection = TRADE_DIRECTION_ALL; // Valid trading type
|
||||
input bool CloseTradeOnSignalChange = true; // Close trade on signal change
|
||||
input bool ForceSR = false; // Force Stop & Reverse
|
||||
input bool CloseTradeAfterTradingHours = true; // Close trade after trading hours
|
||||
input ulong DeviationPoints = 0; // Maximum defiation (in points)
|
||||
input double ManualTickSize = 0.000; // Tick Size (0 = auto detect)
|
||||
input group "### Trading schedule (Non stop if start = 0 & end = 0)"
|
||||
input string Start="9:00"; // Start trading at
|
||||
input string End="17:55"; // End trading at
|
||||
input bool CloseTradeAfterTradingHours = true; // Close trade after trading hours
|
||||
input group "### Trade management";
|
||||
input int InpBEPoints = 0; // BreakEven (Points) [ 0 = OFF ]
|
||||
input int InpTrailByPoints = 0; // Trail by (Points) [ 0 = OFF ]
|
||||
input int InpTrailStartPoints = 150; // Start trailing after (Points)
|
||||
input int InpPartialCloseAtProfitPoints = 0; // Partial close at (Points) [ 0 = OFF ]
|
||||
input int InpPartialClosePercentage = 50; // Partial close %
|
||||
input group "### Misc";
|
||||
input ulong MagicNumber=8888; // Assign trade ID
|
||||
input ulong DeviationPoints = 0; // Maximum defiation (in points)
|
||||
input double ManualTickSize = 0.000; // Tick Size (0 = auto detect)
|
||||
input int NumberOfRetries = 50; // Maximum number of retries
|
||||
input int BusyTimeout_ms = 1000; // Wait [ms] before retry on bussy errors
|
||||
input int BusyTimeout_ms = 1000; // Wait [ms] before retry on busy errors
|
||||
input int RequoteTimeout_ms = 250; // Wait [ms] before retry on requotes
|
||||
|
||||
// Global data buffers
|
||||
@@ -107,10 +119,12 @@ int _prevSignalBars;
|
||||
|
||||
// EA variables
|
||||
|
||||
CMarketOrder *marketOrder;
|
||||
CTimeControl *timeControl;
|
||||
CMarketOrder *marketOrder = NULL;
|
||||
CTimeControl *timeControl = NULL;
|
||||
CTradeManager *tradeManager = NULL;
|
||||
|
||||
ulong currentTicket;
|
||||
CTradeManagerState tradeManagerState;
|
||||
ENUM_POSITION_TYPE currentPositionType;
|
||||
ENUM_POSITION_TYPE signal;
|
||||
ENUM_POSITION_TYPE validation;
|
||||
@@ -168,6 +182,8 @@ int OnInit()
|
||||
}
|
||||
|
||||
customBars.Init();
|
||||
if(customBars.GetHandle() == INVALID_HANDLE)
|
||||
return(INIT_FAILED);
|
||||
|
||||
signal = POSITION_TYPE_NONE;
|
||||
_confirmationBars = (ConfirmationBars < 1) ? 1 : ConfirmationBars;
|
||||
@@ -195,6 +211,24 @@ int OnInit()
|
||||
|
||||
timeControl.SetValidTraingHours(Start,End);
|
||||
|
||||
//
|
||||
// Init TradeManager
|
||||
//
|
||||
|
||||
CTradeManagerParameters params2;
|
||||
{
|
||||
params2.BEPoints = InpBEPoints;
|
||||
params2.TrailByPoints = InpTrailByPoints;
|
||||
params2.TrailStartPoints = InpTrailStartPoints;
|
||||
params2.PartialCloseAtProfitPoints = InpPartialCloseAtProfitPoints;
|
||||
params2.PartialClosePercentage = InpPartialClosePercentage;
|
||||
}
|
||||
|
||||
if(tradeManager == NULL)
|
||||
{
|
||||
tradeManager = new CTradeManager(params2, marketOrder);
|
||||
}
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -228,6 +262,12 @@ void OnDeinit(const int reason)
|
||||
customBars = NULL;
|
||||
}
|
||||
|
||||
if(tradeManager != NULL)
|
||||
{
|
||||
delete tradeManager;
|
||||
tradeManager = NULL;
|
||||
}
|
||||
|
||||
Comment("");
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
@@ -235,20 +275,15 @@ void OnDeinit(const int reason)
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTick()
|
||||
{
|
||||
if(marketOrder == NULL)
|
||||
if(marketOrder == NULL || customBars == NULL || timeControl == NULL || tradeManager == NULL)
|
||||
return;
|
||||
|
||||
if(customBars.IsNewBar())
|
||||
|
||||
// trade management
|
||||
|
||||
if(marketOrder.IsOpen(currentTicket, _Symbol, MagicNumber))
|
||||
{
|
||||
if(timeControl.IsScheduleEnabled())
|
||||
{
|
||||
Comment("EA trading schedule ON ("+Start+" to "+End+") | trading enabled = "+(string)timeControl.IsTradingTimeValid());
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment("EA trading schedule OFF");
|
||||
}
|
||||
|
||||
// checks done on every tick
|
||||
|
||||
if(!timeControl.IsTradingTimeValid())
|
||||
{
|
||||
if(marketOrder.IsOpen(currentTicket,_Symbol,MagicNumber))
|
||||
@@ -262,7 +297,23 @@ void OnTick()
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
tradeManager.Manage(currentTicket, tradeManagerState);
|
||||
}
|
||||
|
||||
// Signal handler
|
||||
|
||||
if(customBars.IsNewBar())
|
||||
{
|
||||
if(timeControl.IsScheduleEnabled())
|
||||
{
|
||||
Comment("EA trading schedule ON ("+Start+" to "+End+") | trading enabled = "+(string)timeControl.IsTradingTimeValid());
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment("EA trading schedule OFF");
|
||||
}
|
||||
|
||||
//
|
||||
// Get MqlRateInfo & moving average values for current, last completed bar and the bar before that...
|
||||
//
|
||||
@@ -283,17 +334,19 @@ void OnTick()
|
||||
if(timeControl.IsScheduleEnabled())
|
||||
{
|
||||
Comment("EA trading schedule ("+Start+" to "+End+") | trading enabled = "+(string)timeControl.IsTradingTimeValid()+
|
||||
"\n MA_1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
"\n Close[2]: "+DoubleToString(RateInfo[2].close,_Digits)+" [1]: "+DoubleToString(RateInfo[1].close,_Digits)+
|
||||
//"\n MA_1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
//"\n Close[2]: "+DoubleToString(RateInfo[2].close,_Digits)+" [1]: "+DoubleToString(RateInfo[1].close,_Digits)+
|
||||
"\n Price & MA cross signal = "+marketOrder.PositionTypeToString(signal)+
|
||||
"\n Trade manager: "+tradeManager.ToString()+
|
||||
"\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
Comment("EA trading schedule not used. Trading is enabled."+
|
||||
"\n MA_1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
"\n Close[2]: "+DoubleToString(RateInfo[2].close,_Digits)+" [1]: "+DoubleToString(RateInfo[1].close,_Digits)+
|
||||
//"\n MA_1 [2]: "+DoubleToString(MA1[2],_Digits)+" [1]: "+DoubleToString(MA1[1],_Digits)+
|
||||
//"\n Close[2]: "+DoubleToString(RateInfo[2].close,_Digits)+" [1]: "+DoubleToString(RateInfo[1].close,_Digits)+
|
||||
"\n Price & MA cross signal = "+marketOrder.PositionTypeToString(signal)+
|
||||
"\n Trade manager: "+tradeManager.ToString()+
|
||||
"\n");
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -12,38 +12,35 @@
|
||||
#ifdef SHOW_INDICATOR_INPUTS
|
||||
#ifdef MQL5_MARKET_DEMO // hardcoded values
|
||||
|
||||
int barSizeInTicks = 180; // Range bar size (in ticks)
|
||||
ENUM_BOOL atrEnabled = false; // Enable ATR based bar size calculation
|
||||
ENUM_TIMEFRAMES atrTimeFrame = PERIOD_D1; // Use ATR period
|
||||
int atrPeriod = 14; // ATR period
|
||||
int atrPercentage = 10; // Use percentage of ATR
|
||||
int showNumberOfDays = 7; // Show history for number of days
|
||||
ENUM_BOOL resetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
|
||||
double InpBarSize = 180; // Range bar size
|
||||
ENUM_BAR_SIZE_CALC_MODE InpBarSizeCalcMode = BAR_SIZE_ABSOLUTE_TICKS; // Bar size calculation
|
||||
int InpShowNumberOfDays = 7; // Show history for number of days
|
||||
datetime InpShowFromDate = 0; // Show history starting from
|
||||
ENUM_TIMEFRAMES InpAtrTimeFrame = PERIOD_D1; // ATR timeframe setting
|
||||
int InpAtrPeriod = 14; // ATR period setting
|
||||
ENUM_BOOL InpResetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
|
||||
|
||||
#else // user defined settings
|
||||
|
||||
|
||||
input int barSizeInTicks = 100; // Range bar size (in ticks)
|
||||
input int showNumberOfDays = 5; // Show history for number of days
|
||||
|
||||
input group "### ATR based bar size calculation"
|
||||
input ENUM_BOOL atrEnabled = false; // Enable ATR based bar size calculation
|
||||
input ENUM_TIMEFRAMES atrTimeFrame = PERIOD_D1; // Use ATR period
|
||||
input int atrPeriod = 14; // ATR period
|
||||
input int atrPercentage = 10; // Use percentage of ATR
|
||||
|
||||
input group "### Chart synchronization"
|
||||
input ENUM_BOOL resetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
|
||||
|
||||
input double InpBarSize = 100; // Range bar size
|
||||
input ENUM_BAR_SIZE_CALC_MODE InpBarSizeCalcMode = BAR_SIZE_ABSOLUTE_TICKS;// Bar size calculation
|
||||
input int InpShowNumberOfDays = 5; // Show history for number of days
|
||||
input datetime InpShowFromDate = 0; // Show history starting from
|
||||
input group "### ATR bar size calculation settings"
|
||||
input ENUM_TIMEFRAMES InpAtrTimeFrame = PERIOD_D1; // ATR timeframe setting
|
||||
input int InpAtrPeriod = 14; // ATR period setting
|
||||
input group "### Chart synchronization"
|
||||
input ENUM_BOOL InpResetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
|
||||
|
||||
#endif
|
||||
#else // don't SHOW_INDICATOR_INPUTS
|
||||
int barSizeInTicks = 180; // Range bar size (in ticks)
|
||||
ENUM_BOOL atrEnabled = false; // Enable ATR based bar size calculation
|
||||
ENUM_TIMEFRAMES atrTimeFrame = PERIOD_D1; // Use ATR period
|
||||
int atrPeriod = 14; // ATR period
|
||||
int atrPercentage = 10; // Use percentage of ATR
|
||||
int showNumberOfDays = 7; // Show history for number of days
|
||||
ENUM_BOOL resetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
|
||||
double InpBarSize = 180; // Range bar size
|
||||
ENUM_BAR_SIZE_CALC_MODE InpBarSizeCalcMode = BAR_SIZE_ABSOLUTE_TICKS;// Bar size calculation
|
||||
int InpShowNumberOfDays = 7; // Show history for number of days
|
||||
datetime InpShowFromDate = 0; // Show history starting from
|
||||
ENUM_TIMEFRAMES InpAtrTimeFrame = PERIOD_D1; // ATR timeframe setting
|
||||
int InpAtrPeriod = 14; // ATR period setting
|
||||
ENUM_BOOL InpResetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
|
||||
#endif
|
||||
|
||||
//
|
||||
@@ -52,15 +49,19 @@
|
||||
//
|
||||
#include <az-invest/sdk/CustomChartSettingsBase.mqh>
|
||||
|
||||
#define SETNAME_BAR_SIZE_CALC_MODE "barSizeCalcMode"
|
||||
#define SETNAME_ATR_TIMEFRAME "atrTimeFrame"
|
||||
#define SETNAME_ATR_PERIOD "atrPeriod"
|
||||
|
||||
struct RANGEBAR_SETTINGS
|
||||
{
|
||||
int barSizeInTicks;
|
||||
ENUM_BOOL atrEnabled;
|
||||
ENUM_TIMEFRAMES atrTimeFrame;
|
||||
int atrPeriod;
|
||||
int atrPercentage;
|
||||
int showNumberOfDays;
|
||||
ENUM_BOOL resetOpenOnNewTradingDay;
|
||||
double barSize;
|
||||
ENUM_BAR_SIZE_CALC_MODE barSizeCalcMode;
|
||||
ENUM_TIMEFRAMES atrTimeFrame;
|
||||
int atrPeriod;
|
||||
int showNumberOfDays;
|
||||
datetime showFromDate;
|
||||
ENUM_BOOL resetOpenOnNewTradingDay;
|
||||
};
|
||||
|
||||
|
||||
@@ -109,12 +110,11 @@ uint CRangeBarCustomChartSettigns::CustomChartSettingsFromFile(int file_handle)
|
||||
|
||||
void CRangeBarCustomChartSettigns::SetCustomChartSettings()
|
||||
{
|
||||
settings.barSizeInTicks = barSizeInTicks;
|
||||
|
||||
settings.atrEnabled = atrEnabled;
|
||||
settings.atrTimeFrame = atrTimeFrame;
|
||||
settings.atrPeriod = atrPeriod;
|
||||
settings.atrPercentage = atrPercentage;
|
||||
settings.showNumberOfDays = showNumberOfDays;
|
||||
settings.resetOpenOnNewTradingDay = resetOpenOnNewTradingDay;
|
||||
settings.barSize = InpBarSize;
|
||||
settings.barSizeCalcMode = InpBarSizeCalcMode;
|
||||
settings.showNumberOfDays = InpShowNumberOfDays;
|
||||
settings.showFromDate = InpShowFromDate;
|
||||
settings.atrTimeFrame = InpAtrTimeFrame;
|
||||
settings.atrPeriod = InpAtrPeriod;
|
||||
settings.resetOpenOnNewTradingDay = InpResetOpenOnNewTradingDay;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#property copyright "Copyright 2018-2020, Level Up Software"
|
||||
#property copyright "Copyright 2018-2021, Level Up Software"
|
||||
#property link "http://www.az-invest.eu"
|
||||
|
||||
#ifdef DEVELOPER_VERSION
|
||||
#define RANGEBAR_INDICATOR_NAME "RangeBars\\RangeBarsOverlay300"
|
||||
#define RANGEBAR_INDICATOR_NAME "RangeBars\\RangeBarsOverlay316"
|
||||
#else
|
||||
#ifdef RANGEBAR_LICENSE
|
||||
#ifdef MQL5_MARKET_VERSION
|
||||
@@ -193,23 +193,24 @@ int RangeBars::Init()
|
||||
|
||||
RANGEBAR_SETTINGS s = rangeBarSettings.GetCustomChartSettings();
|
||||
CHART_INDICATOR_SETTINGS cis = rangeBarSettings.GetChartIndicatorSettings();
|
||||
ALERT_INFO_SETTINGS als = rangeBarSettings.GetAlertInfoSettings();
|
||||
|
||||
rangeBarsHandle = iCustom(this.rangeBarsSymbol, _Period, RANGEBAR_INDICATOR_NAME,
|
||||
s.barSizeInTicks,
|
||||
s.barSize,
|
||||
s.barSizeCalcMode,
|
||||
s.showNumberOfDays,
|
||||
s.showFromDate,
|
||||
"=",
|
||||
s.atrEnabled,
|
||||
s.atrTimeFrame,
|
||||
s.atrPeriod,
|
||||
s.atrPercentage,
|
||||
"=",
|
||||
s.resetOpenOnNewTradingDay,
|
||||
"=",
|
||||
showPivots,
|
||||
pivotPointCalculationType,
|
||||
als.showPivots,
|
||||
als.pivotPointCalculationType,
|
||||
"=",
|
||||
AlertMeWhen,
|
||||
AlertNotificationType,
|
||||
InpAlertMeWhen,
|
||||
InpAlertNotificationType,
|
||||
"=",
|
||||
cis.MA1lineType,
|
||||
cis.MA1period,
|
||||
@@ -242,8 +243,7 @@ int RangeBars::Init()
|
||||
cis.ChannelAppliedPrice,
|
||||
cis.ChannelMultiplier,
|
||||
cis.ChannelBandsDeviations,
|
||||
cis.ChannelPriceLabel,
|
||||
cis.ChannelMidPriceLabel,
|
||||
cis.ChannelPriceLabels,
|
||||
"=",
|
||||
true); // used in EA
|
||||
// TopBottomPaddingPercentage,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//
|
||||
// Copyright 2018-19, Artur Zas
|
||||
// Copyright 2018-2021, Artur Zas
|
||||
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
|
||||
// https://www.az-invest.eu
|
||||
// https://www.mql5.com/en/users/arturz
|
||||
//
|
||||
@@ -8,46 +9,100 @@ class CTimeControl
|
||||
{
|
||||
private:
|
||||
|
||||
int scheduleID;
|
||||
|
||||
int startHH;
|
||||
int startMM;
|
||||
string start;
|
||||
datetime startOfSession;
|
||||
|
||||
int endHH;
|
||||
int endMM;
|
||||
string end;
|
||||
datetime endOfSession;
|
||||
|
||||
bool scheduleEnabled;
|
||||
|
||||
public:
|
||||
|
||||
CTimeControl(int id = 0) { scheduleID = id; };
|
||||
|
||||
void SetValidTraingHours(string _from = "0:00", string _to = "0:00");
|
||||
void SetValidTraingHours(bool _unused, string _timeSpan = "0:00-0:00");
|
||||
bool IsTradingTimeValid();
|
||||
bool IsScheduleEnabled() { return scheduleEnabled; };
|
||||
void UpdateSessionDateTime(int addSecods = 0);
|
||||
datetime GetSessionStartTime() { return startOfSession; };
|
||||
datetime GetSessionEndTime() { return endOfSession; };
|
||||
void MoveSessionStartToNow();
|
||||
string ToString();
|
||||
|
||||
private:
|
||||
|
||||
void StringToHHMM(string value, int &HH, int &MM);
|
||||
bool StringToHHMMRange(string value, int &startHH, int &startMM, string& _start, int &endHH, int &endMM, string& _end);
|
||||
void SetScheduleState();
|
||||
};
|
||||
|
||||
void CTimeControl::SetValidTraingHours(string _from,string _to)
|
||||
void CTimeControl::SetValidTraingHours(string _from, string _to)
|
||||
{
|
||||
this.start = _from;
|
||||
this.end = _to;
|
||||
|
||||
StringToHHMM(this.start, this.startHH, this.startMM);
|
||||
StringToHHMM(this.end, this.endHH, this.endMM);
|
||||
UpdateSessionDateTime();
|
||||
|
||||
if(this.startHH == 0 && this.startMM == 0 && this.endHH == 0 && this.endMM == 0)
|
||||
SetScheduleState();
|
||||
}
|
||||
|
||||
void CTimeControl::MoveSessionStartToNow()
|
||||
{
|
||||
datetime now = TimeCurrent();
|
||||
|
||||
MqlDateTime temp;
|
||||
TimeToStruct(now,temp);
|
||||
|
||||
startHH = temp.hour;
|
||||
startMM = temp.min;
|
||||
start = StringFormat("%02d:%02d", startHH, startMM);
|
||||
|
||||
UpdateSessionDateTime(temp.sec + 1);
|
||||
}
|
||||
|
||||
void CTimeControl::UpdateSessionDateTime(int addSecods = 0)
|
||||
{
|
||||
datetime now = TimeCurrent();
|
||||
|
||||
MqlDateTime temp;
|
||||
TimeToStruct(now,temp);
|
||||
|
||||
if(addSecods > 0)
|
||||
{
|
||||
scheduleEnabled = false;
|
||||
string startTimeTemp = StringFormat("%s:%02d", this.start, addSecods);
|
||||
startOfSession = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+startTimeTemp);
|
||||
}
|
||||
else
|
||||
{
|
||||
scheduleEnabled = true;
|
||||
startOfSession = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.start);
|
||||
}
|
||||
|
||||
endOfSession = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.end);
|
||||
}
|
||||
|
||||
void CTimeControl::SetValidTraingHours(bool _unused, string _timeSpan = "0:00-0:00")
|
||||
{
|
||||
if(!StringToHHMMRange(_timeSpan, this.startHH, this.startMM, this.start, this.endHH, this.endMM, this.end))
|
||||
return;
|
||||
|
||||
UpdateSessionDateTime();
|
||||
SetScheduleState();
|
||||
}
|
||||
|
||||
bool CTimeControl::IsTradingTimeValid()
|
||||
{
|
||||
if(scheduleEnabled == false)
|
||||
return true;
|
||||
return true;
|
||||
|
||||
datetime now = TimeCurrent();
|
||||
|
||||
@@ -57,12 +112,32 @@ bool CTimeControl::IsTradingTimeValid()
|
||||
datetime _start = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.start);
|
||||
datetime _end = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.end);
|
||||
|
||||
if((now >= _start) && (now <= _end))
|
||||
if(_start <= now && now <= _end)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
string CTimeControl::ToString()
|
||||
{
|
||||
string tradingScheduleName = "Trading schedule ";
|
||||
|
||||
tradingScheduleName += (scheduleID != 0)
|
||||
? (string)scheduleID+" "
|
||||
: "";
|
||||
|
||||
if(IsScheduleEnabled())
|
||||
{
|
||||
return tradingScheduleName+"ON ("+this.start+" to "+this.end+") | trading "+(IsTradingTimeValid()
|
||||
? "enabled"
|
||||
: "disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
return tradingScheduleName+"NOT USED";
|
||||
}
|
||||
}
|
||||
|
||||
void CTimeControl::StringToHHMM(string value, int &HH, int &MM)
|
||||
{
|
||||
MqlDateTime temp;
|
||||
@@ -73,4 +148,46 @@ void CTimeControl::StringToHHMM(string value, int &HH, int &MM)
|
||||
|
||||
HH = temp.hour;
|
||||
MM = temp.min;
|
||||
}
|
||||
}
|
||||
|
||||
bool CTimeControl::StringToHHMMRange(string value, int &_startHH, int &_startMM, string& _start, int &_endHH, int &_endMM, string& _end)
|
||||
{
|
||||
string result[];
|
||||
int count = StringSplit(value, '-', result);
|
||||
if(count != 2)
|
||||
return false;
|
||||
|
||||
MqlDateTime temp;
|
||||
TimeToStruct(TimeCurrent(),temp);
|
||||
|
||||
// Start time
|
||||
_start = result[0];
|
||||
datetime fullDateTime = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+_start);
|
||||
TimeToStruct(fullDateTime,temp);
|
||||
|
||||
startHH = temp.hour;
|
||||
startMM = temp.min;
|
||||
|
||||
// End time
|
||||
TimeToStruct(TimeCurrent(),temp);
|
||||
_end = result[1];
|
||||
fullDateTime = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+_end);
|
||||
TimeToStruct(fullDateTime,temp);
|
||||
|
||||
endHH = temp.hour;
|
||||
endMM = temp.min;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CTimeControl::SetScheduleState()
|
||||
{
|
||||
if(this.startHH == 0 && this.startMM == 0 && this.endHH == 0 && this.endMM == 0)
|
||||
{
|
||||
scheduleEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
scheduleEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//
|
||||
// Copyright 2017-2018, Artur Zas
|
||||
// Copyright 2017-2021, Artur Zas
|
||||
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
|
||||
// https://www.az-invest.eu
|
||||
// https://www.mql5.com/en/users/arturz
|
||||
//
|
||||
@@ -732,8 +733,26 @@ bool CMarketOrder::ClosePartial(ulong ticket, double lots)
|
||||
|
||||
while(!IsStopped() && !result)
|
||||
{
|
||||
result = ctrade.PositionClosePartial(ticket, NormalizeLots(symbol,lots));
|
||||
if(_IsNettingAccount()) // Netting account type
|
||||
{
|
||||
// open opposite position with volume = "lots" to do a parial close
|
||||
|
||||
ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
|
||||
|
||||
if(type == POSITION_TYPE_BUY)
|
||||
{
|
||||
result = this.Short(symbol,lots,0,0);
|
||||
}
|
||||
else if(type == POSITION_TYPE_SELL)
|
||||
{
|
||||
result = this.Long(symbol,lots,0,0);
|
||||
}
|
||||
}
|
||||
else // Hedging account type
|
||||
{
|
||||
result = ctrade.PositionClosePartial(ticket, lots);
|
||||
}
|
||||
|
||||
if(result)
|
||||
{
|
||||
Sleep(500);
|
||||
@@ -1072,5 +1091,3 @@ void CMarketOrder::SetTradeId(ulong tradeId)
|
||||
ctrade.SetExpertMagicNumber(tradeId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
//
|
||||
// Copyright 2018-2021, Artur Zas
|
||||
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
|
||||
// https://www.az-invest.eu
|
||||
// https://www.mql5.com/en/users/arturz
|
||||
//
|
||||
|
||||
#include <AZ-INVEST/SDK/TradeFunctions.mqh>
|
||||
|
||||
class CTradeManagerState
|
||||
{
|
||||
public:
|
||||
|
||||
void Clear() { DoneBreakEven = false; TrailStarted = false; DonePartialClose = false; };
|
||||
|
||||
// Break Even
|
||||
bool DoneBreakEven;
|
||||
|
||||
// Trailing Stop
|
||||
bool TrailStarted;
|
||||
|
||||
// Partial Close
|
||||
bool DonePartialClose;
|
||||
};
|
||||
|
||||
struct CTradeManagerParameters
|
||||
{
|
||||
// Break Even
|
||||
int BEPoints;
|
||||
|
||||
// Trailing Stop
|
||||
int TrailByPoints;
|
||||
int TrailStartPoints;
|
||||
|
||||
// Partial Close
|
||||
int PartialCloseAtProfitPoints;
|
||||
int PartialClosePercentage;
|
||||
};
|
||||
|
||||
class CTradeManager
|
||||
{
|
||||
private:
|
||||
|
||||
bool initialized;
|
||||
CMarketOrder *orderHandler;
|
||||
CTradeManagerParameters inputs;
|
||||
|
||||
ENUM_ORDER_TYPE __type;
|
||||
double __open;
|
||||
double __lots;
|
||||
string __symbol;
|
||||
double __tp;
|
||||
double __sl;
|
||||
double __bid;
|
||||
double __ask;
|
||||
|
||||
public:
|
||||
|
||||
CTradeManager();
|
||||
CTradeManager(CTradeManagerParameters ¶ms, CMarketOrder *orderHalder);
|
||||
~CTradeManager();
|
||||
|
||||
bool IsInitialized() { return this.initialized; };
|
||||
bool Initialize(CTradeManagerParameters ¶ms, CMarketOrder *orderHalder);
|
||||
bool Manage(ulong ticket, CTradeManagerState &_state);
|
||||
string ToString();
|
||||
|
||||
private:
|
||||
|
||||
bool GetTradeInfo(ulong ticket);
|
||||
bool BreakEven(ulong ticket);
|
||||
bool OkToTrailTheStop(ulong ticket);
|
||||
bool TrailTheStop(ulong ticket);
|
||||
bool PartialClose(ulong ticket, double lots);
|
||||
double GetPartialCloseLotSize();
|
||||
bool IsDistanceFromOpenReached(double distancePriceDiff);
|
||||
ENUM_ORDER_TYPE GetType(ulong ticket);
|
||||
};
|
||||
|
||||
|
||||
CTradeManager::CTradeManager(void)
|
||||
{
|
||||
this.orderHandler = NULL;
|
||||
this.initialized = false;
|
||||
}
|
||||
|
||||
CTradeManager::CTradeManager(CTradeManagerParameters ¶ms,CMarketOrder *_orderHandler)
|
||||
{
|
||||
this.orderHandler = NULL;
|
||||
this.initialized = false;
|
||||
Initialize(params, _orderHandler);
|
||||
}
|
||||
|
||||
CTradeManager::~CTradeManager(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CTradeManager::GetTradeInfo(ulong ticket)
|
||||
{
|
||||
__type = GetType(ticket);
|
||||
__open = PositionGetDouble(POSITION_PRICE_OPEN);
|
||||
if(__open == 0)
|
||||
return false;
|
||||
|
||||
__lots = PositionGetDouble(POSITION_VOLUME);
|
||||
__symbol = PositionGetString(POSITION_SYMBOL);
|
||||
__tp = PositionGetDouble(POSITION_TP);
|
||||
__sl = PositionGetDouble(POSITION_SL);
|
||||
__bid = SymbolInfoDouble(__symbol,SYMBOL_BID);
|
||||
__ask = SymbolInfoDouble(__symbol,SYMBOL_ASK);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTradeManager::Initialize(CTradeManagerParameters ¶ms, CMarketOrder *_orderHandler)
|
||||
{
|
||||
// Dependency injection
|
||||
this.orderHandler = _orderHandler;
|
||||
if(this.orderHandler == NULL)
|
||||
{
|
||||
Print(__FUNCTION__," failed on orderHandler == NULL");
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
this.inputs = params;
|
||||
|
||||
// normalize inputs
|
||||
this.inputs.PartialClosePercentage = MathMin(MathAbs(this.inputs.PartialClosePercentage), 100);
|
||||
|
||||
//
|
||||
this.initialized = true;
|
||||
return initialized;
|
||||
}
|
||||
|
||||
bool CTradeManager::Manage(ulong ticket, CTradeManagerState &_state)
|
||||
{
|
||||
if(!GetTradeInfo(ticket))
|
||||
return false; // trade info not available
|
||||
|
||||
if(!_state.DonePartialClose)
|
||||
{
|
||||
_state.DonePartialClose = PartialClose(ticket, GetPartialCloseLotSize());
|
||||
}
|
||||
|
||||
if(!_state.DoneBreakEven)
|
||||
{
|
||||
if(BreakEven(ticket))
|
||||
_state.DoneBreakEven = true;
|
||||
}
|
||||
|
||||
if(!_state.TrailStarted)
|
||||
{
|
||||
_state.TrailStarted = OkToTrailTheStop(ticket);
|
||||
}
|
||||
|
||||
if(_state.TrailStarted)
|
||||
{
|
||||
TrailTheStop(ticket);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTradeManager::PartialClose(ulong ticket, double lots)
|
||||
{
|
||||
if(this.inputs.PartialCloseAtProfitPoints == 0 || lots == 0)
|
||||
return false; // nothing to do
|
||||
|
||||
double _partialCloseDistance = SymbolInfoDouble(__symbol,SYMBOL_POINT) * this.inputs.PartialCloseAtProfitPoints;
|
||||
if(!IsDistanceFromOpenReached(_partialCloseDistance))
|
||||
return false;
|
||||
|
||||
return orderHandler.ClosePartial(ticket, lots);
|
||||
}
|
||||
|
||||
bool CTradeManager::BreakEven(ulong ticket)
|
||||
{
|
||||
if(this.inputs.BEPoints == 0)
|
||||
return false; // nothing to do
|
||||
|
||||
double _beDistance = SymbolInfoDouble(__symbol,SYMBOL_POINT) * this.inputs.BEPoints;
|
||||
if(!IsDistanceFromOpenReached(_beDistance))
|
||||
return false;
|
||||
|
||||
return orderHandler.Modify(ticket,__open,__tp);
|
||||
}
|
||||
|
||||
bool CTradeManager::OkToTrailTheStop(ulong ticket)
|
||||
{
|
||||
if(this.inputs.TrailByPoints == 0)
|
||||
return false; // nothing to do
|
||||
|
||||
double _startDistance = SymbolInfoDouble(__symbol,SYMBOL_POINT) * this.inputs.TrailStartPoints;
|
||||
if(!IsDistanceFromOpenReached(_startDistance))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTradeManager::TrailTheStop(ulong ticket)
|
||||
{
|
||||
if(this.inputs.TrailByPoints == 0)
|
||||
return false; // nothing to do
|
||||
|
||||
double _trailDistance = SymbolInfoDouble(__symbol,SYMBOL_POINT) * this.inputs.TrailByPoints;
|
||||
double _sl = __sl;
|
||||
bool okToModify = false;
|
||||
|
||||
if(__type == ORDER_TYPE_BUY)
|
||||
{
|
||||
_sl = (__bid - _trailDistance);
|
||||
if(_sl > __sl)
|
||||
okToModify = true;
|
||||
}
|
||||
else if(__type == ORDER_TYPE_SELL)
|
||||
{
|
||||
_sl = (__ask + _trailDistance);
|
||||
if(_sl < __sl)
|
||||
okToModify = true;
|
||||
}
|
||||
|
||||
if(okToModify)
|
||||
return orderHandler.Modify(ticket,_sl,__tp);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ENUM_ORDER_TYPE CTradeManager::GetType(ulong ticket)
|
||||
{
|
||||
ENUM_POSITION_TYPE _pType;
|
||||
orderHandler.GetPositionType(ticket,_pType);
|
||||
|
||||
return orderHandler.TradeBias((ENUM_ORDER_TYPE)_pType);
|
||||
}
|
||||
|
||||
double CTradeManager::GetPartialCloseLotSize()
|
||||
{
|
||||
double lotsToClose = (__lots * inputs.PartialClosePercentage) / 100;
|
||||
return NormalizeLots(__symbol, lotsToClose);
|
||||
}
|
||||
|
||||
bool CTradeManager::IsDistanceFromOpenReached(double distancePriceDiff)
|
||||
{
|
||||
if(__type == ORDER_TYPE_BUY)
|
||||
{
|
||||
if((__bid - distancePriceDiff) >= __open)
|
||||
return true;
|
||||
}
|
||||
else if(__type == ORDER_TYPE_SELL)
|
||||
{
|
||||
if((__ask + distancePriceDiff) <= __open)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
string CTradeManager::ToString()
|
||||
{
|
||||
string _be = (inputs.BEPoints > 0) ? "[BE ON] " : "[BE off] ";
|
||||
string _trail = (inputs.TrailByPoints > 0) ? "[Trail ON] ": "[Trail off] ";
|
||||
string _partial = (inputs.PartialCloseAtProfitPoints > 0) ? "[Partial "+(string)inputs.PartialClosePercentage+"%] ": "[Partial off] ";
|
||||
|
||||
return _be+_trail+_partial;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,7 +14,7 @@
|
||||
#property indicator_color1 DodgerBlue
|
||||
#property indicator_label1 "ATR"
|
||||
//--- input parameters
|
||||
input int InpAtrPeriod=14; // ATR period
|
||||
input int Inp_AtrPeriod=14; // ATR period
|
||||
//--- indicator buffers
|
||||
double ExtATRBuffer[];
|
||||
double ExtTRBuffer[];
|
||||
@@ -33,19 +33,19 @@ int ExtPeriodATR;
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input value
|
||||
if(InpAtrPeriod<=0)
|
||||
if(Inp_AtrPeriod<=0)
|
||||
{
|
||||
ExtPeriodATR=14;
|
||||
printf("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",InpAtrPeriod,ExtPeriodATR);
|
||||
printf("Incorrect input parameter InpAtrPeriod = %d. Indicator will use value %d for calculations.",Inp_AtrPeriod,ExtPeriodATR);
|
||||
}
|
||||
else ExtPeriodATR=InpAtrPeriod;
|
||||
else ExtPeriodATR=Inp_AtrPeriod;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,ExtATRBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,ExtTRBuffer,INDICATOR_CALCULATIONS);
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- sets first bar from what index will be drawn
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpAtrPeriod);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,Inp_AtrPeriod);
|
||||
//--- name for DataWindow and indicator subwindow label
|
||||
string short_name="ATR("+string(ExtPeriodATR)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,169 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| BB.mq5 |
|
||||
//| Copyright 2009-2020, MetaQuotes Software Corp. |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "2009-2020, MetaQuotes Software Corp."
|
||||
#property link "http://www.mql5.com"
|
||||
#property description "Bollinger Bands"
|
||||
#include <MovingAverages.mqh>
|
||||
#include <AZ-INVEST/CustomBarConfig.mqh>
|
||||
//---
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 3
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 LightSeaGreen
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 LightSeaGreen
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 LightSeaGreen
|
||||
#property indicator_label1 "Bands middle"
|
||||
#property indicator_label2 "Bands upper"
|
||||
#property indicator_label3 "Bands lower"
|
||||
//--- input parametrs
|
||||
input int InpBandsPeriod=20; // Period
|
||||
input int InpBandsShift=0; // Shift
|
||||
input double InpBandsDeviations=2.0; // Deviation
|
||||
input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price
|
||||
//--- global variables
|
||||
int ExtBandsPeriod,ExtBandsShift;
|
||||
double ExtBandsDeviations;
|
||||
int ExtPlotBegin=0;
|
||||
//--- indicator buffer
|
||||
double ExtMLBuffer[];
|
||||
double ExtTLBuffer[];
|
||||
double ExtBLBuffer[];
|
||||
double ExtStdDevBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnInit()
|
||||
{
|
||||
//--- check for input values
|
||||
if(InpBandsPeriod<2)
|
||||
{
|
||||
ExtBandsPeriod=20;
|
||||
PrintFormat("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod);
|
||||
}
|
||||
else
|
||||
ExtBandsPeriod=InpBandsPeriod;
|
||||
if(InpBandsShift<0)
|
||||
{
|
||||
ExtBandsShift=0;
|
||||
PrintFormat("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift);
|
||||
}
|
||||
else
|
||||
ExtBandsShift=InpBandsShift;
|
||||
if(InpBandsDeviations==0.0)
|
||||
{
|
||||
ExtBandsDeviations=2.0;
|
||||
PrintFormat("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations);
|
||||
}
|
||||
else
|
||||
ExtBandsDeviations=InpBandsDeviations;
|
||||
//--- define buffers
|
||||
SetIndexBuffer(0,ExtMLBuffer);
|
||||
SetIndexBuffer(1,ExtTLBuffer);
|
||||
SetIndexBuffer(2,ExtBLBuffer);
|
||||
SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS);
|
||||
//--- set index labels
|
||||
PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle");
|
||||
PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper");
|
||||
PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower");
|
||||
//--- indicator name
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands");
|
||||
//--- indexes draw begin settings
|
||||
ExtPlotBegin=ExtBandsPeriod-1;
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod);
|
||||
//--- indexes shift settings
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift);
|
||||
PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift);
|
||||
PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift);
|
||||
//--- number of digits of indicator value
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
|
||||
customChartIndicator.SetUseAppliedPriceFlag(InpAppliedPrice);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Bollinger Bands |
|
||||
//+------------------------------------------------------------------+
|
||||
/*
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
*/
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
static int begin = 0;
|
||||
|
||||
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
|
||||
return(0);
|
||||
|
||||
if(!customChartIndicator.BufferSynchronizationCheck(close))
|
||||
return(0);
|
||||
|
||||
int _prev_calculated = customChartIndicator.GetPrevCalculated();
|
||||
int _rates_total = ArraySize(customChartIndicator.Close);
|
||||
|
||||
if(_rates_total<ExtPlotBegin)
|
||||
return(0);
|
||||
|
||||
//--- indexes draw begin settings, when we've recieved previous begin
|
||||
if(ExtPlotBegin!=ExtBandsPeriod+begin)
|
||||
{
|
||||
ExtPlotBegin=ExtBandsPeriod+begin;
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin);
|
||||
}
|
||||
//--- starting calculation
|
||||
int pos;
|
||||
if(_prev_calculated>1)
|
||||
pos=_prev_calculated-1;
|
||||
else
|
||||
pos=0;
|
||||
//--- main cycle
|
||||
for(int i=pos; i<_rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//--- middle line
|
||||
ExtMLBuffer[i]=SimpleMA(i,ExtBandsPeriod,customChartIndicator.Price);
|
||||
//--- calculate and write down StdDev
|
||||
ExtStdDevBuffer[i]=StdDev_Func(i,customChartIndicator.Price,ExtMLBuffer,ExtBandsPeriod);
|
||||
//--- upper line
|
||||
ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i];
|
||||
//--- lower line
|
||||
ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i];
|
||||
}
|
||||
//--- OnCalculate done. Return new prev_calculated.
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate Standard Deviation |
|
||||
//+------------------------------------------------------------------+
|
||||
double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period)
|
||||
{
|
||||
double std_dev=0.0;
|
||||
//--- calcualte StdDev
|
||||
if(position>=period)
|
||||
{
|
||||
for(int i=0; i<period; i++)
|
||||
std_dev+=MathPow(price[position-i]-ma_price[position],2.0);
|
||||
std_dev=MathSqrt(std_dev/period);
|
||||
}
|
||||
//--- return calculated value
|
||||
return(std_dev);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,10 +16,10 @@
|
||||
#property indicator_color1 clrDodgerBlue, clrOrangeRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
#property indicator_label1 "GHL (13, SMMA)"
|
||||
#property indicator_label1 "GHL_SSL"
|
||||
//--- input parameters
|
||||
input uint InpPeriod=13; // Period
|
||||
input ENUM_MA_METHOD InpMethod=MODE_SMMA;// Method
|
||||
input uint InpPeriod=10; // Period
|
||||
input ENUM_MA_METHOD InpMethod=MODE_SMA;// Method
|
||||
//--- buffers
|
||||
double GannBuffer[];
|
||||
double ColorBuffer[];
|
||||
@@ -27,12 +27,12 @@ double MaHighBuffer[];
|
||||
double MaLowBuffer[];
|
||||
double TrendBuffer[];
|
||||
//--- global vars
|
||||
int ma_high_handle;
|
||||
int ma_low_handle;
|
||||
int period;
|
||||
//int ma_high_handle;
|
||||
//int ma_low_handle;
|
||||
int _period;
|
||||
|
||||
//
|
||||
|
||||
#include <MovingAverages.mqh>
|
||||
#include <AZ-INVEST/CustomBarConfig.mqh>
|
||||
|
||||
//
|
||||
@@ -43,7 +43,7 @@ int period;
|
||||
int OnInit()
|
||||
{
|
||||
//--- check period
|
||||
period=(int)fmax(InpPeriod,2);
|
||||
_period=(int)fmax(InpPeriod,2);
|
||||
//--- set buffers
|
||||
SetIndexBuffer(0,GannBuffer);
|
||||
SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
@@ -57,19 +57,19 @@ int OnInit()
|
||||
ArraySetAsSeries(MaLowBuffer,true);
|
||||
ArraySetAsSeries(TrendBuffer,true);
|
||||
//--- get handles
|
||||
ma_high_handle=iMA(NULL,0,period,0,InpMethod,PRICE_HIGH);
|
||||
ma_low_handle =iMA(NULL,0,period,0,InpMethod,PRICE_LOW);
|
||||
if(ma_high_handle==INVALID_HANDLE || ma_low_handle==INVALID_HANDLE)
|
||||
{
|
||||
Print("Unable to create handle for iMA");
|
||||
return(INIT_FAILED);
|
||||
}
|
||||
//ma_high_handle=iMA(NULL,0,_period,0,InpMethod,PRICE_HIGH);
|
||||
//ma_low_handle =iMA(NULL,0,_period,0,InpMethod,PRICE_LOW);
|
||||
//if(ma_high_handle==INVALID_HANDLE || ma_low_handle==INVALID_HANDLE)
|
||||
// {
|
||||
// Print("Unable to create handle for iMA");
|
||||
// return(INIT_FAILED);
|
||||
// }
|
||||
//--- set indicator properties
|
||||
string short_name=StringFormat("Gann High-Low Activator SSL (%u, %s)",period,StringSubstr(EnumToString(InpMethod),5));
|
||||
string short_name=StringFormat("Gann High-Low Activator SSL (%u, %s)",_period,StringSubstr(EnumToString(InpMethod),5));
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
//--- set label
|
||||
short_name=StringFormat("GHL (%u, %s)",period,StringSubstr(EnumToString(InpMethod),5));
|
||||
short_name=StringFormat("GHL (%u, %s)",_period,StringSubstr(EnumToString(InpMethod),5));
|
||||
PlotIndexSetString(0,PLOT_LABEL,short_name);
|
||||
//--- done
|
||||
return(INIT_SUCCEEDED);
|
||||
@@ -89,7 +89,7 @@ int OnCalculate(const int rates_total,
|
||||
const int &spread[])
|
||||
{
|
||||
|
||||
if(rates_total<period+1)return(0);
|
||||
//if(rates_total<_period+1)return(0);
|
||||
|
||||
//
|
||||
// Process data through MedianRenko indicator
|
||||
@@ -135,7 +135,7 @@ int OnCalculate(const int rates_total,
|
||||
int limit;
|
||||
if(rates_total<_prev_calculated || _prev_calculated<=0)
|
||||
{
|
||||
limit=rates_total-period-1;
|
||||
limit=rates_total-_period-1;
|
||||
ArrayInitialize(GannBuffer,EMPTY_VALUE);
|
||||
ArrayInitialize(ColorBuffer,0);
|
||||
ArrayInitialize(MaHighBuffer,0);
|
||||
@@ -145,8 +145,30 @@ int OnCalculate(const int rates_total,
|
||||
else
|
||||
limit=rates_total-_prev_calculated;
|
||||
//--- get MA
|
||||
if(CopyBuffer(ma_high_handle,0,0,limit+1,MaHighBuffer)!=limit+1)return(0);
|
||||
if(CopyBuffer(ma_low_handle,0,0,limit+1,MaLowBuffer)!=limit+1)return(0);
|
||||
//if(CopyBuffer(ma_high_handle,0,0,limit+1,MaHighBuffer)!=limit+1)return(0);
|
||||
//if(CopyBuffer(ma_low_handle,0,0,limit+1,MaLowBuffer)!=limit+1)return(0);
|
||||
|
||||
switch(InpMethod)
|
||||
{
|
||||
case MODE_SMA:
|
||||
SimpleMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
|
||||
SimpleMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
|
||||
break;
|
||||
case MODE_EMA:
|
||||
ExponentialMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
|
||||
ExponentialMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
|
||||
break;
|
||||
case MODE_SMMA:
|
||||
SmoothedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
|
||||
SmoothedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
|
||||
break;
|
||||
case MODE_LWMA:
|
||||
LinearWeightedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
|
||||
LinearWeightedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//--- main cycle
|
||||
for(int i=limit; i>=0 && !_StopFlag; i--)
|
||||
{
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user