beast super signal expert advisor.mq4
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «beast super signal expert advisor.mq4» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
Имеет встроенный счётчик спреда и статусную строку на графике, систему виртуальных стопов, обработчик истечения срока сделок, а также механизм обработки OCO-ордеров (One Cancels Other). Поддерживает несколько моделей управления объёмом и рисками, включая мартингейл, фиксированное соотношение, последовательности и другие.
Поиск по коду файла
#property description ""
#property version "1.0"
#property strict
/************************************************************************************************************************/
/************************************************************************************************************************/
#define PROJECT_ID "I1mGWuUCc"
#define POINT_FORMAT_RULES "0.001=0.01,0.00001=0.0001,0.000001=0.0001" // this is deserialized in a special function later
#define ENABLE_SPREAD_METER true
#define ENABLE_STATUS true
#define ENABLE_TEST_INDICATORS true
#define ENABLE_EVENT_TICK 1 // enable "Tick" event
#define ENABLE_EVENT_TRADE 0 // enable "Trade" event
#define ENABLE_EVENT_TIMER 0 // enable "Timer" event
#define VIRTUAL_STOPS_ENABLED 0 // enable virtual stops
#define VIRTUAL_STOPS_TIMEOUT 0 // virtual stops timeout
#define USE_EMERGENCY_STOPS "no" // "yes" to use emergency (hard stops) when virtual stops are in use. "always" to use EMERGENCY_STOPS_ADD as emergency stops when there is no virtual stop.
#define EMERGENCY_STOPS_REL 0 // use 0 to disable hard stops when virtual stops are enabled. Use a value >=0 to automatically set hard stops with virtual. Example: if 2 is used, then hard stops will be 2 times bigger than virtual ones.
#define EMERGENCY_STOPS_ADD 0 // add pips to relative size of emergency stops (hard stops)
#define ON_TRADE_REALTIME 0 //
#define ON_TIMER_PERIOD 60 // Timer event period (in seconds)
string fxdBlocksLookupTable[];
#define TLOBJPROP_TIME1 801
#define OBJPROP_TL_PRICE_BY_SHIFT 802
#define OBJPROP_TL_SHIFT_BY_PRICE 803
#define OBJPROP_FIBOVALUE 804
#define OBJPROP_FIBOPRICEVALUE 805
#define OBJPROP_BARSHIFT1 807
#define OBJPROP_BARSHIFT2 808
#define OBJPROP_BARSHIFT3 809
#define SEL_CURRENT 0
#define SEL_INITIAL 1
input double Lot = 0.1;input int MagicStart = 4444; // Magic Number, kind of...
class c
{
public:
static double Lot;
static int MagicStart;
};
double c::Lot;
int c::MagicStart;
class v
{
public:
};
int FXD_CURRENT_FUNCTION_ID = 0;
double FXD_MILS_INIT_END = 0;
int FXD_TICKS_FROM_START = 0;
int FXD_MORE_SHIFT = 0;
bool FXD_DRAW_SPREAD_INFO = false;
bool FXD_FIRST_TICK_PASSED = false;
bool FXD_BREAK = false;
bool FXD_CONTINUE = false;
bool FXD_CHART_IS_OFFLINE = false;
bool FXD_ONTIMER_TAKEN = false;
bool FXD_ONTIMER_TAKEN_IN_MILLISECONDS = false;
double FXD_ONTIMER_TAKEN_TIME = 0;
bool USE_VIRTUAL_STOPS = VIRTUAL_STOPS_ENABLED;
string FXD_CURRENT_SYMBOL = "";
int FXD_BLOCKS_COUNT = 10;
datetime FXD_TICKSKIP_UNTIL = 0;
struct fxd_onchart
{
int id;
long lparam;
double dparam;
string sparam;
};
fxd_onchart FXD_ONCHART;
/************************************************************************************************************************/
/************************************************************************************************************************/
int OnInit()
{
// код доступен только после оплаты
}
void OnTick()
{
// код доступен только после оплаты
}
void EventTrade()
{
OnTradeQueue(-1);
}
void OnTimer()
{
if (FXD_CHART_IS_OFFLINE && RefreshRates()) {
OnTick();
}
if (ON_TRADE_REALTIME == 1) {
OnTradeListener();
}
static datetime t0 = 0;
datetime t = 0;
bool ok = false;
if (FXD_ONTIMER_TAKEN)
{
if (FXD_ONTIMER_TAKEN_TIME > 0)
{
if (FXD_ONTIMER_TAKEN_IN_MILLISECONDS == true)
{
t = GetTickCount();
}
else
{
t = TimeLocal();
}
if ((t - t0) >= FXD_ONTIMER_TAKEN_TIME)
{
t0 = t;
ok = true;
}
}
if (ok == false) {
return;
}
}
}
void OnChartEvent(
const int id, // Event ID
const long& lparam, // Parameter of type long event
const double& dparam, // Parameter of type double event
const string& sparam // Parameter of type string events
)
{
FXD_ONCHART.id = id;
FXD_ONCHART.lparam = lparam;
FXD_ONCHART.dparam = dparam;
FXD_ONCHART.sparam = sparam;
return;
}
void OnDeinit(const int reason)
{
int reson = UninitializeReason();
if (reson == REASON_CHARTCHANGE || reson == REASON_PARAMETERS || reason == REASON_TEMPLATE) {return;}
EventKillTimer();
if (ENABLE_STATUS) DrawStatus("stopped");
if (ENABLE_SPREAD_METER) DrawSpreadInfo();
int blocks_to_run[] = {0};
for (int i=0; i<ArraySize(blocks_to_run); i++) {
_blocks_[blocks_to_run[i]].run();
}
if (MQLInfoInteger(MQL_TESTER)) {
Print("Backtested in "+DoubleToString((GetTickCount()-FXD_MILS_INIT_END)/1000, 2)+" seconds");
double tc = GetTickCount()-FXD_MILS_INIT_END;
if (tc > 0)
{
Print("Average ticks per second: "+DoubleToString(FXD_TICKS_FROM_START/tc, 0));
}
}
if (MQLInfoInteger(MQL_PROGRAM_TYPE) == PROGRAM_EXPERT)
{
switch(UninitializeReason())
{
case REASON_PROGRAM : Print("Expert Advisor self terminated"); break;
case REASON_REMOVE : Print("Expert Advisor removed from the chart"); break;
case REASON_RECOMPILE : Print("Expert Advisor has been recompiled"); break;
case REASON_CHARTCHANGE : Print("Symbol or chart period has been changed"); break;
case REASON_CHARTCLOSE : Print("Chart has been closed"); break;
case REASON_PARAMETERS : Print("Input parameters have been changed by a user"); break;
case REASON_ACCOUNT : Print("Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings"); break;
case REASON_TEMPLATE : Print("A new template has been applied"); break;
case REASON_INITFAILED : Print("OnInit() handler has returned a nonzero value"); break;
case REASON_CLOSE : Print("Terminal has been closed"); break;
}
}
for (int i=0; i<ArraySize(_blocks_); i++)
{
delete _blocks_[i];
_blocks_[i] = NULL;
}
ArrayResize(_blocks_, 0);
return;
}
/************************************************************************************************************************/
/************************************************************************************************************************/
/**
The base class for all block calls
*/
class BlockCalls
{
public:
bool __disabled; // whether or not the block is disabled
string __block_user_number;
int __block_number;
int __block_waiting;
int __parent_number;
int __inbound_blocks[];
int __outbound_blocks[];
void __addInboundBlock(int id = 0) {
int size = ArraySize(__inbound_blocks);
for (int i = 0; i < size; i++) {
if (__inbound_blocks[i] == id) {
return;
}
}
ArrayResize(__inbound_blocks, size + 1);
__inbound_blocks[size] = id;
}
void BlockCalls() {
__disabled = false;
__block_user_number = "";
__block_number = 0;
__block_waiting = 0;
__parent_number = 0;
}
/**
Announce this block to the list of inbound connections of all the blocks to which this block is connected to
*/
void __announceThisBlock()
{
for (int i = 0; i < ArraySize(__outbound_blocks); i++)
{
int block = __outbound_blocks[i]; // outbound block number
int size = ArraySize(_blocks_[block].__inbound_blocks); // the size of its inbound list
for (int j = 0; j < size; j++) {
if (_blocks_[block].__inbound_blocks[j] == __block_number)
{
return;
}
}
ArrayResize(_blocks_[block].__inbound_blocks, size + 1);
_blocks_[block].__inbound_blocks[size] = __block_number;
}
}
virtual void _execute_() = 0;
/**
In the derived class this method should be used to set dynamic parameters or other stuff before the main execute.
This method is automatically called within the main "run" method below, before the execution of the main class.
*/
virtual void _beforeExecute_() {return;};
bool _beforeExecuteEnabled; // for speed
/**
Same as _beforeExecute_, but to work after the execute method.
*/
virtual void _afterExecute_() {return;};
bool _afterExecuteEnabled; // for speed
/**
This is the method that is used to run the block
*/
virtual void run(int _parent_=0) {
__parent_number = _parent_;
if (__disabled || FXD_BREAK) {return;}
FXD_CURRENT_FUNCTION_ID = __block_number;
if (_beforeExecuteEnabled) {_beforeExecute_();}
_execute_();
if (_afterExecuteEnabled) {_afterExecute_();}
if (__block_waiting && FXD_CURRENT_FUNCTION_ID == __block_number) {fxdWait.Accumulate(FXD_CURRENT_FUNCTION_ID);}
}
};
BlockCalls *_blocks_[];
class MDL_Pass: public BlockCalls
{
virtual void _callback_(int r) {return;}
public: /* The main method */
virtual void _execute_()
{
_callback_(1);
}
};
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6>
class MDL_ChartDeleteObjects: public BlockCalls
{
public: /* Input Parameters */
T1 NameStartsWith;
T2 NameContains;
T3 ObjColor;
T4 SortMode;
T5 MaxObjects;
T6 SkipObjects;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDL_ChartDeleteObjects()
{
NameStartsWith = (string)"";
NameContains = (string)"";
ObjColor = (color)EMPTY_VALUE;
SortMode = (string)"z-a";
MaxObjects = (int)0;
SkipObjects = (int)0;
}
public: /* The main method */
virtual void _execute_()
{
int index = 0;
int total = ObjectsTotal(0,-1,-1);
int length = 0;
bool deleted = false;
int deleted_count = 0;
int skipped_count = 0;
string name = "";
if (SortMode == "a-z")
{
for (index=0; index<total; index++)
{
name = ObjectName(0,index);
if (name != "")
{
if (MaxObjects > 0 && deleted_count >= MaxObjects) {break;}
deleted = false;
if (ObjColor != EMPTY_VALUE && ObjColor != clrBlack && ObjectGetInteger(0, name, OBJPROP_COLOR) != ObjColor) {continue;}
if (NameStartsWith == "" && NameContains == "")
{
if (SkipObjects > 0 && skipped_count < SkipObjects)
{
skipped_count++;
continue;
}
if (ObjectDelete(0,name))
{
deleted_count++;
}
}
else
{
if (NameStartsWith != "")
{
length = StringLen(NameStartsWith);
if (StringSubstr(name,0,length) == NameStartsWith)
{
if (SkipObjects > 0 && skipped_count < SkipObjects)
{
skipped_count++;
continue;
}
if (ObjectDelete(0,name))
{
deleted_count++;
}
}
}
if (deleted == false && NameContains != "")
{
if (StringFind(name,NameContains,0) > -1)
{
if (SkipObjects > 0 && skipped_count < SkipObjects)
{
skipped_count++;
continue;
}
if (ObjectDelete(0,name))
{
deleted_count++;
}
}
}
}
}
}
}
else if (SortMode == "z-a")
{
for (index=total-1; index>=0; index--)
{
name = ObjectName(0,index);
if (name != "")
{
if (MaxObjects > 0 && deleted_count >= MaxObjects) {break;}
deleted = false;
if (ObjColor != EMPTY_VALUE && ObjectGetInteger(0, name, OBJPROP_COLOR) != ObjColor) {continue;}
if (NameStartsWith == "" && NameContains == "")
{
if (SkipObjects > 0 && skipped_count < SkipObjects)
{
skipped_count++;
continue;
}
if (ObjectDelete(0,name))
{
deleted_count++;
}
}
else
{
if (NameStartsWith != "")
{
length = StringLen(NameStartsWith);
if (StringSubstr(name,0,length) == NameStartsWith)
{
if (SkipObjects > 0 && skipped_count < SkipObjects)
{
skipped_count++;
continue;
}
if (ObjectDelete(0,name))
{
deleted_count++;
}
}
}
if (deleted == false && NameContains != "")
{
if (StringFind(name,NameContains,0) > -1)
{
if (SkipObjects > 0 && skipped_count < SkipObjects)
{
skipped_count++;
continue;
}
if (ObjectDelete(0,name))
{
deleted_count++;
}
}
}
}
}
}
}
if (deleted_count > 0)
{
ChartRedraw();
}
_callback_(1);
}
};
template<typename T1,typename T2,typename T3,typename T4,typename T5>
class MDL_NoOpenedOrders: public BlockCalls
{
public: /* Input Parameters */
T1 GroupMode;
T2 Group;
T3 SymbolMode;
T4 Symbol;
T5 BuysOrSells;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDL_NoOpenedOrders()
{
GroupMode = (string)"group";
Group = (string)"";
SymbolMode = (string)"symbol";
Symbol = (string)CurrentSymbol();
BuysOrSells = (string)"both";
}
public: /* The main method */
virtual void _execute_()
{
bool exist = false;
for (int index = TradesTotal()-1; index >= 0; index--)
{
if (TradeSelectByIndex(index, GroupMode, Group, SymbolMode, Symbol, BuysOrSells))
{
exist = true;
break;
}
}
if (exist == false) {_callback_(1);} else {_callback_(0);}
}
};
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7,typename T8,typename T9,typename _T9_,typename T10,typename T11,typename T12,typename T13,typename T14,typename T15,typename T16,typename T17,typename T18,typename T19,typename T20,typename T21,typename T22,typename T23,typename T24,typename T25,typename T26,typename T27,typename T28,typename T29,typename T30,typename T31,typename T32,typename T33,typename T34,typename T35,typename T36,typename _T36_,typename T37,typename _T37_,typename T38,typename _T38_,typename T39,typename T40,typename T41,typename T42,typename T43,typename _T43_,typename T44,typename _T44_,typename T45,typename _T45_,typename T46,typename T47,typename T48,typename T49,typename T50,typename _T50_,typename T51,typename T52,typename T53>
class MDL_BuyNow: public BlockCalls
{
public: /* Input Parameters */
T1 Group;
T2 Symbol;
T3 VolumeMode;
T4 VolumeSize;
T5 VolumeSizeRisk;
T6 VolumeRisk;
T7 VolumePercent;
T8 VolumeBlockPercent;
T9 dVolumeSize; virtual _T9_ _dVolumeSize_(){return(_T9_)0;}
T10 FixedRatioUnitSize;
T11 FixedRatioDelta;
T12 mmMgInitialLots;
T13 mmMgMultiplyOnLoss;
T14 mmMgMultiplyOnProfit;
T15 mmMgAddLotsOnLoss;
T16 mmMgAddLotsOnProfit;
T17 mmMgResetOnLoss;
T18 mmMgResetOnProfit;
T19 mm1326InitialLots;
T20 mm1326Reverse;
T21 mmFiboInitialLots;
T22 mmDalembertInitialLots;
T23 mmDalembertReverse;
T24 mmLabouchereInitialLots;
T25 mmLabouchereList;
T26 mmLabouchereReverse;
T27 mmSeqBaseLots;
T28 mmSeqOnLoss;
T29 mmSeqOnProfit;
T30 mmSeqReverse;
T31 VolumeUpperLimit;
T32 StopLossMode;
T33 StopLossPips;
T34 StopLossPercentPrice;
T35 StopLossPercentTP;
T36 dlStopLoss; virtual _T36_ _dlStopLoss_(){return(_T36_)0;}
T37 dpStopLoss; virtual _T37_ _dpStopLoss_(){return(_T37_)0;}
T38 ddStopLoss; virtual _T38_ _ddStopLoss_(){return(_T38_)0;}
T39 TakeProfitMode;
T40 TakeProfitPips;
T41 TakeProfitPercentPrice;
T42 TakeProfitPercentSL;
T43 dlTakeProfit; virtual _T43_ _dlTakeProfit_(){return(_T43_)0;}
T44 dpTakeProfit; virtual _T44_ _dpTakeProfit_(){return(_T44_)0;}
T45 ddTakeProfit; virtual _T45_ _ddTakeProfit_(){return(_T45_)0;}
T46 ExpMode;
T47 ExpDays;
T48 ExpHours;
T49 ExpMinutes;
T50 dExp; virtual _T50_ _dExp_(){return(_T50_)0;}
T51 Slippage;
T52 MyComment;
T53 ArrowColorBuy;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDL_BuyNow()
{
Group = (string)"";
Symbol = (string)CurrentSymbol();
VolumeMode = (string)"fixed";
VolumeSize = (double)0.1;
VolumeSizeRisk = (double)50.0;
VolumeRisk = (double)2.5;
VolumePercent = (double)100.0;
VolumeBlockPercent = (double)3.0;
FixedRatioUnitSize = (double)0.01;
FixedRatioDelta = (double)20.0;
mmMgInitialLots = (double)0.1;
mmMgMultiplyOnLoss = (double)2.0;
mmMgMultiplyOnProfit = (double)1.0;
mmMgAddLotsOnLoss = (double)0.0;
mmMgAddLotsOnProfit = (double)0.0;
mmMgResetOnLoss = (int)0;
mmMgResetOnProfit = (int)1;
mm1326InitialLots = (double)0.1;
mm1326Reverse = (bool)false;
mmFiboInitialLots = (double)0.1;
mmDalembertInitialLots = (double)0.1;
mmDalembertReverse = (bool)false;
mmLabouchereInitialLots = (double)0.1;
mmLabouchereList = (string)"1,2,3,4,5,6";
mmLabouchereReverse = (bool)false;
mmSeqBaseLots = (double)0.1;
mmSeqOnLoss = (string)"3,2,6";
mmSeqOnProfit = (string)"1";
mmSeqReverse = (bool)false;
VolumeUpperLimit = (double)0.0;
StopLossMode = (string)"fixed";
StopLossPips = (double)50.0;
StopLossPercentPrice = (double)0.55;
StopLossPercentTP = (double)100.0;
TakeProfitMode = (string)"fixed";
TakeProfitPips = (double)50.0;
TakeProfitPercentPrice = (double)0.55;
TakeProfitPercentSL = (double)100.0;
ExpMode = (string)"GTC";
ExpDays = (int)0;
ExpHours = (int)1;
ExpMinutes = (int)0;
Slippage = (ulong)4;
MyComment = (string)"";
ArrowColorBuy = (color)clrBlue;
}
public: /* The main method */
virtual void _execute_()
{
double sll = 0, slp = 0, tpl = 0, tpp = 0;
if (StopLossMode == "fixed") {slp = StopLossPips;}
else if (StopLossMode == "dynamicPips") {slp = _dpStopLoss_();}
else if (StopLossMode == "dynamicDigits") {slp = toPips(_ddStopLoss_(),Symbol);}
else if (StopLossMode == "dynamicLevel") {sll = _dlStopLoss_();}
else if (StopLossMode == "percentPrice") {sll = SymbolAsk(Symbol) - (SymbolAsk(Symbol) * StopLossPercentPrice / 100);}
if (TakeProfitMode == "fixed") {tpp = TakeProfitPips;}
else if (TakeProfitMode == "dynamicPips") {tpp = _dpTakeProfit_();}
else if (TakeProfitMode == "dynamicDigits") {tpp = toPips(_ddTakeProfit_(),Symbol);}
else if (TakeProfitMode == "dynamicLevel") {tpl = _dlTakeProfit_();}
else if (TakeProfitMode == "percentPrice") {tpl = SymbolAsk(Symbol) + (SymbolAsk(Symbol) * TakeProfitPercentPrice / 100);}
if (StopLossMode == "percentTP") {
if (tpp > 0) {slp = tpp*StopLossPercentTP/100;}
if (tpl > 0) {slp = toPips(MathAbs(SymbolAsk(Symbol) - tpl), Symbol)*StopLossPercentTP/100;}
}
if (TakeProfitMode == "percentSL") {
if (slp > 0) {tpp = slp*TakeProfitPercentSL/100;}
if (sll > 0) {tpp = toPips(MathAbs(SymbolAsk(Symbol) - sll), Symbol)*TakeProfitPercentSL/100;}
}
double lots = 0;
double pre_sll = sll;
if (pre_sll == 0) {
pre_sll = SymbolAsk(Symbol);
}
double pre_sl_pips = toPips(SymbolAsk(Symbol)-(pre_sll-toDigits(slp,Symbol)), Symbol);
if (VolumeMode == "fixed") {lots = DynamicLots(Symbol, VolumeMode, VolumeSize);}
else if (VolumeMode == "block-equity") {lots = DynamicLots(Symbol, VolumeMode, VolumeBlockPercent);}
else if (VolumeMode == "block-balance") {lots = DynamicLots(Symbol, VolumeMode, VolumeBlockPercent);}
else if (VolumeMode == "block-freemargin") {lots = DynamicLots(Symbol, VolumeMode, VolumeBlockPercent);}
else if (VolumeMode == "equity") {lots = DynamicLots(Symbol, VolumeMode, VolumePercent);}
else if (VolumeMode == "balance") {lots = DynamicLots(Symbol, VolumeMode, VolumePercent);}
else if (VolumeMode == "freemargin") {lots = DynamicLots(Symbol, VolumeMode, VolumePercent);}
else if (VolumeMode == "equityRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeRisk, pre_sl_pips);}
else if (VolumeMode == "balanceRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeRisk, pre_sl_pips);}
else if (VolumeMode == "freemarginRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeRisk, pre_sl_pips);}
else if (VolumeMode == "fixedRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeSizeRisk, pre_sl_pips);}
else if (VolumeMode == "fixedRatio") {lots = DynamicLots(Symbol, VolumeMode, FixedRatioUnitSize, FixedRatioDelta);}
else if (VolumeMode == "dynamic") {lots = _dVolumeSize_();}
else if (VolumeMode == "1326") {lots = Bet1326((int)Group, Symbol, mm1326InitialLots, mm1326Reverse);}
else if (VolumeMode == "fibonacci") {lots = BetFibonacci((int)Group, Symbol, mmFiboInitialLots);}
else if (VolumeMode == "dalembert") {lots = BetDalembert((int)Group, Symbol, mmDalembertInitialLots, mmDalembertReverse);}
else if (VolumeMode == "labouchere") {lots = BetLabouchere((int)Group, Symbol, mmLabouchereInitialLots, mmLabouchereList, mmLabouchereReverse);}
else if (VolumeMode == "martingale") {lots = BetMartingale((int)Group, Symbol, mmMgInitialLots, mmMgMultiplyOnLoss, mmMgMultiplyOnProfit, mmMgAddLotsOnLoss, mmMgAddLotsOnProfit, mmMgResetOnLoss, mmMgResetOnProfit);}
else if (VolumeMode == "sequence") {lots = BetSequence((int)Group, Symbol, mmSeqBaseLots, mmSeqOnLoss, mmSeqOnProfit, mmSeqReverse);}
lots = AlignLots(Symbol, lots, 0, VolumeUpperLimit);
datetime exp = ExpirationTime(ExpMode,ExpDays,ExpHours,ExpMinutes,_dExp_());
long ticket = BuyNow(Symbol, lots, sll, tpl, slp, tpp, Slippage, (MagicStart+(int)Group), MyComment, ArrowColorBuy, exp);
if (ticket > 0) {_callback_(1);} else {_callback_(0);}
}
};
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7,typename T8,typename T9,typename _T9_,typename T10,typename T11,typename T12,typename T13,typename T14,typename T15,typename T16,typename T17,typename T18,typename T19,typename T20,typename T21,typename T22,typename T23,typename T24,typename T25,typename T26,typename T27,typename T28,typename T29,typename T30,typename T31,typename T32,typename T33,typename T34,typename T35,typename T36,typename _T36_,typename T37,typename _T37_,typename T38,typename _T38_,typename T39,typename T40,typename T41,typename T42,typename T43,typename _T43_,typename T44,typename _T44_,typename T45,typename _T45_,typename T46,typename T47,typename T48,typename T49,typename T50,typename _T50_,typename T51,typename T52,typename T53>
class MDL_SellNow: public BlockCalls
{
public: /* Input Parameters */
T1 Group;
T2 Symbol;
T3 VolumeMode;
T4 VolumeSize;
T5 VolumeSizeRisk;
T6 VolumeRisk;
T7 VolumePercent;
T8 VolumeBlockPercent;
T9 dVolumeSize; virtual _T9_ _dVolumeSize_(){return(_T9_)0;}
T10 FixedRatioUnitSize;
T11 FixedRatioDelta;
T12 mmMgInitialLots;
T13 mmMgMultiplyOnLoss;
T14 mmMgMultiplyOnProfit;
T15 mmMgAddLotsOnLoss;
T16 mmMgAddLotsOnProfit;
T17 mmMgResetOnLoss;
T18 mmMgResetOnProfit;
T19 mm1326InitialLots;
T20 mm1326Reverse;
T21 mmFiboInitialLots;
T22 mmDalembertInitialLots;
T23 mmDalembertReverse;
T24 mmLabouchereInitialLots;
T25 mmLabouchereList;
T26 mmLabouchereReverse;
T27 mmSeqBaseLots;
T28 mmSeqOnLoss;
T29 mmSeqOnProfit;
T30 mmSeqReverse;
T31 VolumeUpperLimit;
T32 StopLossMode;
T33 StopLossPips;
T34 StopLossPercentPrice;
T35 StopLossPercentTP;
T36 dlStopLoss; virtual _T36_ _dlStopLoss_(){return(_T36_)0;}
T37 dpStopLoss; virtual _T37_ _dpStopLoss_(){return(_T37_)0;}
T38 ddStopLoss; virtual _T38_ _ddStopLoss_(){return(_T38_)0;}
T39 TakeProfitMode;
T40 TakeProfitPips;
T41 TakeProfitPercentPrice;
T42 TakeProfitPercentSL;
T43 dlTakeProfit; virtual _T43_ _dlTakeProfit_(){return(_T43_)0;}
T44 dpTakeProfit; virtual _T44_ _dpTakeProfit_(){return(_T44_)0;}
T45 ddTakeProfit; virtual _T45_ _ddTakeProfit_(){return(_T45_)0;}
T46 ExpMode;
T47 ExpDays;
T48 ExpHours;
T49 ExpMinutes;
T50 dExp; virtual _T50_ _dExp_(){return(_T50_)0;}
T51 Slippage;
T52 MyComment;
T53 ArrowColorSell;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDL_SellNow()
{
Group = (string)"";
Symbol = (string)CurrentSymbol();
VolumeMode = (string)"fixed";
VolumeSize = (double)0.1;
VolumeSizeRisk = (double)50.0;
VolumeRisk = (double)2.5;
VolumePercent = (double)100.0;
VolumeBlockPercent = (double)3.0;
FixedRatioUnitSize = (double)0.01;
FixedRatioDelta = (double)20.0;
mmMgInitialLots = (double)0.1;
mmMgMultiplyOnLoss = (double)2.0;
mmMgMultiplyOnProfit = (double)1.0;
mmMgAddLotsOnLoss = (double)0.0;
mmMgAddLotsOnProfit = (double)0.0;
mmMgResetOnLoss = (int)0;
mmMgResetOnProfit = (int)1;
mm1326InitialLots = (double)0.1;
mm1326Reverse = (bool)false;
mmFiboInitialLots = (double)0.1;
mmDalembertInitialLots = (double)0.1;
mmDalembertReverse = (bool)false;
mmLabouchereInitialLots = (double)0.1;
mmLabouchereList = (string)"1,2,3,4,5,6";
mmLabouchereReverse = (bool)false;
mmSeqBaseLots = (double)0.1;
mmSeqOnLoss = (string)"3,2,6";
mmSeqOnProfit = (string)"1";
mmSeqReverse = (bool)false;
VolumeUpperLimit = (double)0.0;
StopLossMode = (string)"fixed";
StopLossPips = (double)50.0;
StopLossPercentPrice = (double)0.55;
StopLossPercentTP = (double)100.0;
TakeProfitMode = (string)"fixed";
TakeProfitPips = (double)50.0;
TakeProfitPercentPrice = (double)0.55;
TakeProfitPercentSL = (double)100.0;
ExpMode = (string)"GTC";
ExpDays = (int)0;
ExpHours = (int)1;
ExpMinutes = (int)0;
Slippage = (ulong)4;
MyComment = (string)"";
ArrowColorSell = (color)clrRed;
}
public: /* The main method */
virtual void _execute_()
{
double sll = 0, slp = 0, tpl = 0, tpp = 0;
if (StopLossMode == "fixed") {slp = StopLossPips;}
else if (StopLossMode == "dynamicPips") {slp = _dpStopLoss_();}
else if (StopLossMode == "dynamicDigits") {slp = toPips(_ddStopLoss_(),Symbol);}
else if (StopLossMode == "dynamicLevel") {sll = _dlStopLoss_();}
else if (StopLossMode == "percentPrice") {sll = SymbolBid(Symbol) + (SymbolBid(Symbol) * StopLossPercentPrice / 100);}
if (TakeProfitMode == "fixed") {tpp = TakeProfitPips;}
else if (TakeProfitMode == "dynamicPips") {tpp = _dpTakeProfit_();}
else if (TakeProfitMode == "dynamicDigits") {tpp = toPips(_ddTakeProfit_(),Symbol);}
else if (TakeProfitMode == "dynamicLevel") {tpl = _dlTakeProfit_();}
else if (TakeProfitMode == "percentPrice") {tpl = SymbolBid(Symbol) - (SymbolBid(Symbol) * TakeProfitPercentPrice / 100);}
if (StopLossMode == "percentTP") {
if (tpp > 0) {slp = tpp*StopLossPercentTP/100;}
if (tpl > 0) {slp = toPips(MathAbs(SymbolBid(Symbol) - tpl), Symbol)*StopLossPercentTP/100;}
}
if (TakeProfitMode == "percentSL") {
if (slp > 0) {tpp = slp*TakeProfitPercentSL/100;}
if (sll > 0) {tpp = toPips(MathAbs(SymbolBid(Symbol) - sll), Symbol)*TakeProfitPercentSL/100;}
}
double lots = 0;
double pre_sll = sll;
if (pre_sll == 0) {
pre_sll = SymbolBid(Symbol);
}
double pre_sl_pips = toPips((pre_sll+toDigits(slp,Symbol))-SymbolBid(Symbol), Symbol);
if (VolumeMode == "fixed") {lots = DynamicLots(Symbol, VolumeMode, VolumeSize);}
else if (VolumeMode == "block-equity") {lots = DynamicLots(Symbol, VolumeMode, VolumeBlockPercent);}
else if (VolumeMode == "block-balance") {lots = DynamicLots(Symbol, VolumeMode, VolumeBlockPercent);}
else if (VolumeMode == "block-freemargin") {lots = DynamicLots(Symbol, VolumeMode, VolumeBlockPercent);}
else if (VolumeMode == "equity") {lots = DynamicLots(Symbol, VolumeMode, VolumePercent);}
else if (VolumeMode == "balance") {lots = DynamicLots(Symbol, VolumeMode, VolumePercent);}
else if (VolumeMode == "freemargin") {lots = DynamicLots(Symbol, VolumeMode, VolumePercent);}
else if (VolumeMode == "equityRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeRisk, pre_sl_pips);}
else if (VolumeMode == "balanceRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeRisk, pre_sl_pips);}
else if (VolumeMode == "freemarginRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeRisk, pre_sl_pips);}
else if (VolumeMode == "fixedRisk") {lots = DynamicLots(Symbol, VolumeMode, VolumeSizeRisk, pre_sl_pips);}
else if (VolumeMode == "fixedRatio") {lots = DynamicLots(Symbol, VolumeMode, FixedRatioUnitSize, FixedRatioDelta);}
else if (VolumeMode == "dynamic") {lots = _dVolumeSize_();}
else if (VolumeMode == "1326") {lots = Bet1326((int)Group, Symbol, mm1326InitialLots, mm1326Reverse);}
else if (VolumeMode == "fibonacci") {lots = BetFibonacci((int)Group, Symbol, mmFiboInitialLots);}
else if (VolumeMode == "dalembert") {lots = BetDalembert((int)Group, Symbol, mmDalembertInitialLots, mmDalembertReverse);}
else if (VolumeMode == "labouchere") {lots = BetLabouchere((int)Group, Symbol, mmLabouchereInitialLots, mmLabouchereList, mmLabouchereReverse);}
else if (VolumeMode == "martingale") {lots = BetMartingale((int)Group, Symbol, mmMgInitialLots, mmMgMultiplyOnLoss, mmMgMultiplyOnProfit, mmMgAddLotsOnLoss, mmMgAddLotsOnProfit, mmMgResetOnLoss, mmMgResetOnProfit);}
else if (VolumeMode == "sequence") {lots = BetSequence((int)Group, Symbol, mmSeqBaseLots, mmSeqOnLoss, mmSeqOnProfit, mmSeqReverse);}
lots = AlignLots(Symbol, lots, 0, VolumeUpperLimit);
datetime exp = ExpirationTime(ExpMode,ExpDays,ExpHours,ExpMinutes,_dExp_());
long ticket = SellNow(Symbol, lots, sll, tpl, slp, tpp, Slippage, (MagicStart+(int)Group), MyComment, ArrowColorSell, exp);
if (ticket > 0) {_callback_(1);} else {_callback_(0);}
}
};
template<typename T1,typename _T1_>
class MDL_IndicatorAppear: public BlockCalls
{
public: /* Input Parameters */
T1 Indicator; virtual _T1_ _Indicator_(){return(_T1_)0;}
/* Static Parameters */
double old_buff;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDL_IndicatorAppear()
{
}
public: /* The main method */
virtual void _execute_()
{
bool next = false;
_T1_ ivalue = _Indicator_();
if (FXD_TICKS_FROM_START > 1)
{
if (old_buff == 0 || old_buff >= EMPTY_VALUE)
{
if (ivalue != 0 && ivalue < EMPTY_VALUE)
{
next = true;
}
}
}
old_buff = ivalue;
if (next == true) {_callback_(1);} else {_callback_(0);}
}
};
template<typename T1,typename T2,typename T3,typename T4,typename T5,typename T6,typename T7,typename T8>
class MDL_CloseOpened: public BlockCalls
{
public: /* Input Parameters */
T1 GroupMode;
T2 Group;
T3 SymbolMode;
T4 Symbol;
T5 BuysOrSells;
T6 OrderMinutes;
T7 Slippage;
T8 ArrowColor;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDL_CloseOpened()
{
GroupMode = (string)"group";
Group = (string)"";
SymbolMode = (string)"symbol";
Symbol = (string)CurrentSymbol();
BuysOrSells = (string)"both";
OrderMinutes = (int)0;
Slippage = (ulong)4;
ArrowColor = (color)clrDeepPink;
}
public: /* The main method */
virtual void _execute_()
{
int closed_count = 0;
bool finished = false;
while (finished == false)
{
int count = 0;
for (int index = TradesTotal()-1; index >= 0; index--)
{
if (TradeSelectByIndex(index, GroupMode, Group, SymbolMode, Symbol, BuysOrSells))
{
datetime time_diff = TimeCurrent() - OrderOpenTime();
if (time_diff < 0) {time_diff = 0;} // this actually happens sometimes
if (time_diff >= 60 * OrderMinutes)
{
if (CloseTrade(OrderTicket(), Slippage, ArrowColor))
{
closed_count++;
}
count++;
}
}
}
if (count == 0) {finished = true;}
}
_callback_(1);
}
};
class MDLIC_value_value
{
public: /* Input Parameters */
double Value;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDLIC_value_value()
{
Value = (double)1.0;
}
public: /* The main method */
double _execute_()
{
return Value;
}
};
class MDLIC_value_time
{
public: /* Input Parameters */
int ModeTime;
int TimeSource;
string TimeStamp;
int TimeCandleID;
string TimeMarket;
ENUM_TIMEFRAMES TimeCandleTimeframe;
int TimeComponentYear;
int TimeComponentMonth;
double TimeComponentDay;
double TimeComponentHour;
double TimeComponentMinute;
int TimeComponentSecond;
int ModeTimeShift;
int TimeShiftYears;
int TimeShiftMonths;
int TimeShiftWeeks;
double TimeShiftDays;
double TimeShiftHours;
double TimeShiftMinutes;
int TimeShiftSeconds;
bool TimeSkipWeekdays;
/* Static Parameters */
datetime retval;
datetime retval0;
int ModeTime0;
int smodeshift;
int years0;
int months0;
datetime Time[];
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDLIC_value_time()
{
ModeTime = (int)0;
TimeSource = (int)0;
TimeStamp = (string)"00:00";
TimeCandleID = (int)1;
TimeMarket = (string)"";
TimeCandleTimeframe = (ENUM_TIMEFRAMES)0;
TimeComponentYear = (int)0;
TimeComponentMonth = (int)0;
TimeComponentDay = (double)0.0;
TimeComponentHour = (double)12.0;
TimeComponentMinute = (double)0.0;
TimeComponentSecond = (int)0;
ModeTimeShift = (int)0;
TimeShiftYears = (int)0;
TimeShiftMonths = (int)0;
TimeShiftWeeks = (int)0;
TimeShiftDays = (double)0.0;
TimeShiftHours = (double)0.0;
TimeShiftMinutes = (double)0.0;
TimeShiftSeconds = (int)0;
TimeSkipWeekdays = (bool)false;
/* Static Parameters (initial value) */
retval = 0;
retval0 = 0;
ModeTime0 = 0;
smodeshift = 0;
years0 = 0;
months0 = 0;
}
public: /* The main method */
datetime _execute_()
{
if (TimeMarket == "") TimeMarket = Symbol();
if (ModeTime == 0)
{
if (TimeSource == 0) {retval = TimeCurrent();}
else if (TimeSource == 1) {retval = TimeLocal();}
else if (TimeSource == 2) {retval = TimeGMT();}
}
else if (ModeTime == 1)
{
retval = StringToTime(TimeStamp);
retval0 = retval;
}
else if (ModeTime==2)
{
retval = TimeFromComponents(TimeSource, TimeComponentYear, TimeComponentMonth, TimeComponentDay, TimeComponentHour, TimeComponentMinute, TimeComponentSecond);
}
else if (ModeTime == 3)
{
ArraySetAsSeries(Time,true);
CopyTime(TimeMarket,TimeCandleTimeframe,TimeCandleID,1,Time);
retval = Time[0];
}
if (ModeTimeShift > 0)
{
int sh = 1;
if (ModeTimeShift == 1) {sh = -1;}
if (
ModeTimeShift != smodeshift
|| TimeShiftYears != years0
|| TimeShiftMonths != months0
)
{
years0 = TimeShiftYears;
months0 = TimeShiftMonths;
if (TimeShiftYears > 0 || TimeShiftMonths > 0)
{
int year = 0, month = 0, week = 0, day = 0, hour = 0, minute = 0, second = 0;
if (ModeTime == 3)
{
year = TimeComponentYear;
month = TimeComponentYear;
day = (int)MathFloor(TimeComponentDay);
hour = (int)(MathFloor(TimeComponentHour) + (24 * (TimeComponentDay - MathFloor(TimeComponentDay))));
minute = (int)(MathFloor(TimeComponentMinute) + (60 * (TimeComponentHour - MathFloor(TimeComponentHour))));
second = (int)(TimeComponentSecond + (60 * (TimeComponentMinute - MathFloor(TimeComponentMinute))));
}
else {
year = TimeYear(retval);
month = TimeMonth(retval);
day = TimeDay(retval);
hour = TimeHour(retval);
minute = TimeMinute(retval);
second = TimeSeconds(retval);
}
year = year + TimeShiftYears * sh;
month = month + TimeShiftMonths * sh;
if (month < 0) {month = 12 - month;}
else if (month > 12) {month = month - 12;}
retval = StringToTime(IntegerToString(year)+"."+IntegerToString(month)+"."+IntegerToString(day)+" "+IntegerToString(hour)+":"+IntegerToString(minute)+":"+IntegerToString(second));
}
}
retval = retval + (sh * ((604800 * TimeShiftWeeks) + SecondsFromComponents(TimeShiftDays, TimeShiftHours, TimeShiftMinutes, TimeShiftSeconds)));
if (TimeSkipWeekdays == true)
{
int weekday = TimeDayOfWeek(retval);
if (sh > 0) { // forward
if (weekday == 0) {retval = retval + 86400;}
else if (weekday == 6) {retval = retval + 172800;}
}
else if (sh < 0) { // back
if (weekday == 0) {retval = retval - 172800;}
else if (weekday == 6) {retval = retval - 86400;}
}
}
}
smodeshift = ModeTimeShift;
ModeTime0 = ModeTime;
return (datetime)retval;
}
};
class MDLIC_myindicators_myindicators_1
{
public: /* Input Parameters */
string Symbol;
ENUM_TIMEFRAMES Period;
string ModeOutput;
string TimeStamp;
int VisibleID;
int VisibleShift;
int VisibleLimit;
int RangeCandleStart;
int RangeCandleEnd;
string RangeTimeSource;
string RangeTimeStart;
string RangeTimeEnd;
double RangeDayOffset;
string RangeValue;
int Shift;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDLIC_myindicators_myindicators_1()
{
Symbol = (string)CurrentSymbol();
Period = (ENUM_TIMEFRAMES)CurrentTimeframe();
ModeOutput = (string)"id";
TimeStamp = (string)"00:00";
VisibleID = (int)0;
VisibleShift = (int)0;
VisibleLimit = (int)100;
RangeCandleStart = (int)0;
RangeCandleEnd = (int)10;
RangeTimeSource = (string)"server";
RangeTimeStart = (string)"01:00";
RangeTimeEnd = (string)"08:00";
RangeDayOffset = (double)0.0;
RangeValue = (string)"max";
Shift = (int)0;
}
public: /* The main method */
double _execute_()
{
string symbol = Symbol;
ENUM_TIMEFRAMES timeframe = Period;
int buffer = 0;
int shift = Shift + FXD_MORE_SHIFT;
double retval = EMPTY_VALUE;
int i;
double ival;
if (ModeOutput == "id")
{
retval = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift);
}
else if (ModeOutput == "time")
{
datetime time;
if (0 && StringFind(TimeStamp, ":") == -1)
{
time = (datetime)StringToInteger(TimeStamp); // hangs in MQL4!!!
}
else
{
time = StringToTime(TimeStamp);
}
shift = iCandleID(symbol, timeframe, time);
retval = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift);
}
else if (ModeOutput == "visible" || ModeOutput == "id_by_visible")
{
if (VisibleLimit == 0) {VisibleLimit = iBars(symbol, timeframe);}
int vid = 0;
for (i = shift; i <= VisibleLimit; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (vid >= VisibleID) {
if (ModeOutput == "visible") {retval = ival;}
else {retval = i;}
break;
}
vid++;
}
}
else if (ModeOutput == "range")
{
int cstart = RangeCandleStart;
int cend = RangeCandleEnd;
if (RangeCandleStart > RangeCandleEnd) {
int ctmp = RangeCandleEnd;
RangeCandleEnd = RangeCandleStart;
RangeCandleStart = ctmp;
}
if (RangeValue == "max")
{
retval = -EMPTY_VALUE;
for (i = RangeCandleStart; i <= RangeCandleEnd; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival > retval) {retval = ival;}
}
if (retval == -EMPTY_VALUE) {retval = EMPTY_VALUE;}
}
else if (RangeValue == "min")
{
retval = EMPTY_VALUE;
for (i = RangeCandleStart; i <= RangeCandleEnd; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival < retval) {retval = ival;}
}
}
}
else if (ModeOutput == "range_time")
{
datetime offset = 0;
if (RangeTimeSource == "gmt") {offset = (int)(TimeCurrent() - TimeLocal() + TimeGMTOffset());}
else if (RangeTimeSource == "server") {offset = (int)(TimeCurrent() - TimeLocal());}
datetime time1 = StringToTime(RangeTimeStart)-(datetime)(86400*RangeDayOffset) + offset;
datetime time2 = StringToTime(RangeTimeEnd)-(datetime)(86400*RangeDayOffset) + offset;
int x1 = iBarShift(symbol, timeframe, time1, false);
int x2 = iBarShift(symbol, timeframe, time2, false);
if (x1<x2) {x1=iBarShift(symbol,timeframe,(time1-86400),false);}
if (RangeValue == "max")
{
retval = -EMPTY_VALUE;
for (i=x2; i<=x1; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival > retval) {retval = ival;}
}
if (retval == -EMPTY_VALUE) {retval = EMPTY_VALUE;}
}
else if (RangeValue == "min")
{
retval = EMPTY_VALUE;
for (i=x2; i<=x1; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival < retval) {retval = ival;}
}
}
}
return (retval);
}
};
class MDLIC_myindicators_myindicators_2
{
public: /* Input Parameters */
string Symbol;
ENUM_TIMEFRAMES Period;
string ModeOutput;
string TimeStamp;
int VisibleID;
int VisibleShift;
int VisibleLimit;
int RangeCandleStart;
int RangeCandleEnd;
string RangeTimeSource;
string RangeTimeStart;
string RangeTimeEnd;
double RangeDayOffset;
string RangeValue;
int Shift;
virtual void _callback_(int r) {return;}
public: /* Constructor */
MDLIC_myindicators_myindicators_2()
{
Symbol = (string)CurrentSymbol();
Period = (ENUM_TIMEFRAMES)CurrentTimeframe();
ModeOutput = (string)"id";
TimeStamp = (string)"00:00";
VisibleID = (int)0;
VisibleShift = (int)0;
VisibleLimit = (int)100;
RangeCandleStart = (int)0;
RangeCandleEnd = (int)10;
RangeTimeSource = (string)"server";
RangeTimeStart = (string)"01:00";
RangeTimeEnd = (string)"08:00";
RangeDayOffset = (double)0.0;
RangeValue = (string)"max";
Shift = (int)0;
}
public: /* The main method */
double _execute_()
{
string symbol = Symbol;
ENUM_TIMEFRAMES timeframe = Period;
int buffer = 1;
int shift = Shift + FXD_MORE_SHIFT;
double retval = EMPTY_VALUE;
int i;
double ival;
if (ModeOutput == "id")
{
retval = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift);
}
else if (ModeOutput == "time")
{
datetime time;
if (0 && StringFind(TimeStamp, ":") == -1)
{
time = (datetime)StringToInteger(TimeStamp); // hangs in MQL4!!!
}
else
{
time = StringToTime(TimeStamp);
}
shift = iCandleID(symbol, timeframe, time);
retval = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift);
}
else if (ModeOutput == "visible" || ModeOutput == "id_by_visible")
{
if (VisibleLimit == 0) {VisibleLimit = iBars(symbol, timeframe);}
int vid = 0;
for (i = shift; i <= VisibleLimit; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (vid >= VisibleID) {
if (ModeOutput == "visible") {retval = ival;}
else {retval = i;}
break;
}
vid++;
}
}
else if (ModeOutput == "range")
{
int cstart = RangeCandleStart;
int cend = RangeCandleEnd;
if (RangeCandleStart > RangeCandleEnd) {
int ctmp = RangeCandleEnd;
RangeCandleEnd = RangeCandleStart;
RangeCandleStart = ctmp;
}
if (RangeValue == "max")
{
retval = -EMPTY_VALUE;
for (i = RangeCandleStart; i <= RangeCandleEnd; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival > retval) {retval = ival;}
}
if (retval == -EMPTY_VALUE) {retval = EMPTY_VALUE;}
}
else if (RangeValue == "min")
{
retval = EMPTY_VALUE;
for (i = RangeCandleStart; i <= RangeCandleEnd; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival < retval) {retval = ival;}
}
}
}
else if (ModeOutput == "range_time")
{
datetime offset = 0;
if (RangeTimeSource == "gmt") {offset = (int)(TimeCurrent() - TimeLocal() + TimeGMTOffset());}
else if (RangeTimeSource == "server") {offset = (int)(TimeCurrent() - TimeLocal());}
datetime time1 = StringToTime(RangeTimeStart)-(datetime)(86400*RangeDayOffset) + offset;
datetime time2 = StringToTime(RangeTimeEnd)-(datetime)(86400*RangeDayOffset) + offset;
int x1 = iBarShift(symbol, timeframe, time1, false);
int x2 = iBarShift(symbol, timeframe, time2, false);
if (x1<x2) {x1=iBarShift(symbol,timeframe,(time1-86400),false);}
if (RangeValue == "max")
{
retval = -EMPTY_VALUE;
for (i=x2; i<=x1; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival > retval) {retval = ival;}
}
if (retval == -EMPTY_VALUE) {retval = EMPTY_VALUE;}
}
else if (RangeValue == "min")
{
retval = EMPTY_VALUE;
for (i=x2; i<=x1; i++)
{
ival = iCustom(symbol, timeframe, "Beast Super Signal" , buffer, shift + i);
if (ival == EMPTY_VALUE || ival == 0) {continue;}
if (ival < retval) {retval = ival;}
}
}
}
return (retval);
}
};
class Block0: public MDL_Pass
{
public: /* Constructor */
Block0() {
__block_number = 0;
__block_user_number = "2";
int ___outbound_blocks[1] = {1};
ArrayCopy(__outbound_blocks, ___outbound_blocks);
}
public: /* Callback & Run */
virtual void _callback_(int value) {
if (value == 1) {
_blocks_[1].run(0);
}
}
};
class Block1: public MDL_ChartDeleteObjects<string,string,color,string,int,int>
{
public: /* Constructor */
Block1() {
__block_number = 1;
__block_user_number = "3";
_beforeExecuteEnabled = true;
}
public: /* Callback & Run */
virtual void _callback_(int value) {
}
virtual void _beforeExecute_()
{
ObjColor = (color)EMPTY_VALUE;
}
};
class Block2: public MDL_NoOpenedOrders<string,string,string,string,string>
{
public: /* Constructor */
Block2() {
__block_number = 2;
__block_user_number = "4";
_beforeExecuteEnabled = true;
int ___outbound_blocks[1] = {6};
ArrayCopy(__outbound_blocks, ___outbound_blocks);
BuysOrSells = "buys";
}
public: /* Callback & Run */
virtual void _callback_(int value) {
if (value == 1) {
_blocks_[6].run(2);
}
}
virtual void _beforeExecute_()
{
Symbol = (string)CurrentSymbol();
}
};
class Block3: public MDL_NoOpenedOrders<string,string,string,string,string>
{
public: /* Constructor */
Block3() {
__block_number = 3;
__block_user_number = "5";
_beforeExecuteEnabled = true;
int ___outbound_blocks[1] = {7};
ArrayCopy(__outbound_blocks, ___outbound_blocks);
BuysOrSells = "sells";
}
public: /* Callback & Run */
virtual void _callback_(int value) {
if (value == 1) {
_blocks_[7].run(3);
}
}
virtual void _beforeExecute_()
{
Symbol = (string)CurrentSymbol();
}
};
class Block4: public MDL_BuyNow<string,string,string,double,double,double,double,double,MDLIC_value_value,double,double,double,double,double,double,double,double,int,int,double,bool,double,double,bool,double,string,bool,double,string,string,bool,double,string,double,double,double,MDLIC_value_value,double,MDLIC_value_value,double,MDLIC_value_value,double,string,double,double,double,MDLIC_value_value,double,MDLIC_value_value,double,MDLIC_value_value,double,string,int,int,int,MDLIC_value_time,datetime,ulong,string,color>
{
public: /* Constructor */
Block4() {
__block_number = 4;
__block_user_number = "6";
_beforeExecuteEnabled = true;
dVolumeSize.Value = 0.1;
dpStopLoss.Value = 100.0;
ddStopLoss.Value = 0.01;
dpTakeProfit.Value = 100.0;
ddTakeProfit.Value = 0.01;
dExp.ModeTimeShift = 2;
dExp.TimeShiftDays = 1.0;
dExp.TimeSkipWeekdays = true;
StopLossMode = "none";
TakeProfitMode = "none";
}
public: /* Custom methods */
virtual double _dVolumeSize_() {return dVolumeSize._execute_();}
virtual double _dlStopLoss_() {return dlStopLoss._execute_();}
virtual double _dpStopLoss_() {return dpStopLoss._execute_();}
virtual double _ddStopLoss_() {return ddStopLoss._execute_();}
virtual double _dlTakeProfit_() {return dlTakeProfit._execute_();}
virtual double _dpTakeProfit_() {return dpTakeProfit._execute_();}
virtual double _ddTakeProfit_() {return ddTakeProfit._execute_();}
virtual datetime _dExp_() {return dExp._execute_();}
public: /* Callback & Run */
virtual void _callback_(int value) {
}
virtual void _beforeExecute_()
{
Symbol = (string)CurrentSymbol();
VolumeSize = (double)c::Lot;
ArrowColorBuy = (color)clrBlue;
}
};
class Block5: public MDL_SellNow<string,string,string,double,double,double,double,double,MDLIC_value_value,double,double,double,double,double,double,double,double,int,int,double,bool,double,double,bool,double,string,bool,double,string,string,bool,double,string,double,double,double,MDLIC_value_value,double,MDLIC_value_value,double,MDLIC_value_value,double,string,double,double,double,MDLIC_value_value,double,MDLIC_value_value,double,MDLIC_value_value,double,string,int,int,int,MDLIC_value_time,datetime,ulong,string,color>
{
public: /* Constructor */
Block5() {
__block_number = 5;
__block_user_number = "7";
_beforeExecuteEnabled = true;
dVolumeSize.Value = 0.1;
dpStopLoss.Value = 100.0;
ddStopLoss.Value = 0.01;
dpTakeProfit.Value = 100.0;
ddTakeProfit.Value = 0.01;
dExp.ModeTimeShift = 2;
dExp.TimeShiftDays = 1.0;
dExp.TimeSkipWeekdays = true;
StopLossMode = "none";
TakeProfitMode = "none";
}
public: /* Custom methods */
virtual double _dVolumeSize_() {return dVolumeSize._execute_();}
virtual double _dlStopLoss_() {return dlStopLoss._execute_();}
virtual double _dpStopLoss_() {return dpStopLoss._execute_();}
virtual double _ddStopLoss_() {return ddStopLoss._execute_();}
virtual double _dlTakeProfit_() {return dlTakeProfit._execute_();}
virtual double _dpTakeProfit_() {return dpTakeProfit._execute_();}
virtual double _ddTakeProfit_() {return ddTakeProfit._execute_();}
virtual datetime _dExp_() {return dExp._execute_();}
public: /* Callback & Run */
virtual void _callback_(int value) {
}
virtual void _beforeExecute_()
{
Symbol = (string)CurrentSymbol();
VolumeSize = (double)c::Lot;
ArrowColorSell = (color)clrRed;
}
};
class Block6: public MDL_IndicatorAppear<MDLIC_myindicators_myindicators_1,double>
{
public: /* Constructor */
Block6() {
__block_number = 6;
__block_user_number = "10";
_beforeExecuteEnabled = true;
int ___outbound_blocks[2] = {4,8};
ArrayCopy(__outbound_blocks, ___outbound_blocks);
Indicator.Shift = 1;
}
public: /* Custom methods */
virtual double _Indicator_() {
Indicator.Symbol = CurrentSymbol();
Indicator.Period = CurrentTimeframe();
return Indicator._execute_();
}
public: /* Callback & Run */
virtual void _callback_(int value) {
if (value == 1) {
_blocks_[4].run(6);
_blocks_[8].run(6);
}
}
virtual void _beforeExecute_()
{
/* Inputs, modified into the code must be set here every time */
Indicator.RangeCandleStart = 0;
Indicator.RangeCandleEnd = 10;
}
};
class Block7: public MDL_IndicatorAppear<MDLIC_myindicators_myindicators_2,double>
{
public: /* Constructor */
Block7() {
__block_number = 7;
__block_user_number = "11";
_beforeExecuteEnabled = true;
int ___outbound_blocks[2] = {5,9};
ArrayCopy(__outbound_blocks, ___outbound_blocks);
Indicator.Shift = 1;
}
public: /* Custom methods */
virtual double _Indicator_() {
Indicator.Symbol = CurrentSymbol();
Indicator.Period = CurrentTimeframe();
return Indicator._execute_();
}
public: /* Callback & Run */
virtual void _callback_(int value) {
if (value == 1) {
_blocks_[5].run(7);
_blocks_[9].run(7);
}
}
virtual void _beforeExecute_()
{
/* Inputs, modified into the code must be set here every time */
Indicator.RangeCandleStart = 0;
Indicator.RangeCandleEnd = 10;
}
};
class Block8: public MDL_CloseOpened<string,string,string,string,string,int,ulong,color>
{
public: /* Constructor */
Block8() {
__block_number = 8;
__block_user_number = "12";
_beforeExecuteEnabled = true;
BuysOrSells = "sells";
}
public: /* Callback & Run */
virtual void _callback_(int value) {
}
virtual void _beforeExecute_()
{
Symbol = (string)CurrentSymbol();
ArrowColor = (color)clrDeepPink;
}
};
class Block9: public MDL_CloseOpened<string,string,string,string,string,int,ulong,color>
{
public: /* Constructor */
Block9() {
__block_number = 9;
__block_user_number = "13";
_beforeExecuteEnabled = true;
BuysOrSells = "buys";
}
public: /* Callback & Run */
virtual void _callback_(int value) {
}
virtual void _beforeExecute_()
{
Symbol = (string)CurrentSymbol();
ArrowColor = (color)clrDeepPink;
}
};
/************************************************************************************************************************/
/************************************************************************************************************************/
double AccountBalanceAtStart()
{
static double memory = 0;
if (memory == 0) memory = NormalizeDouble(AccountInfoDouble(ACCOUNT_BALANCE), 2);
return memory;
}
double AlignLots(string symbol, double lots, double lowerlots=0, double upperlots=0)
{
double LotStep = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
double LotSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE);
double MinLots = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
double MaxLots = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
if (LotStep > MinLots) MinLots = LotStep;
if (lots == EMPTY_VALUE) {lots = 0;}
lots = MathRound(lots/LotStep)*LotStep;
if (lots < MinLots) {lots = MinLots;}
if (lots > MaxLots) {lots = MaxLots;}
if (lowerlots > 0)
{
lowerlots = MathRound(lowerlots/LotStep)*LotStep;
if (lots < lowerlots) {lots = lowerlots;}
}
if (upperlots > 0)
{
upperlots = MathRound(upperlots/LotStep)*LotStep;
if (lots > upperlots) {lots = upperlots;}
}
return lots;
}
double AlignStopLoss(
string symbol,
int type,
double price,
double slo = 0, // original sl, used when modifying
double sll = 0,
double slp = 0,
bool consider_freezelevel = false
)
{
double sl = 0;
if (MathAbs(sll) == EMPTY_VALUE) {sll = 0;}
if (MathAbs(slp) == EMPTY_VALUE) {slp = 0;}
if (sll == 0 && slp == 0)
{
return 0;
}
if (price <= 0)
{
Print("AlignStopLoss() error: No price entered");
return(-1);
}
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
slp = slp * PipValue(symbol) * point;
int bs = 1;
if (
type == OP_SELL
|| type == OP_SELLSTOP
|| type == OP_SELLLIMIT
)
{
bs = -1;
}
double askbid = price;
double bidask = price;
if (type < 2)
{
double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
askbid = ask;
bidask = bid;
if (bs < 0)
{
askbid = bid;
bidask = ask;
}
}
if (sll == 0 && slp != 0) {sll = price;}
if (sll > 0) {sl = sll - slp * bs;}
if (sl < 0)
{
return -1;
}
sl = NormalizeDouble(sl, digits);
slo = NormalizeDouble(slo, digits);
if (sl == slo)
{
return sl;
}
double minstops = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL);
if (consider_freezelevel == true)
{
double freezelevel = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_FREEZE_LEVEL);
if (freezelevel > minstops) {minstops = freezelevel;}
}
minstops = NormalizeDouble(minstops * point,digits);
double sllimit = bidask - minstops * bs; // SL min price level
if (sl > 0 && sl != slo)
{
if ((bs > 0 && sl > askbid) || (bs < 0 && sl < askbid))
{
string abstr = "";
if (bs > 0) {abstr = "Bid";} else {abstr = "Ask";}
Print(
"Error: Invalid SL requested (",
DoubleToStr(sl, digits),
" for ", abstr, " price ",
bidask,
")"
);
return -1;
}
else if ((bs > 0 && sl > sllimit) || (bs < 0 && sl < sllimit))
{
if (USE_VIRTUAL_STOPS)
{
return sl;
}
Print(
"Warning: Too short SL requested (",
DoubleToStr(sl, digits),
" or ",
DoubleToStr(MathAbs(sl - askbid) / point, 0),
" points), minimum will be taken (",
DoubleToStr(sllimit, digits),
" or ",
DoubleToStr(MathAbs(askbid - sllimit) / point, 0),
" points)"
);
sl = sllimit;
return sl;
}
}
double ticksize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
sl = MathRound(sl / ticksize) * ticksize;
return sl;
}
double AlignTakeProfit(
string symbol,
int type,
double price,
double tpo = 0, // original tp, used when modifying
double tpl = 0,
double tpp = 0,
bool consider_freezelevel = false
)
{
double tp=0;
if (MathAbs(tpl) == EMPTY_VALUE) {tpl = 0;}
if (MathAbs(tpp) == EMPTY_VALUE) {tpp = 0;}
if (tpl == 0 && tpp == 0)
{
return 0;
}
if (price <= 0)
{
Print("AlignTakeProfit() error: No price entered");
return -1;
}
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
tpp = tpp * PipValue(symbol) * point;
int bs = 1;
if (
type == OP_SELL
|| type == OP_SELLSTOP
|| type == OP_SELLLIMIT
)
{
bs = -1;
}
double askbid = price;
double bidask = price;
if (type < 2)
{
double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
askbid = ask;
bidask = bid;
if (bs < 0)
{
askbid = bid;
bidask = ask;
}
}
if (tpl == 0 && tpp != 0) {tpl = price;}
if (tpl > 0) {tp = tpl + tpp * bs;}
if (tp < 0)
{
return -1;
}
tp = NormalizeDouble(tp, digits);
tpo = NormalizeDouble(tpo, digits);
if (tp == tpo)
{
return tp;
}
double minstops = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL);
if (consider_freezelevel == true)
{
double freezelevel = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_FREEZE_LEVEL);
if (freezelevel > minstops) {minstops = freezelevel;}
}
minstops = NormalizeDouble(minstops * point,digits);
double tplimit = bidask + minstops * bs; // TP min price level
if (tp > 0 && tp != tpo)
{
if ((bs > 0 && tp < bidask) || (bs < 0 && tp > bidask))
{
string abstr = "";
if (bs > 0) {abstr = "Bid";} else {abstr = "Ask";}
Print(
"Error: Invalid TP requested (",
DoubleToStr(tp, digits),
" for ", abstr, " price ",
bidask,
")"
);
return -1;
}
else if ((bs > 0 && tp < tplimit) || (bs < 0 && tp > tplimit))
{
if (USE_VIRTUAL_STOPS)
{
return tp;
}
Print(
"Warning: Too short TP requested (",
DoubleToStr(tp, digits),
" or ",
DoubleToStr(MathAbs(tp - askbid) / point, 0),
" points), minimum will be taken (",
DoubleToStr(tplimit, digits),
" or ",
DoubleToStr(MathAbs(askbid - tplimit) / point, 0),
" points)"
);
tp = tplimit;
return tp;
}
}
double ticksize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
tp = MathRound(tp / ticksize) * ticksize;
return tp;
}
template<typename T>
bool ArrayEnsureValue(T &array[], T value)
{
int size = ArraySize(array);
if (size > 0)
{
if (InArray(array, value))
{
return false; // no value added
}
}
ArrayResize(array, size+1);
array[size] = value;
return true; // value added
}
template<typename T>
int ArraySearch(T &array[], T value)
{
static int index;
static int size;
index = -1;
size = ArraySize(array);
for (int i=0; i<size; i++)
{
if (array[i] == value)
{
index = i;
break;
}
}
return index;
}
template<typename T>
bool ArrayStripKey(T &array[], int key)
{
int x = 0;
int size = ArraySize(array);
for (int i=0; i<size; i++)
{
if (i != key)
{
array[x] = array[i];
x++;
}
}
if (x < size)
{
ArrayResize(array, x);
return true; // stripped
}
return false; // not stripped
}
template<typename T>
bool ArrayStripValue(T &array[], T value)
{
int x = 0;
int size = ArraySize(array);
for (int i=0; i<size; i++)
{
if (array[i] != value)
{
array[x] = array[i];
x++;
}
}
if (x < size)
{
ArrayResize(array, x);
return true; // stripped
}
return false; // not stripped
}
double Bet1326(int group, string symbol, double initial_lots, bool reverse=false)
{
int pos=0;
int total=0;
double lots=0;
double profit=0;
int profit_or_loss=0; // 0 - unknown, 1 - profit, -1 - loss
total=OrdersTotal();
for (pos=total-1; pos>=0; pos--)
{
if (!OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
if (OrderExpiration() > 0 && OrderExpiration() <= OrderCloseTime()) {continue;} // no expired po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
if (lots==0)
{
total=OrdersHistoryTotal();
for (pos=total-1; pos>=0; pos--)
{
if(!OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (OrderType() > OP_SELL) {continue;} // no po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
}
if (initial_lots < MarketInfo(symbol,MODE_MINLOT)) {
initial_lots = MarketInfo(symbol,MODE_MINLOT);
}
if (lots==0) {lots = initial_lots;}
else
{
if ((reverse==false && profit_or_loss==1) || (reverse==true && profit_or_loss==-1))
{
double div = lots/initial_lots;
if (div < 1.5) {lots = initial_lots*3;}
else if (div < 2.5) {lots = initial_lots*6;}
else if (div < 3.5) {lots = initial_lots*2;}
else {lots = initial_lots;}
}
else {
lots = initial_lots;
}
}
return lots;
}
double BetDalembert(int group, string symbol, double initial_lots, double reverse=false)
{
int pos=0;
int total=0;
double lots=0;
double profit=0;
int profit_or_loss=0; // 0 - unknown, 1 - profit, -1 - loss
total=OrdersTotal();
for (pos=total-1; pos>=0; pos--)
{
if (!OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
if (OrderExpiration() > 0 && OrderExpiration() <= OrderCloseTime()) {continue;} // no expired po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
if (lots==0)
{
total=OrdersHistoryTotal();
for (pos=total-1; pos>=0; pos--)
{
if(!OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (OrderType() > OP_SELL) {continue;} // no po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
}
if (initial_lots < MarketInfo(symbol,MODE_MINLOT)) {
initial_lots = MarketInfo(symbol,MODE_MINLOT);
}
if (lots==0) {lots = initial_lots;}
else
{
if ((reverse==0 && profit_or_loss==1) || (reverse==1 && profit_or_loss==-1))
{
lots = lots - initial_lots;
if (lots < initial_lots) {lots = initial_lots;}
}
else {
lots = lots + initial_lots;
}
}
return lots;
}
double BetFibonacci(
int group,
string symbol,
double initial_lots
)
{
int pos=0;
int total=0;
double lots=0;
double profit=0;
int profit_or_loss=0; // 0 - unknown, 1 - profit, -1 - loss
total=OrdersTotal();
for (pos=total-1; pos>=0; pos--)
{
if (!OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
if (OrderExpiration() > 0 && OrderExpiration() <= OrderCloseTime()) {continue;} // no expired po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
if (lots==0)
{
total=OrdersHistoryTotal();
for (pos=total-1; pos>=0; pos--)
{
if(!OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (OrderType() > OP_SELL) {continue;} // no po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
}
if (initial_lots < MarketInfo(symbol,MODE_MINLOT)) {
initial_lots = MarketInfo(symbol,MODE_MINLOT);
}
if (lots==0) {lots = initial_lots;}
else
{
int fibo1=1, fibo2=0, fibo3=0, fibo4=0;
double div = lots/initial_lots;
if (div<=0) {div=1;}
while(true)
{
fibo1=fibo1+fibo2;
fibo3=fibo2;
fibo2=fibo1-fibo2;
fibo4=fibo2-fibo3;
if (fibo1 > NormalizeDouble(div, 2)) {break;}
}
if (profit_or_loss==1)
{
if (fibo4<=0) {fibo4=1;}
lots=initial_lots*(fibo4);
}
else {
lots=initial_lots*(fibo1);
}
}
lots=NormalizeDouble(lots, 2);
return lots;
}
double BetLabouchere(int group, string symbol, double initial_lots, string list_of_numbers, double reverse=false)
{
int pos=0;
int total=0;
double lots=0;
double profit=0;
int profit_or_loss=0; // 0 - unknown, 1 - profit, -1 - loss
total=OrdersTotal();
for (pos=total-1; pos>=0; pos--)
{
if (!OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
if (OrderExpiration() > 0 && OrderExpiration() <= OrderCloseTime()) {continue;} // no expired po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
if (lots==0)
{
total=OrdersHistoryTotal();
for (pos=total-1; pos>=0; pos--)
{
if(!OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (OrderType() > OP_SELL) {continue;} // no po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
}
static int mem_group[];
static string mem_list[];
static int mem_ticket[];
int start_again=false;
int id=ArraySearch(mem_group, group);
if (id == -1) {
start_again=true;
if (list_of_numbers=="") {list_of_numbers="1";}
id = ArraySize(mem_group);
ArrayResize(mem_group, id+1, id+1);
ArrayResize(mem_list, id+1, id+1);
ArrayResize(mem_ticket, id+1, id+1);
mem_group[id]=group;
mem_list[id]=list_of_numbers;
}
if (mem_ticket[id]==OrderTicket()) {
mem_list[id]=list_of_numbers;
}
mem_ticket[id]=OrderTicket();
int list[];
string listS[];
StringExplode(",", mem_list[id], listS);
ArrayResize(list, ArraySize(listS));
for (int s=0; s<ArraySize(listS); s++) {
list[s]=(int)StringToInteger(StringTrim(listS[s]));
}
int size = ArraySize(list);
if (initial_lots < MarketInfo(symbol,MODE_MINLOT)) {
initial_lots = MarketInfo(symbol,MODE_MINLOT);
}
if (lots==0) {
start_again=true;
}
if (start_again==true)
{
if (size==1) {
lots = initial_lots*list[0];
} else {
lots = initial_lots*(list[0]+list[size-1]);
}
}
else
{
if ((reverse==0 && profit_or_loss==1) || (reverse==1 && profit_or_loss==-1))
{
if (size==1) {
lots=initial_lots*list[0];
ArrayResize(list, 0);
}
else if (size==2) {
lots = initial_lots*(list[0]+list[1]);
ArrayResize(list, 0);
}
else if (size>2) {
lots = initial_lots*(list[0]+list[size-1]);
for(pos=0; pos<size-1; pos++) {
list[pos]=list[pos+1];
}
ArrayResize(list,ArraySize(list)-2); // remove last 2 elements
}
if (lots < initial_lots) {lots = initial_lots;}
}
else {
if (size>1)
{
ArrayResize(list, size+1);
list[size]=list[0]+list[size-1];
lots = initial_lots*(list[0]+list[size]);
} else {
lots = initial_lots*list[0];
}
if (lots < initial_lots) {lots = initial_lots;}
}
}
Print("Labouchere (for group "+(string)id+") current list of numbers:"+StringImplode(",", list));
size=ArraySize(list);
if (size==0) {
ArrayStripKey(mem_group, id);
ArrayStripKey(mem_list, id);
ArrayStripKey(mem_ticket, id);
} else {
mem_list[id]=StringImplode(",", list);
}
return lots;
}
double BetMartingale(
int group,
string symbol,
double initial_lots,
double multiply_on_loss,
double multiply_on_profit,
double add_on_loss,
double add_on_profit,
int reset_on_loss,
int reset_on_profit
)
{
int pos=0;
int total=0;
double lots=0;
double profit=0;
int profit_or_loss=0; // 0 - unknown, 1 - profit, -1 - loss
int in_a_row=0;
total=OrdersTotal();
for (pos=total-1; pos>=0; pos--)
{
if (!OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
if (OrderExpiration() > 0 && OrderExpiration() <= OrderCloseTime()) {continue;} // no expired po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit_or_loss == 0)
{
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
}
else {
if (profit_or_loss==1 && profit<0) {break;}
else if (profit_or_loss==-1 && profit>=0) {break;}
}
in_a_row++;
}
if (lots==0)
{
total=OrdersHistoryTotal();
for (pos=total-1; pos>=0; pos--)
{
if(!OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (OrderType() > OP_SELL) {continue;} // no po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit_or_loss == 0)
{
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
}
else {
if (profit_or_loss==1 && profit<0) {break;}
else if (profit_or_loss==-1 && profit>=0) {break;}
}
in_a_row++;
}
}
/*
if (initial_lots < MarketInfo(symbol,MODE_MINLOT)) {
initial_lots = MarketInfo(symbol,MODE_MINLOT);
}*/
if (lots==0) {lots = initial_lots;}
else {
if (profit_or_loss==1)
{
if (reset_on_profit>0 && in_a_row >= reset_on_profit) {
lots=initial_lots;
}
else {
if (multiply_on_profit<=0) {multiply_on_profit=1;}
lots=(lots*multiply_on_profit) + add_on_profit;
}
}
else {
if (reset_on_loss>0 && in_a_row >= reset_on_loss) {
lots=initial_lots;
}
else {
if (multiply_on_loss<=0) {multiply_on_loss=1;}
lots=(lots*multiply_on_loss) + add_on_loss;
}
}
}
return lots;
}
double BetSequence(int group, string symbol, double initial_lots, string sequence_on_loss, string sequence_on_profit, bool reverse=false)
{
int pos=0;
int total=0;
double lots=0;
int size=0;
double profit=0;
int profit_or_loss=0; // 0 - unknown, 1 - profit, -1 - loss
total=OrdersTotal();
for (pos=total-1; pos>=0; pos--)
{
if (!OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
if (OrderExpiration() > 0 && OrderExpiration() <= OrderCloseTime()) {continue;} // no expired po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
if (lots==0)
{
total=OrdersHistoryTotal();
for (pos=total-1; pos>=0; pos--)
{
if(!OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)) {continue;}
if (OrderMagicNumber() != MagicStart+group) {continue;}
if (OrderSymbol() != symbol) {continue;}
if (OrderType() > OP_SELL) {continue;} // no po
if (lots==0) {
lots=OrderLots();
}
profit = OrderClosePrice()-OrderOpenPrice();
profit = NormalizeDouble(profit, SymbolDigits(OrderSymbol()));
if (IsOrderTypeSell()) {profit = -1*profit;}
if (profit == 0) {
return(lots);
}
if (profit<0) {profit_or_loss=-1;}
else {profit_or_loss=1;}
break;
}
}
static int mem_group[];
static string mem_list_loss[];
static string mem_list_profit[];
static int mem_ticket[];
int id=ArraySearch(mem_group, group);
if (id == -1)
{
if (sequence_on_loss=="") {sequence_on_loss="1";}
if (sequence_on_profit=="") {sequence_on_profit="1";}
id = ArraySize(mem_group);
ArrayResize(mem_group, id+1, id+1);
ArrayResize(mem_list_loss, id+1, id+1);
ArrayResize(mem_list_profit, id+1, id+1);
ArrayResize(mem_ticket, id+1, id+1);
mem_group[id] =group;
mem_list_loss[id] =sequence_on_loss;
mem_list_profit[id] =sequence_on_profit;
}
bool loss_reset=false;
bool profit_reset=false;
if (profit_or_loss==-1 && mem_list_loss[id]=="") {
loss_reset=true;
mem_list_profit[id]="";
}
if (profit_or_loss==1 && mem_list_profit[id]=="") {
profit_reset=true;
mem_list_loss[id]="";
}
if (profit_or_loss==1 || mem_list_loss[id]=="") {
mem_list_loss[id]=sequence_on_loss;
if (loss_reset) {mem_list_loss[id]="1,"+mem_list_loss[id];}
}
if (profit_or_loss==-1 ||mem_list_profit[id]=="") {
mem_list_profit[id]=sequence_on_profit;
if (profit_reset) {mem_list_profit[id]="1,"+mem_list_profit[id];}
}
if (mem_ticket[id]==OrderTicket()) {
mem_list_loss[id]=sequence_on_loss;
mem_list_profit[id]=sequence_on_profit;
}
mem_ticket[id]=OrderTicket();
int s=0;
double list_loss[];
double list_profit[];
string listS[];
StringExplode(",", mem_list_loss[id], listS);
ArrayResize(list_loss, ArraySize(listS), ArraySize(listS));
for (s=0; s<ArraySize(listS); s++) {
list_loss[s]=(double)StringToDouble(StringTrim(listS[s]));
}
StringExplode(",", mem_list_profit[id], listS);
ArrayResize(list_profit, ArraySize(listS), ArraySize(listS));
for (s=0; s<ArraySize(listS); s++) {
list_profit[s]=(double)StringToDouble(StringTrim(listSПоказано первые 50% кода (символов: 125718)
Открыть по тарифу
Купите тариф с пакетом открытий или войдите, если тариф уже есть. Открытый файл останется в вашем кабинете навсегда.
Разовая покупка файла
На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.
Зачем нужен email? После подтверждения оплаты файл сохранится в кабинете на этот email. Если аккаунта ещё нет, мы создадим его и пришлём ссылку для задания пароля. Если аккаунт уже есть, покупка добавится в него. Укажите адрес, к которому у вас есть доступ.
Чтобы оформить заказ, введите email и перейдите к оплате.