//+------------------------------------------------------------------------------+//
//)   ____  _  _  ____  ____  ____  ____  __  __    __      ___  _____  __  __   (//
//)  ( ___)( \/ )(  _ \(  _ \( ___)( ___)(  \/  )  /__\    / __)(  _  )(  \/  )  (//
//)   )__)  )  (  )(_) ))   / )__)  )__)  )    (  /(__)\  ( (__  )(_)(  )    (   (//
//)  (__)  (_/\_)(____/(_)\_)(____)(____)(_/\/\_)(__)(__)()\___)(_____)(_/\/\_)  (//
//)   http://fxdreema.com                              Copyright 2018, fxDreema  (//
//+------------------------------------------------------------------------------+//
#property copyright ""
#property link      "https://fxdreema.com"

/************************************************************************************************************************/
// +------------------------------------------------------------------------------------------------------------------+ //
// |                       INPUT PARAMETERS, GLOBAL VARIABLES, CONSTANTS, IMPORTS and INCLUDES                        | //
// |                      System and Custom variables and other definitions used in the project                       | //
// +------------------------------------------------------------------------------------------------------------------+ //
/************************************************************************************************************************/

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// System constants (project settings) //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
#define PROJECT_ID           "mt5-4466"
//--
#define ENABLE_EVENT_TIMER 0 // "Timer" event: 1 - enable, 0 - disable
#define ON_TIMER_PERIOD   60        // Timer event period (in seconds)

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// System constants (predefined constants) //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
#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_FIRSTLEVEL 806
#define OBJPROP_TIME1 807
#define OBJPROP_TIME2 808
#define OBJPROP_TIME3 809
#define OBJPROP_PRICE1 810
#define OBJPROP_PRICE2 811
#define OBJPROP_PRICE3 812
#define OBJPROP_BARSHIFT1 813
#define OBJPROP_BARSHIFT2 814
#define OBJPROP_BARSHIFT3 815
#define SEL_CURRENT 0
#define SEL_INITIAL 1

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// Project global variables, includes, imports //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//

// fxDreema Constants
input int atrPeriod = 72; // atrPeriod
input int fast = 144; // fast
input int slow = 610; // slow
input int sig = 9; // sig
input int goodRise = 13; // goodRise
input int escapeBars = 13; // escapeBars
input int minAnchor = 34; // minAnchor
input int surebars = 1; // surebars
input int rsi = 5; // rsi
input int tradeQuality = 8; // tradeQuality

// fxDreema Variables
double currentH = 0; // currentH
int currentHAGE = 0; // currentHAGE
double currentL = 0; // currentL
int currentLAGE = 0; // currentLAGE
int confirmedHAGE = 0; // confirmedHAGE
int confirmedLAGE = 0; // confirmedLAGE
int anchorH = 0; // anchorH
int anchorL = 0; // anchorL
int risingBars = 0; // risingBars
int fallingBars = 0; // fallingBars
double cAngle = 0; // cAngle
int outsideRISE = 0; // outsideRISE
int outsideFALL = 0; // outsideFALL
int intraBar = 0; // intraBar
double anchorHregL = 0; // anchorHregL
double anchorHregL2 = 0; // anchorHregL2
double anchorLregL = 0; // anchorLregL
double anchorLregL2 = 0; // anchorLregL2
int checkbars = 0; // checkbars
int dayDrawn = 0; // dayDrawn
int correctDrawn = 0; // correctDrawn
int actualFall = 0; // actualFall
int actualRise = 0; // actualRise
int trUp = 0; // trUp
int trDn = 0; // trDn
int blc = 0; // blc
// Global variables used as Formula Results or coming out of some blocks
double atr2;
double check1;
double check2;
double check3;
double check4;
input int MagicStart=4466; // Magic Start (MagicNumber=MagicStart+Group#)

//VVVVVVVVVVVVVVVVVVVVVVVVV//
// System global variables //
//^^^^^^^^^^^^^^^^^^^^^^^^^//
int FXD_CURRENT_FUNCTION_ID=0;
double FXD_MILS_INIT_END=0;
bool FXD_FIRST_TICK_PASSED=false;
bool FXD_BREAK=false;
bool FXD_CONTINUE=false;

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// Global variables used as On-Off property for fxDreema blocks //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
bool block1=true; // (1) Once per bar
bool block2=true; // (2) RISINGMACD
bool block3=true; // (3) Modify Variables
bool block4=true; // (4) Condition
bool block5=true; // (5) Condition
bool block6=true; // (6) NewHigh
bool block7=true; // (7) Modify Variables
bool block8=true; // (8) Condition
bool block9=true; // (9) Condition
bool block10=true; // (10) NewLow
bool block11=true; // (11) PASS THESE FIRST
bool block12=true; // (12) CROSSED
bool block13=true; // (13) PASS THESE FIRST
bool block14=true; // (14) Condition
bool block15=true; // (15) Modify Variables
bool block16=true; // (16) RESET
bool block17=true; // (17) PASS THESE FIRST
bool block18=true; // (18) CROSSED
bool block19=true; // (19) PASS THESE FIRST
bool block20=true; // (20) Condition
bool block21=true; // (21) Modify Variables
bool block22=true; // (22) RESET
bool block23=true; // (23) PASS THESE FIRST
bool block26=true; // (26) Draw Line
bool block27=true; // (27) Draw Line
bool block28=true; // (28) AGEAGEAGE
bool block29=true; // (29) PASS THESE FIRST
bool block31=true; // (31) Modify Variables
bool block32=true; // (32) Once per DAY
bool block33=true; // (33) Condition
bool block34=true; // (34) Condition
bool block35=true; // (35) Draw Channel
bool block36=true; // (36) Draw Channel
bool block38=true; // (38) Draw Line&nbsp;
bool block39=true; // (39) Formula&nbsp;
bool block48=true; // (48) Draw Line&nbsp;
bool block55=true; // (55) PASS THESE FIRST
bool block57=true; // (57) Draw Line&nbsp;
bool block67=true; // (67) Draw Line&nbsp;
bool block74=true; // (74) Condition
bool block75=true; // (75) Modify Variables&nbsp;
bool block76=true; // (76) Modify Variables&nbsp;
bool block77=true; // (77) Condition
bool block78=true; // (78) Condition
bool block79=true; // (79) NEW ANCHOR
bool block80=true; // (80) PASS THESE FIRST
bool block81=true; // (81) Condition
bool block82=true; // (82) Modify Variables&nbsp;
bool block83=true; // (83) Modify Variables&nbsp;
bool block84=true; // (84) Condition
bool block85=true; // (85) Condition
bool block86=true; // (86) NEW ANCHOR
bool block92=true; // (92) Modify Variables
bool block94=true; // (94) Condition
bool block95=true; // (95) Condition
bool block97=true; // (97) Condition
bool block99=true; // (99) Custom MQL5 code
bool block100=true; // (100) Condition&nbsp;
bool block101=true; // (101) Modify Variables
bool block102=true; // (102) Condition&nbsp;
bool block103=true; // (103) Modify Variables
bool block104=true; // (104) Condition
bool block105=true; // (105) PASS THESE FIRST
bool block106=true; // (106) Condition&nbsp;
bool block107=true; // (107) Modify Variables
bool block108=true; // (108) Condition&nbsp;
bool block109=true; // (109) Modify Variables
bool block110=true; // (110) Condition&nbsp;
bool block111=true; // (111) PASS THESE FIRST
bool block112=true; // (112) Condition
bool block113=true; // (113) Condition
bool block114=true; // (114) Formula
bool block115=true; // (115) Formula
bool block116=true; // (116) Formula
bool block117=true; // (117) Formula
bool block118=true; // (118) Condition
bool block119=true; // (119) Condition
bool block120=true; // (120) Pass
bool block121=true; // (121) Comment
bool block122=true; // (122) PASS THESE FIRST
bool block123=true; // (123) Draw Line&nbsp;
bool block142=true; // (142) Draw Line&nbsp;
bool block143=true; // (143) Condition
bool block144=true; // (144) Condition
bool block145=true; // (145) Modify Variables&nbsp;
bool block146=true; // (146) Condition&nbsp;
bool block147=true; // (147) Condition&nbsp;
bool block148=true; // (148) PASS THESE FIRST
bool block149=true; // (149) TRADE
bool block150=true; // (150) Condition
bool block151=true; // (151) PASS THESE FIRST
bool block152=true; // (152) REAL RISE
bool block153=true; // (153) REAL FALL
bool block154=true; // (154) QUALITY CHECK
bool block155=true; // (155) QUALITY CHECK
bool block156=true; // (156) Condition
bool block157=true; // (157) Condition
bool block158=true; // (158) Condition
bool block159=true; // (159) BuyRun
bool block160=true; // (160) SellRun
bool block161=true; // (161) GA &nbsp; &nbsp;TE
bool block162=true; // (162) Buy now
bool block163=true; // (163) Condition
bool block164=true; // (164) Condition
bool block165=true; // (165) Condition
bool block168=true; // (168) GA &nbsp; &nbsp;TE
bool block169=true; // (169) Sell now
bool block171=true; // (171) Draw Line&nbsp;
bool block190=true; // (190) Draw Line&nbsp;
bool block191=true; // (191) Condition
bool block192=true; // (192) Condition
bool block193=true; // (193) BuyRun
bool block194=true; // (194) Condition
bool block195=true; // (195) Condition
bool block196=true; // (196) SellRun

//VVVVVVVVVVVVVVVVVVV//
// System structures //
//^^^^^^^^^^^^^^^^^^^//
struct position
{
   ulong    position_id;
   long     type,
            magic;
   datetime time;
   double   volume,
            price_open,
            sl,
            tp,
            price_current,
            comission,
            swap,
            profit;
   string   symbol,
            comment;
};
struct order
{
   datetime time_setup,
            time_expiration,
            time_done;
   long     type,
            state,
            type_filling,
            type_time,
            magic,
            position_id;
   ulong    ticket;
   double   volume_initial,
            volume_current,
            price_open,
            sl,
            tp,
            price_current,
            price_stoplimit;
   string   symbol,
            comment;
};

position  EGV_PositionsList[];
position  EGV_PositionsList0[];
order     EGV_OrderList[];
order     EGV_OrderList0[];

/************************************************************************************************************************/
// +------------------------------------------------------------------------------------------------------------------+ //
// |                                                 EVENT FUNCTIONS                                                  | //
// |                           These are the main functions that controls the whole project                           | //
// +------------------------------------------------------------------------------------------------------------------+ //
/************************************************************************************************************************/

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// This function is executed once when the program starts //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
int OnInit()
{
	Comment("");
	for (int i=ObjectsTotal(ChartID()); i>=0; i--)
	{
	   string name = ObjectName(ChartID(), i);
	   if (StringSubstr(name,0,8) == "fxd_cmnt") {ObjectDelete(ChartID(), name);}
	}
	ChartRedraw();
	
	// This is needed for OnTrade event
	BuildPositionsList(EGV_PositionsList0);
	BuildOrdersList(EGV_OrderList0);

	TimeAtStart("set"); // Set local and server time at start
	AccountBalanceAtStart(); // Set balance at start

	DrawSpreadInfo();
	DrawStatus("Starting...");

	if (ENABLE_EVENT_TIMER) {
		OnTimerSet(ON_TIMER_PERIOD);
	}



	FXD_MILS_INIT_END=(double)GetTickCount();
	FXD_FIRST_TICK_PASSED = false; // reset is needed when changing inputs

	return(INIT_SUCCEEDED);
}


//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// This function is executed on every incoming tick //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
void OnTick()
{
	if (FXD_FIRST_TICK_PASSED==false) {DrawStatus("Working"); FXD_FIRST_TICK_PASSED=true;}
	DrawSpreadInfo();
	TicksData(""); // Collect ticks (if needed)
	// Main beginning on the graph
	block1();

	// Needed by the system
	TicksFromStart(true);
}

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// This function is executed on trade events - open, close, modify //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
void OnTrade()
{
	OnTradeQueue(1);
	OnTradeQueue(-1);
}

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//
// This function is executed once when the program ends //
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
void OnDeinit(const int reason)
{
	//-- if Timer was set, kill it here
	EventKillTimer();

	if (MQL5InfoInteger(MQL5_TESTING)) {
		Print("Backtested in "+DoubleToString((GetTickCount()-FXD_MILS_INIT_END)/1000, 2)+" seconds");
		Print("Average ticks per second: "+DoubleToString(TicksFromStart()/(GetTickCount()-FXD_MILS_INIT_END),0));
	}

	DrawStatus("Stopped");
	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 Advisorhas 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;
		}
	}
}

/************************************************************************************************************************/
// +------------------------------------------------------------------------------------------------------------------+ //
// |                                   FUNCTIONS THAT REPRESENTS BLOCKS IN FXDREEMA                                   | //
// |                                    Each block is represented as function here                                    | //
// +------------------------------------------------------------------------------------------------------------------+ //
/************************************************************************************************************************/

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #1 (Once per bar) //
void block1(int _parent_=0)
{
	if (block1==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=1;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string SYMBOL=CurrentSymbol(); // Market
	ENUM_TIMEFRAMES TIMEFRAME=CurrentTimeframe(); // Timeframe
	int PassMaxTimes=1; // Max. times to pass
	
	///////////////
	// Main code //
	///////////////
	
	static int times = 0;
	datetime Time[];
	static datetime time0;
	ArraySetAsSeries(Time,true);
	CopyTime(SYMBOL,TIMEFRAME,0,1,Time);
	datetime time=Time[0];
	if (time0<time) {
	   times++;
	   if (times >= PassMaxTimes)
	   {
	      time0=time;
	      times=0;
	   }
	   block122(1);
	}
	else {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #2 (RISINGMACD) //
void block2(int _parent_=0)
{
	if (block2==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=2;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_iMACD(fast, slow, sig, PRICE_CLOSE, 0, CurrentSymbol(), CurrentTimeframe(), 1);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_iMACD(fast, slow, sig, PRICE_CLOSE, 1, CurrentSymbol(), CurrentTimeframe(), 2);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block3(2);} else if (o2==true) {block7(2);}
}
double _iMACD(int FastEMAperiod, int SlowEMAperiod, int SignalPeriod, int AppliedPrice, int Mode, string SYMBOL, ENUM_TIMEFRAMES TIMEFRAME, int SHIFT) {
	SHIFT=SHIFT+IndicatorMoreShift();
	double retval=IndicatorGetValue(iMACD(SYMBOL,TIMEFRAME,FastEMAperiod,SlowEMAperiod,SignalPeriod,AppliedPrice),Mode,SHIFT);
	SetLastIndicatorData(retval,SYMBOL,TIMEFRAME,SHIFT);
	return(retval);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #3 (Modify Variables) //
void block3(int _parent_=0)
{
	if (block3==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=3;

	risingBars=(_value(risingBars)+1);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	block11(3);
}
double _value(double Value) {
	return(Value);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #4 (Condition) //
void block4(int _parent_=0)
{
	if (block4==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=4;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(currentH);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(0);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		currentHAGE=0;
		// (finish)
	
	block6(4);} else if (o2==true) {block5(4);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #5 (Condition) //
void block5(int _parent_=0)
{
	if (block5==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=5;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iHigh", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(currentH);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block6(5);} else if (o2==true) {/* Yellow output */}
}
double _candles(string iOHLC, string ModeCandleFindBy, int CandleID, string TimeStamp, string SYMBOL, ENUM_TIMEFRAMES TIMEFRAME) {
	double retval=0;
	double cOpen[];
	double cHigh[];
	double cLow[];
	double cClose[]; 
	long cTickVolume[];
	long cRealVolume[];
	datetime cTime[];
	
	if (ModeCandleFindBy == "time")
	{
	   CandleID = iCandleID(SYMBOL, TIMEFRAME, StrToTime(TimeStamp));
	}
	
	CandleID=CandleID+IndicatorMoreShift();
	
	if (iOHLC=="iOpen") {
	   CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
	   retval=cOpen[0];
	}
	else if (iOHLC=="iHigh") {
	   CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
	   retval=cHigh[0];
	}
	else if (iOHLC=="iLow") {
	   CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
	   retval=cLow[0];
	}
	else if (iOHLC=="iClose") {
	   CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=cClose[0];
	}
	else if (iOHLC=="iTickVolume") {
		CopyTickVolume(SYMBOL,TIMEFRAME,CandleID,1,cTickVolume);
		retval=(double)cTickVolume[0];
	}
	else if (iOHLC=="iRealVolume") {
		CopyRealVolume(SYMBOL,TIMEFRAME,CandleID,1,cRealVolume);
		retval=(double)cRealVolume[0];
	}
	else if (iOHLC=="iTime") {
		CopyTime(SYMBOL,TIMEFRAME,CandleID,1,cTime);
		retval=(double)cTime[0];
	}
	else if (iOHLC=="iTypical") {
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=((cLow[0]+cHigh[0]+cClose[0])/3);
	}
	else if (iOHLC=="iMedian") {
	   CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		retval=((cLow[0]+cHigh[0])/2);
	}
	else if (iOHLC=="iAverage") {
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=((cLow[0]+cHigh[0]+cClose[0]+cClose[0])/4);
	}
	else if (iOHLC=="iTotal") {
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		retval=toPips(MathAbs(cHigh[0]-cLow[0]),SYMBOL);
	}
	else if (iOHLC=="iBody") {
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=toPips(MathAbs(cClose[0]-cOpen[0]),SYMBOL);
	}
	else if (iOHLC=="iUpperWick") {
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		retval=0;
		if (cClose[0]>cOpen[0]) {
		   retval=toPips(MathAbs(cHigh[0]-cClose[0]),SYMBOL);
		} else {
		   retval=toPips(MathAbs(cHigh[0]-cOpen[0]),SYMBOL);
		}
	}
	else if (iOHLC=="iBottomWick") {
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		retval=0;
		if (cClose[0]>cOpen[0]) {
		   retval=toPips(MathAbs(cOpen[0]-cLow[0]),SYMBOL);
		} else {
		   retval=toPips(MathAbs(cClose[0]-cLow[0]),SYMBOL);
		}
	}
	else if (iOHLC=="iBullTotal") {
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		retval=toPips((cHigh[0]-cLow[0]),SYMBOL);
		if (cClose[0]<cOpen[0]) {return(EMPTY_VALUE);}
	}
	else if (iOHLC=="iBullBody") {
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=toPips((cClose[0]-cOpen[0]),SYMBOL);
		if (cClose[0]<cOpen[0]) {return(EMPTY_VALUE);}
		}
	else if (iOHLC=="iBullUpperWick") {
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=toPips((cHigh[0]-cClose[0]),SYMBOL);
		if (cClose[0]<cOpen[0]) {return(EMPTY_VALUE);}
		}
	else if (iOHLC=="iBullBottomWick") {
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=toPips((cOpen[0]-cLow[0]),SYMBOL);
		if (cClose[0]<cOpen[0]) {return(EMPTY_VALUE);}
	}
	else if (iOHLC=="iBearTotal") {
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		retval=toPips((cHigh[0]-cLow[0]),SYMBOL);
		if (cOpen[0]<cClose[0]) {return(EMPTY_VALUE);}
	}
	else if (iOHLC=="iBearBody") {
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=toPips((cOpen[0]-cClose[0]),SYMBOL);
		if (cOpen[0]<cClose[0]) {return(EMPTY_VALUE);}
	}
	else if (iOHLC=="iBearUpperWick") {
		CopyHigh(SYMBOL,TIMEFRAME,CandleID,1,cHigh);
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=toPips((cHigh[0]-cOpen[0]),SYMBOL);
		if (cOpen[0]<cClose[0]) {return(EMPTY_VALUE);}
	}
	else if (iOHLC=="iBearBottomWick") {
		CopyLow(SYMBOL,TIMEFRAME,CandleID,1,cLow);
		CopyOpen(SYMBOL,TIMEFRAME,CandleID,1,cOpen);
		CopyClose(SYMBOL,TIMEFRAME,CandleID,1,cClose);
		retval=toPips((cClose[0]-cLow[0]),SYMBOL);
		if (cOpen[0]<cClose[0]) {return(EMPTY_VALUE);}
	}
	return(retval);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #6 (NewHigh) //
void block6(int _parent_=0)
{
	if (block6==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=6;

	currentH=_candles("iHigh", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	currentHAGE=_value(0);
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #7 (Modify Variables) //
void block7(int _parent_=0)
{
	if (block7==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=7;

	fallingBars=(_value(fallingBars)+1);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	block17(7);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #8 (Condition) //
void block8(int _parent_=0)
{
	if (block8==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=8;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(currentL);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(0);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		currentLAGE=0;
		// (finish)
	
	block10(8);} else if (o2==true) {block9(8);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #9 (Condition) //
void block9(int _parent_=0)
{
	if (block9==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=9;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iLow", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(currentL);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block10(9);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #10 (NewLow) //
void block10(int _parent_=0)
{
	if (block10==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=10;

	currentL=_candles("iLow", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	currentLAGE=_value(0);
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #11 (PASS THESE FIRST) //
void block11(int _parent_=0)
{
	if (block11==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=11;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block4(11);}
	block13(11);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #12 (CROSSED) //
void block12(int _parent_=0)
{
	if (block12==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=12;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(risingBars);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block14(12);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #13 (PASS THESE FIRST) //
void block13(int _parent_=0)
{
	if (block13==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=13;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block12(13);}
	block16(13);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #14 (Condition) //
void block14(int _parent_=0)
{
	if (block14==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=14;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(fallingBars);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(goodRise);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block15(14);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #15 (Modify Variables) //
void block15(int _parent_=0)
{
	if (block15==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=15;

	confirmedLAGE=_value(currentLAGE);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #16 (RESET) //
void block16(int _parent_=0)
{
	if (block16==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=16;

	currentL=_value(0);
	currentLAGE=_value(0);
	fallingBars=_value(0);
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #17 (PASS THESE FIRST) //
void block17(int _parent_=0)
{
	if (block17==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=17;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block8(17);}
	block19(17);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #18 (CROSSED) //
void block18(int _parent_=0)
{
	if (block18==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=18;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(fallingBars);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block20(18);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #19 (PASS THESE FIRST) //
void block19(int _parent_=0)
{
	if (block19==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=19;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block18(19);}
	block22(19);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #20 (Condition) //
void block20(int _parent_=0)
{
	if (block20==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=20;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(risingBars);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(goodRise);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block21(20);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #21 (Modify Variables) //
void block21(int _parent_=0)
{
	if (block21==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=21;

	confirmedHAGE=_value(currentHAGE);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #22 (RESET) //
void block22(int _parent_=0)
{
	if (block22==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=22;

	currentH=_value(0);
	currentHAGE=_value(0);
	risingBars=_value(0);
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #23 (PASS THESE FIRST) //
void block23(int _parent_=0)
{
	if (block23==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=23;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block2(23);}
	block29(23);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #26 (Draw Line) //
void block26(int _parent_=0)
{
	if (block26==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=26;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="CONH"; // Object name/prefix (optional)
	int ObjectType=OBJ_VLINE; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=false; // Ray right
	color ObjColor=clrRed; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=3; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=true; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","26","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", confirmedHAGE, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 10, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=_candles("iClose", "id", 0, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=_candles("iClose", "id", 10, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	block27(26);
}
datetime _time(int ModeTime, int TimeSource, string TimeStamp, int TimeCandleID, string TimeMarket, ENUM_TIMEFRAMES TimeCandleTimeframe, int TimeComponentYear, int TimeComponentMonth, int TimeComponentDay, int TimeComponentHour, int TimeComponentMinute, int TimeComponentSecond, int ModeTimeShift, int TimeShiftYears, int TimeShiftMonths, int TimeShiftWeeks, int TimeShiftDays, int TimeShiftHours, int TimeShiftMinutes, int TimeShiftSeconds, bool TimeSkipWeekdays) {
	static datetime retval=0, retval0=0;
	static int ModeTime0=0;
	static int smodeshift=0;
	
	if(ModeTime==0) {
	   if (TimeSource==1) {retval=TimeLocal();} else {retval=TimeCurrent();}
	}
	else if(ModeTime==1) {
	      retval=StringToTime(TimeStamp);
	      retval0=retval;
	}
	else if(ModeTime==2) {
	   retval = TimeFromComponents(TimeSource == 1, TimeComponentYear, TimeComponentMonth, TimeComponentDay, TimeComponentHour, TimeComponentMinute, TimeComponentSecond);
	}
	else if(ModeTime==3) {
	      datetime Time[];
	      ArraySetAsSeries(Time,true);
	      CopyTime(TimeMarket,TimeCandleTimeframe,TimeCandleID,1,Time);
	      retval=Time[0];
	}
	
	
	
	if (ModeTimeShift>0) {
	   int sh=1;
	   if (ModeTimeShift==1) {sh=-1;}
	   
	   static int years0=0,months0=0;
	   
	   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=TimeComponentDay;
	            hour=TimeComponentHour; minute=TimeComponentMinute; second=TimeComponentSecond;
	         }
	         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+TimeShiftWeeks*604800*sh+TimeShiftDays*86400*sh+TimeShiftHours*3600*sh+TimeShiftMinutes*60*sh+TimeShiftSeconds*sh;
	   
	   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(retval);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #27 (Draw Line) //
void block27(int _parent_=0)
{
	if (block27==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=27;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="CONL"; // Object name/prefix (optional)
	int ObjectType=OBJ_VLINE; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=false; // Ray right
	color ObjColor=clrDeepSkyBlue; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=3; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=true; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","27","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", confirmedLAGE, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 10, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=_candles("iClose", "id", 0, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=_candles("iClose", "id", 10, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #28 (AGEAGEAGE) //
void block28(int _parent_=0)
{
	if (block28==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=28;

	currentHAGE=(_value(currentHAGE)+1);
	currentLAGE=(_value(currentLAGE)+1);
	confirmedHAGE=(_value(confirmedHAGE)+1);
	confirmedLAGE=(_value(confirmedLAGE)+1);
	// Variable5 is not selected =;
	
	block26(28); block31(28);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #29 (PASS THESE FIRST) //
void block29(int _parent_=0)
{
	if (block29==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=29;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block28(29);}
	block80(29);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #31 (Modify Variables) //
void block31(int _parent_=0)
{
	if (block31==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=31;

	anchorH=(_value(anchorH)+1);
	anchorL=(_value(anchorL)+1);
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #32 (Once per DAY) //
void block32(int _parent_=0)
{
	if (block32==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=32;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string SYMBOL=CurrentSymbol(); // Market
	ENUM_TIMEFRAMES TIMEFRAME=PERIOD_D1; // Timeframe
	int PassMaxTimes=1; // Max. times to pass
	
	///////////////
	// Main code //
	///////////////
	
	static int times = 0;
	datetime Time[];
	static datetime time0;
	ArraySetAsSeries(Time,true);
	CopyTime(SYMBOL,TIMEFRAME,0,1,Time);
	datetime time=Time[0];
	if (time0<time) {
	   times++;
	   if (times >= PassMaxTimes)
	   {
	      time0=time;
	      times=0;
	   }
	   
	
		// (adjust) Variables
		outsideRISE=6;
		outsideFALL=6;
		intraBar=0;
		dayDrawn=0;
		correctDrawn=0;
		// (finish)
	
	block33(32); block34(32);
	}
	else {block105(32);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #33 (Condition) //
void block33(int _parent_=0)
{
	if (block33==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=33;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(anchorH);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(goodRise);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block35(33);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #34 (Condition) //
void block34(int _parent_=0)
{
	if (block34==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=34;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(anchorL);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(goodRise);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block36(34);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #35 (Draw Channel) //
void block35(int _parent_=0)
{
	if (block35==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=35;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="FALLC"; // Object name/prefix (optional)
	ENUM_OBJECT ObjectType=OBJ_REGRESSION; // Object type
	double ObjDeviation=1; // Deviation
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=false; // Ray right
	double ObjFill=false; // Fill with color
	color ObjColor=clrNONE; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=true; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0, p3=0;
	   datetime t1=0, t2=0, t3=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_channel_","35","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	      
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2,t3,p3))
	      {
	         Print(__FUNCTION__,": failed to create channel object! Error code = ",GetLastError());
	      }
	      
	      switch(ObjectType)
	      {
	         case OBJ_CHANNEL: {t1=1; p1=1; t2=1; p2=1; t3=1; p3=1; break;}
	         case OBJ_STDDEVCHANNEL: {t1=1; t2=1;}
	         case OBJ_REGRESSION: {t1=1; t2=1;}
	         case OBJ_PITCHFORK: {t1=1; p1=1; t2=1; p2=1; t3=1; p3=1; break;}
	      }
	      
	      
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorH, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 1, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (t3==1) {t3=_time(3, 0, "00:00", 20, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,2,t3);}
	      if (p1==1) {p1=_candles("iClose", "id", 0, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=_candles("iClose", "id", 10, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      if (p3==1) {p3=_candles("iClose", "id", 20, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,2,p3);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_FILL,ObjFill);
	      ObjectSetDouble(ObjChartID,name,OBJPROP_DEVIATION,ObjDeviation);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #36 (Draw Channel) //
void block36(int _parent_=0)
{
	if (block36==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=36;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="RISEC"; // Object name/prefix (optional)
	ENUM_OBJECT ObjectType=OBJ_REGRESSION; // Object type
	double ObjDeviation=1; // Deviation
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=false; // Ray right
	double ObjFill=false; // Fill with color
	color ObjColor=clrNONE; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=true; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0, p3=0;
	   datetime t1=0, t2=0, t3=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_channel_","36","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	      
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2,t3,p3))
	      {
	         Print(__FUNCTION__,": failed to create channel object! Error code = ",GetLastError());
	      }
	      
	      switch(ObjectType)
	      {
	         case OBJ_CHANNEL: {t1=1; p1=1; t2=1; p2=1; t3=1; p3=1; break;}
	         case OBJ_STDDEVCHANNEL: {t1=1; t2=1;}
	         case OBJ_REGRESSION: {t1=1; t2=1;}
	         case OBJ_PITCHFORK: {t1=1; p1=1; t2=1; p2=1; t3=1; p3=1; break;}
	      }
	      
	      
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorL, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 1, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (t3==1) {t3=_time(3, 0, "00:00", 20, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,2,t3);}
	      if (p1==1) {p1=_candles("iClose", "id", 0, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=_candles("iClose", "id", 10, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      if (p3==1) {p3=_candles("iClose", "id", 20, "00:00", CurrentSymbol(), CurrentTimeframe()); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,2,p3);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_FILL,ObjFill);
	      ObjectSetDouble(ObjChartID,name,OBJPROP_DEVIATION,ObjDeviation);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #38 (Draw Line&nbsp;) //
void block38(int _parent_=0)
{
	if (block38==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=38;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="FALL2"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrRed; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","38","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorH, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 1, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=_OBJECT("name", "FALLC", OBJPROP_PRICE1, 0, 1.2, 0); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=_OBJECT("name", "FALLC", OBJPROP_PRICE2, 0, 1.2, 0); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	block57(38);
}
double _OBJECT(string ObjSource, string Name, int Property, int FiboLevelID, double TLpriceLevel, int SHIFT) {
	if (ObjSource=="objloop") {Name=LoadedObjectName();}
	if (ObjectFind(0,Name)<0) {return(EMPTY_VALUE);}
	double retval=0;
	int modifier=0;
	
	double Fibo100=0;
	double Fibo0=0;
	double FiboDiff=0;
	
	if (Property==OBJPROP_TIME1)        {retval=(int)ObjectGetInteger(0,Name,OBJPROP_TIME,0);}
	else if (Property==OBJPROP_TIME2)   {retval=(int)ObjectGetInteger(0,Name,OBJPROP_TIME,1);}
	else if (Property==OBJPROP_TIME3)   {retval=(int)ObjectGetInteger(0,Name,OBJPROP_TIME,2);}
	
	else if (Property==OBJPROP_PRICE1)  {retval=ObjectGetDouble(0,Name,OBJPROP_PRICE,0);}
	else if (Property==OBJPROP_PRICE2)  {retval=ObjectGetDouble(0,Name,OBJPROP_PRICE,1);}
	else if (Property==OBJPROP_PRICE3)  {retval=ObjectGetDouble(0,Name,OBJPROP_PRICE,2);}
	
	else if (Property==OBJPROP_BARSHIFT1) {retval=iBarShift(Symbol(), Period(), (int)ObjectGetInteger(0,Name,OBJPROP_TIME,0), true); if (retval==-1) {SkipThePass(true);}}
	else if (Property==OBJPROP_BARSHIFT2) {retval=iBarShift(Symbol(), Period(), (int)ObjectGetInteger(0,Name,OBJPROP_TIME,1), true); if (retval==-1) {SkipThePass(true);}}
	else if (Property==OBJPROP_BARSHIFT3) {retval=iBarShift(Symbol(), Period(), (int)ObjectGetInteger(0,Name,OBJPROP_TIME,2), true); if (retval==-1) {SkipThePass(true);}}
	
	else if (Property==OBJPROP_COLOR)      {retval=(int)ObjectGetInteger(0,Name,OBJPROP_COLOR);}
	else if (Property==OBJPROP_STYLE)      {retval=(int)ObjectGetInteger(0,Name,OBJPROP_STYLE);}
	else if (Property==OBJPROP_WIDTH)      {retval=(int)ObjectGetInteger(0,Name,OBJPROP_WIDTH);}
	else if (Property==OBJPROP_BACK)       {retval=(int)ObjectGetInteger(0,Name,OBJPROP_BACK);}
	else if (Property==OBJPROP_RAY_LEFT)   {retval=(int)ObjectGetInteger(0,Name,OBJPROP_RAY_LEFT);}
	else if (Property==OBJPROP_RAY_RIGHT)  {retval=(int)ObjectGetInteger(0,Name,OBJPROP_RAY_RIGHT);}
	else if (Property==OBJPROP_RAY)        {retval=(int)ObjectGetInteger(0,Name,OBJPROP_RAY);}
	else if (Property==OBJPROP_ELLIPSE)    {retval=(int)ObjectGetInteger(0,Name,OBJPROP_ELLIPSE);}
	else if (Property==OBJPROP_ARROWCODE)  {retval=(int)ObjectGetInteger(0,Name,OBJPROP_ARROWCODE);}
	else if (Property==OBJPROP_FONTSIZE)   {retval=(int)ObjectGetInteger(0,Name,OBJPROP_FONTSIZE);}
	else if (Property==OBJPROP_CORNER)     {retval=(int)ObjectGetInteger(0,Name,OBJPROP_CORNER);}
	else if (Property==OBJPROP_XDISTANCE)  {retval=(int)ObjectGetInteger(0,Name,OBJPROP_XDISTANCE);}
	else if (Property==OBJPROP_YDISTANCE)  {retval=(int)ObjectGetInteger(0,Name,OBJPROP_YDISTANCE);}
	else if (Property==OBJPROP_LEVELCOLOR) {retval=(int)ObjectGetInteger(0,Name,OBJPROP_LEVELCOLOR);}
	else if (Property==OBJPROP_LEVELSTYLE) {retval=(int)ObjectGetInteger(0,Name,OBJPROP_LEVELSTYLE);}
	else if (Property==OBJPROP_LEVELWIDTH) {retval=(int)ObjectGetInteger(0,Name,OBJPROP_LEVELWIDTH);}
	else if (Property==OBJPROP_ANCHOR)     {retval=(int)ObjectGetInteger(0,Name,OBJPROP_ANCHOR);}
	else if (Property==OBJPROP_DIRECTION)  {retval=(int)ObjectGetInteger(0,Name,OBJPROP_DIRECTION);}
	else if (Property==OBJPROP_DEGREE)     {retval=(int)ObjectGetInteger(0,Name,OBJPROP_DEGREE);}
	else if (Property==OBJPROP_DRAWLINES)  {retval=(int)ObjectGetInteger(0,Name,OBJPROP_DRAWLINES);}
	else if (Property==OBJPROP_STATE)      {retval=(int)ObjectGetInteger(0,Name,OBJPROP_STATE);}
	else if (Property==OBJPROP_XSIZE)      {retval=(int)ObjectGetInteger(0,Name,OBJPROP_XSIZE);}
	else if (Property==OBJPROP_YSIZE)      {retval=(int)ObjectGetInteger(0,Name,OBJPROP_YSIZE);}
	else if (Property==OBJPROP_PERIOD)     {retval=(int)ObjectGetInteger(0,Name,OBJPROP_PERIOD);}
	else if (Property==OBJPROP_LEVELS)     {retval=(int)ObjectGetInteger(0,Name,OBJPROP_LEVELS);}
	
	else if (Property==OBJPROP_ANGLE)      {retval=ObjectGetDouble(0,Name,OBJPROP_ANGLE);}
	else if (Property==OBJPROP_SCALE)      {retval=ObjectGetDouble(0,Name,OBJPROP_SCALE);}
	else if (Property==OBJPROP_DEVIATION)  {retval=ObjectGetDouble(0,Name,OBJPROP_DEVIATION);}
	
	else if (Property==OBJPROP_FIRSTLEVEL) {retval=ObjectGetDouble(0,Name,OBJPROP_LEVELVALUE,FiboLevelID);}
	else if (Property==OBJPROP_TL_PRICE_BY_SHIFT) {SHIFT=SHIFT+IndicatorMoreShift();retval=ObjectGetValueByShift(Name,SHIFT);}
	else if (Property==OBJPROP_TL_SHIFT_BY_PRICE) {retval=ObjectGetShiftByValue(Name,TLpriceLevel);}
	
	else if (Property==OBJPROP_FIBOVALUE) {
		Fibo100  =ObjectGetDouble(0,Name,OBJPROP_PRICE,0);
		Fibo0    =ObjectGetDouble(0,Name,OBJPROP_PRICE,1);
		FiboDiff =Fibo100-Fibo0;
		retval=0;
		if (FiboDiff!=0) {retval=(SymbolInfoDouble(Symbol(),SYMBOL_BID)-Fibo0)/(FiboDiff);}
	}
	else if (Property==OBJPROP_FIBOPRICEVALUE) {
		Fibo100  =ObjectGetDouble(0,Name,OBJPROP_PRICE,0);
		Fibo0    =ObjectGetDouble(0,Name,OBJPROP_PRICE,1);
		FiboDiff =Fibo100-Fibo0;
		retval=(ObjectGetDouble(0,Name,OBJPROP_LEVELVALUE,FiboLevelID)*(FiboDiff))+Fibo0;
	}
	
	return(retval);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #39 (Formula&nbsp;) //
void block39(int _parent_=0)
{
	if (block39==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=39;

	double Lo=_iATR(atrPeriod, CurrentSymbol(), PERIOD_H1, 1);
	if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	
	double Ro=_value(3);
	if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	
	atr2=(Lo * Ro);
	
	block38(39);
}
double _iATR(int ATRperiod, string SYMBOL, ENUM_TIMEFRAMES TIMEFRAME, int SHIFT) {
	SHIFT=SHIFT+IndicatorMoreShift();
	double retval=IndicatorGetValue(iATR(SYMBOL,TIMEFRAME,ATRperiod),0,SHIFT);
	SetLastIndicatorData(retval,SYMBOL,TIMEFRAME,SHIFT);
	return(retval);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #48 (Draw Line&nbsp;) //
void block48(int _parent_=0)
{
	if (block48==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=48;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="FALL1"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrRed; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","48","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorH, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 5, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=(_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, anchorH)+atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=(_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5)+atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	block67(48);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #55 (PASS THESE FIRST) //
void block55(int _parent_=0)
{
	if (block55==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=55;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block39(55);}
	block48(55);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #57 (Draw Line&nbsp;) //
void block57(int _parent_=0)
{
	if (block57==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=57;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="RISE2"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrDeepSkyBlue; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","57","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorL, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 1, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=_OBJECT("name", "RISEC", OBJPROP_PRICE1, 0, 1.2, 0); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=_OBJECT("name", "RISEC", OBJPROP_PRICE2, 0, 1.2, 0); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #67 (Draw Line&nbsp;) //
void block67(int _parent_=0)
{
	if (block67==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=67;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="RISE3"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrDeepSkyBlue; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","67","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorL, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 5, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=(_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, anchorL)-atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=(_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5)-atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	block123(67);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #74 (Condition) //
void block74(int _parent_=0)
{
	if (block74==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=74;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iClose", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "FALL1", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block75(74);} else if (o2==true) {block143(74);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #75 (Modify Variables&nbsp;) //
void block75(int _parent_=0)
{
	if (block75==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=75;

	outsideFALL=(_value(outsideFALL)+1);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	block78(75);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #76 (Modify Variables&nbsp;) //
void block76(int _parent_=0)
{
	if (block76==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=76;

	outsideFALL=(_value(outsideFALL)-1);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	block77(76);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #77 (Condition) //
void block77(int _parent_=0)
{
	if (block77==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=77;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(outsideFALL);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		outsideFALL=1;
		// (finish)
	
	/* Orange output */} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #78 (Condition) //
void block78(int _parent_=0)
{
	if (block78==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=78;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(outsideFALL);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(escapeBars);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block94(78);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #79 (NEW ANCHOR) //
void block79(int _parent_=0)
{
	if (block79==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=79;

	anchorH=_value(confirmedHAGE);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #80 (PASS THESE FIRST) //
void block80(int _parent_=0)
{
	if (block80==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=80;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block97(80);}
	block32(80);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #81 (Condition) //
void block81(int _parent_=0)
{
	if (block81==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=81;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iClose", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "RISE1", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block82(81);} else if (o2==true) {block144(81);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #82 (Modify Variables&nbsp;) //
void block82(int _parent_=0)
{
	if (block82==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=82;

	outsideRISE=(_value(outsideRISE)+1);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	block85(82);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #83 (Modify Variables&nbsp;) //
void block83(int _parent_=0)
{
	if (block83==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=83;

	outsideRISE=(_value(outsideRISE)-1);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	block84(83);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #84 (Condition) //
void block84(int _parent_=0)
{
	if (block84==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=84;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(outsideRISE);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		outsideRISE=1;
		// (finish)
	
	/* Orange output */} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #85 (Condition) //
void block85(int _parent_=0)
{
	if (block85==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=85;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(outsideRISE);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(escapeBars);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block95(85);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #86 (NEW ANCHOR) //
void block86(int _parent_=0)
{
	if (block86==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=86;

	anchorL=_value(confirmedLAGE);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #92 (Modify Variables) //
void block92(int _parent_=0)
{
	if (block92==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=92;

	intraBar=(_value(intraBar)+1);
	checkbars=(_value(checkbars)+1);
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	block111(92);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #94 (Condition) //
void block94(int _parent_=0)
{
	if (block94==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=94;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(confirmedHAGE);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(minAnchor);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block79(94);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #95 (Condition) //
void block95(int _parent_=0)
{
	if (block95==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=95;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(confirmedLAGE);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(minAnchor);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block86(95);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #97 (Condition) //
void block97(int _parent_=0)
{
	if (block97==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=97;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(intraBar);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(2);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block74(97); block81(97);} else if (o2==true) {block145(97);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #99 (Custom MQL5 code) //
void block99(int _parent_=0)
{
	if (block99==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=99;

	ChartRedraw( );
	block121(99); block146(99); block147(99);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #100 (Condition&nbsp;) //
void block100(int _parent_=0)
{
	if (block100==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=100;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_OBJECT("name", "RISEC", OBJPROP_PRICE1, 0, 1.2, 0);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(anchorLregL);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block102(100);} else if (o2==true) {
	
		// (adjust) Variables
		checkbars=0;
		// (finish)
	
	block101(100);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #101 (Modify Variables) //
void block101(int _parent_=0)
{
	if (block101==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=101;

	anchorLregL=_OBJECT("name", "RISEC", OBJPROP_PRICE1, 0, 1.2, 0);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #102 (Condition&nbsp;) //
void block102(int _parent_=0)
{
	if (block102==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=102;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_OBJECT("name", "FALLC", OBJPROP_PRICE1, 0, 1.2, 0);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(anchorHregL);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block106(102);} else if (o2==true) {
	
		// (adjust) Variables
		checkbars=0;
		// (finish)
	
	block103(102);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #103 (Modify Variables) //
void block103(int _parent_=0)
{
	if (block103==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=103;

	anchorHregL=_OBJECT("name", "FALLC", OBJPROP_PRICE1, 0, 1.2, 0);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #104 (Condition) //
void block104(int _parent_=0)
{
	if (block104==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=104;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(checkbars);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(surebars);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		dayDrawn=1;
		// (finish)
	
	block55(104);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #105 (PASS THESE FIRST) //
void block105(int _parent_=0)
{
	if (block105==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=105;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block110(105);}
	/* Yellow output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #106 (Condition&nbsp;) //
void block106(int _parent_=0)
{
	if (block106==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=106;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_OBJECT("name", "RISEC", OBJPROP_PRICE2, 0, 1.2, 0);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(anchorHregL2);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block108(106);} else if (o2==true) {
	
		// (adjust) Variables
		checkbars=0;
		// (finish)
	
	block107(106);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #107 (Modify Variables) //
void block107(int _parent_=0)
{
	if (block107==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=107;

	anchorHregL2=_OBJECT("name", "RISEC", OBJPROP_PRICE2, 0, 1.2, 0);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #108 (Condition&nbsp;) //
void block108(int _parent_=0)
{
	if (block108==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=108;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_OBJECT("name", "FALLC", OBJPROP_PRICE2, 0, 1.2, 0);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(anchorLregL2);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block104(108);} else if (o2==true) {
	
		// (adjust) Variables
		checkbars=0;
		// (finish)
	
	block109(108);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #109 (Modify Variables) //
void block109(int _parent_=0)
{
	if (block109==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=109;

	anchorLregL2=_OBJECT("name", "FALLC", OBJPROP_PRICE2, 0, 1.2, 0);
	// Variable2 is not selected =;
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #110 (Condition&nbsp;) //
void block110(int _parent_=0)
{
	if (block110==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=110;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(dayDrawn);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(0);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block100(110);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #111 (PASS THESE FIRST) //
void block111(int _parent_=0)
{
	if (block111==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=111;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block112(111);}
	block23(111);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #112 (Condition) //
void block112(int _parent_=0)
{
	if (block112==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=112;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(correctDrawn);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(0);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block113(112);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #113 (Condition) //
void block113(int _parent_=0)
{
	if (block113==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=113;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(dayDrawn);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block114(113);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #114 (Formula) //
void block114(int _parent_=0)
{
	if (block114==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=114;

	double Lo=_OBJECT("name", "RISE3", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	
	double Ro=_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	
	check1=(Lo - Ro);
	
	block115(114);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #115 (Formula) //
void block115(int _parent_=0)
{
	if (block115==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=115;

	double Lo=_OBJECT("name", "RISE3", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 3);
	if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	
	double Ro=_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 3);
	if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	
	check2=(Lo - Ro);
	
	block116(115);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #116 (Formula) //
void block116(int _parent_=0)
{
	if (block116==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=116;

	double Lo=_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	
	double Ro=_OBJECT("name", "FALL1", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	
	check3=(Lo - Ro);
	
	block117(116);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #117 (Formula) //
void block117(int _parent_=0)
{
	if (block117==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=117;

	double Lo=_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 3);
	if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	
	double Ro=_OBJECT("name", "FALL1", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 3);
	if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	
	check4=(Lo - Ro);
	
	block118(117);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #118 (Condition) //
void block118(int _parent_=0)
{
	if (block118==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=118;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_fResults(check1);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_fResults(check2);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block119(118);} else if (o2==true) {block120(118);}
}
double _fResults(double fResult) {
	return((double)fResult);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #119 (Condition) //
void block119(int _parent_=0)
{
	if (block119==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=119;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_fResults(check3);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_fResults(check4);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		correctDrawn=1;
		// (finish)
	
	/* Orange output */} else if (o2==true) {block120(119);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #120 (Pass) //
void block120(int _parent_=0)
{
	if (block120==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=120;

	
	
		// (adjust) Variables
		dayDrawn=0;
		correctDrawn=0;
		// (finish)
	
	block104(120);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #121 (Comment) //
void block121(int _parent_=0)
{
	if (block121==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=121;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string Title="Comment Message"; // Comment
	string ObjChartSubWindow=""; // Chart Sub-Window
	int ObjCorner=CORNER_LEFT_UPPER; // Corner
	int ObjX=5; // X coordinate
	int ObjY=24; // Y coordinate
	int ObjFontSize=10; // Font size
	string Label1="riseEFF"; // Label 1
	string Label2="fallEFF"; // Label 2
	string Label3="rise"; // Label 3
	string Label4="fall"; // Label 4
	string Label5=""; // Label 5
	string Label6=""; // Label 6
	string Label7=""; // Label 7
	string Label8=""; // Label 8
	
	///////////////
	// Main code //
	///////////////
	
	if (!MQLInfoInteger(MQL_TESTER) || MQLInfoInteger(MQL_VISUAL_MODE))
	{
	   static bool initialized = false;
	   long ObjChartID   = 0;
	   
	   int ObjAnchor     = ANCHOR_LEFT;
	   if (ObjCorner == CORNER_RIGHT_UPPER || ObjCorner == CORNER_RIGHT_LOWER)
	   {
	      ObjAnchor     = ANCHOR_RIGHT;
	   }
	
	   string namebase = "fxd_cmnt_"+"121";
	   
	   int subwindow = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	   if (subwindow >= 0)
	   {
	      //-- draw comment title
	      if ((string)Title != "")
	      {
	         string nametitle = namebase;
	         if(ObjectFind(ObjChartID,nametitle) < 0)
	         {
	            if (!ObjectCreate(ObjChartID,nametitle,OBJ_LABEL,subwindow,0,0,0,0))
	            {
	               Print(__FUNCTION__,": failed to create text object! Error code = ",GetLastError());
	            }
	            else
	            {
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_FONTSIZE,(int)(ObjFontSize*1.3));
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_COLOR,clrGold);
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_BACK,0);
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_SELECTABLE,1);
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_SELECTED,0);
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_HIDDEN,1);
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_CORNER,ObjCorner);
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_ANCHOR,ObjAnchor);
	               
	               ObjectSetString(ObjChartID,nametitle,OBJPROP_FONT,"Georgia");
	               
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_XDISTANCE,ObjX);
	               ObjectSetInteger(ObjChartID,nametitle,OBJPROP_YDISTANCE,ObjY);
	            }
	         }
	         else
	         {
	            ObjX = (int)ObjectGetInteger(ObjChartID, nametitle, OBJPROP_XDISTANCE);
	            ObjY = (int)ObjectGetInteger(ObjChartID, nametitle, OBJPROP_YDISTANCE);
	         }
	         
	         
	         ObjectSetString(ObjChartID,nametitle,OBJPROP_TEXT,(string)Title);
	         
	         ObjY = (int)(ObjY+ObjFontSize*1.3/3);
	      }
	      
	      //-- draw comment rows
	      for (int i=1; i<=8; i++)
	      {
	         string text="";
	         string textlbl="";
	         
	         switch(i)
	         {
	            case 1: if (Label1 != "") { textlbl = Label1; text = (string)_text(outsideRISE); } break;
	            case 2: if (Label2 != "") { textlbl = Label2; text = (string)_text(outsideFALL); } break;
	            case 3: if (Label3 != "") { textlbl = Label3; text = (string)_text(actualRise); } break;
	            case 4: if (Label4 != "") { textlbl = Label4; text = (string)_text(actualFall); } break;
	            case 5: if (Label5 != "") { textlbl = Label5; text = (string)_text(""); } break;
	            case 6: if (Label6 != "") { textlbl = Label6; text = (string)_text(""); } break;
	            case 7: if (Label7 != "") { textlbl = Label7; text = (string)_text(""); } break;
	            case 8: if (Label8 != "") { textlbl = Label8; text = (string)_text(""); } break;
	         }
	         
	         string name    = namebase+"_"+(string)i;
	         string namelbl = name+"_l";
	
	         if (textlbl == "")
	         {
	            if (!initialized)
	            {
	               //-- pre-delete
	               ObjectDelete(ObjChartID,namelbl);
	               ObjectDelete(ObjChartID,name);   
	            }
	            
	            continue;
	         }
	
	         //-- draw initial objects
	         if(ObjectFind(ObjChartID, name) < 0)
	         {
	            if (textlbl == "")
	            {
	               continue;
	            }
	            
	            if (ObjectCreate(ObjChartID,namelbl,OBJ_LABEL,subwindow,0,0,0,0))
	            {
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_CORNER,ObjCorner);
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_ANCHOR,ObjAnchor);
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_BACK,0);
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_SELECTABLE,0);
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_SELECTED,0);
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_HIDDEN,1);
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_FONTSIZE,ObjFontSize);
	               ObjectSetInteger(ObjChartID,namelbl,OBJPROP_COLOR,clrDarkGray);
	               ObjectSetString(ObjChartID,namelbl,OBJPROP_FONT,"Verdana");
	            }
	            else
	            {
	               Print(__FUNCTION__,": failed to create text object! Error code = ",GetLastError());
	            }
	            
	            if (ObjectCreate(ObjChartID,name,OBJ_LABEL,subwindow,0,0,0,0))
	            {
	               ObjectSetInteger(ObjChartID,name,OBJPROP_CORNER,ObjCorner);
	               ObjectSetInteger(ObjChartID,name,OBJPROP_ANCHOR,ObjAnchor);
	               ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,0);
	               ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,0);
	               ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,0);
	               ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,1);
	               ObjectSetInteger(ObjChartID,name,OBJPROP_FONTSIZE,ObjFontSize);
	               ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,clrWhite);
	               ObjectSetString(ObjChartID,name,OBJPROP_FONT,"Verdana");
	            }
	            else
	            {
	               Print(__FUNCTION__,": failed to create text object! Error code = ",GetLastError());
	            }
	         }
	         else
	         {
	            if (textlbl == "")
	            {
	               ObjectDelete(ObjChartID,namelbl);
	               ObjectDelete(ObjChartID,name);
	               continue;
	            }
	         }
	         
	         ObjY  = (int)(ObjY + ObjFontSize + ObjFontSize/2);
	         
	         //-- update label objects
	         ObjectSetInteger(ObjChartID,namelbl,OBJPROP_XDISTANCE,ObjX);
	         ObjectSetInteger(ObjChartID,namelbl,OBJPROP_YDISTANCE,ObjY);
	         ObjectSetString(ObjChartID,namelbl,OBJPROP_TEXT,(string)textlbl);
	         
	         //-- update value objects
	         int x=0;
	         int xsizelbl = (int)ObjectGetInteger(ObjChartID, namelbl, OBJPROP_XSIZE);
	         
	         if (xsizelbl == 0) {
	            //-- when the object is newly created, it returns 0 for XSIZE and YSIZE, so here we will trick it somehow
	            xsizelbl = (int)(StringLen((string)textlbl)*ObjFontSize/1.5 + ObjFontSize/2);
	         }
	         
	         x = ObjX+(xsizelbl + ObjFontSize/2);
	         
	         ObjectSetInteger(ObjChartID,name,OBJPROP_XDISTANCE,x);
	         ObjectSetInteger(ObjChartID,name,OBJPROP_YDISTANCE,ObjY);
	         ObjectSetString(ObjChartID,name,OBJPROP_TEXT,(string)text);
	      }
	   }
	   initialized = true;
	}
	
	/* Orange output */
}
string _text(string Text) {
	return(Text);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #122 (PASS THESE FIRST) //
void block122(int _parent_=0)
{
	if (block122==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=122;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block92(122);}
	block148(122);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #123 (Draw Line&nbsp;) //
void block123(int _parent_=0)
{
	if (block123==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=123;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="FALL3"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrRed; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","123","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorH, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 5, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=(_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, anchorH)-atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=(_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5)-atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	block142(123);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #142 (Draw Line&nbsp;) //
void block142(int _parent_=0)
{
	if (block142==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=142;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="RISE1"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrDeepSkyBlue; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_SOLID; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","142","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorL, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 5, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=(_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, anchorL)+atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=(_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5)+atr2); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	block171(142);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #143 (Condition) //
void block143(int _parent_=0)
{
	if (block143==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=143;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iClose", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "FALL3", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block75(143);} else if (o2==true) {block76(143);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #144 (Condition) //
void block144(int _parent_=0)
{
	if (block144==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=144;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iClose", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "RISE3", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block82(144);} else if (o2==true) {block83(144);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #145 (Modify Variables&nbsp;) //
void block145(int _parent_=0)
{
	if (block145==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=145;

	outsideFALL=(_value(outsideFALL)-2);
	outsideRISE=(_value(outsideRISE)-2);
	// Variable3 is not selected =;
	// Variable4 is not selected =;
	// Variable5 is not selected =;
	
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #146 (Condition&nbsp;) //
void block146(int _parent_=0)
{
	if (block146==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=146;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 3);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		actualRise=1;
		// (finish)
	
	/* Orange output */} else if (o2==true) {
	
		// (adjust) Variables
		actualRise=0;
		// (finish)
	
	/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #147 (Condition&nbsp;) //
void block147(int _parent_=0)
{
	if (block147==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=147;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 3);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		actualFall=1;
		// (finish)
	
	/* Orange output */} else if (o2==true) {
	
		// (adjust) Variables
		actualFall=0;
		// (finish)
	
	/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #148 (PASS THESE FIRST) //
void block148(int _parent_=0)
{
	if (block148==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=148;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block99(148);}
	block149(148);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #149 (TRADE) //
void block149(int _parent_=0)
{
	if (block149==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=149;

	block151(149);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #150 (Condition) //
void block150(int _parent_=0)
{
	if (block150==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=150;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_iRSI(rsi, PRICE_CLOSE, CurrentSymbol(), CurrentTimeframe(), 1);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(50);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		trUp=1;
		// (finish)
	
	/* Orange output */} else if (o2==true) {
	
		// (adjust) Variables
		trDn=1;
		// (finish)
	
	/* Yellow output */}
}
double _iRSI(int RSIperiod, int AppliedPrice, string SYMBOL, ENUM_TIMEFRAMES TIMEFRAME, int SHIFT) {
	SHIFT=SHIFT+IndicatorMoreShift();
	double retval=IndicatorGetValue(iRSI(SYMBOL,TIMEFRAME,RSIperiod,AppliedPrice),0,SHIFT);
	SetLastIndicatorData(retval,SYMBOL,TIMEFRAME,SHIFT);
	return(retval);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #151 (PASS THESE FIRST) //
void block151(int _parent_=0)
{
	if (block151==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=151;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	int Cycles=1; // Cycles
	
	///////////////
	// Main code //
	///////////////
	
	for (int i=1; i<=Cycles; i++) {block150(151);}
	block152(151); block153(151);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #152 (REAL RISE) //
void block152(int _parent_=0)
{
	if (block152==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=152;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(actualRise);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block154(152);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #153 (REAL FALL) //
void block153(int _parent_=0)
{
	if (block153==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=153;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(actualFall);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block155(153);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #154 (QUALITY CHECK) //
void block154(int _parent_=0)
{
	if (block154==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=154;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(outsideRISE);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(tradeQuality);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<=Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<=Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block156(154); block191(154);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #155 (QUALITY CHECK) //
void block155(int _parent_=0)
{
	if (block155==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=155;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(outsideFALL);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(tradeQuality);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<=Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<=Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block163(155); block194(155);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #156 (Condition) //
void block156(int _parent_=0)
{
	if (block156==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=156;

	int crossover=1;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_iRSI(rsi, PRICE_CLOSE, CurrentSymbol(), CurrentTimeframe(), 1);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(30);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block157(156);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #157 (Condition) //
void block157(int _parent_=0)
{
	if (block157==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=157;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iMedian", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block160(157);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #158 (Condition) //
void block158(int _parent_=0)
{
	if (block158==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=158;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iMedian", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "RISE3", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block161(158);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #159 (BuyRun) //
void block159(int _parent_=0)
{
	if (block159==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=159;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string OrdersScope="all"; // Group mode
	string OrdersGroup=""; // Group # (empty=Default)
	string SymbolScope="symbol"; // Market mode
	string SYMBOL=CurrentSymbol(); // Market
	string BuysOrSells="buys"; // Filter by type
	
	///////////////
	// Main code //
	///////////////
	
	bool exist=false;
	for (int pos=PositionsTotal()-1; pos>=0; pos--) {
	   if (LoadOrder(PositionGetSymbol(pos))) {
	      if (FilterOrderBy(OrdersScope,OrdersGroup, SymbolScope,SYMBOL, BuysOrSells)) {
	         exist=true; break;
	      }
	   }
	}
	
	if (exist==true) {block168(159);} else {block165(159);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #160 (SellRun) //
void block160(int _parent_=0)
{
	if (block160==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=160;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string OrdersScope="all"; // Group mode
	string OrdersGroup=""; // Group # (empty=Default)
	string SymbolScope="symbol"; // Market mode
	string SYMBOL=CurrentSymbol(); // Market
	string BuysOrSells="sells"; // Filter by type
	
	///////////////
	// Main code //
	///////////////
	
	bool exist=false;
	for (int pos=PositionsTotal()-1; pos>=0; pos--) {
	   if (LoadOrder(PositionGetSymbol(pos))) {
	      if (FilterOrderBy(OrdersScope,OrdersGroup, SymbolScope,SYMBOL, BuysOrSells)) {
	         exist=true; break;
	      }
	   }
	}
	
	if (exist==true) {block161(160);} else {block158(160);}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #161 (GA &nbsp; &nbsp;TE) //
void block161(int _parent_=0)
{
	if (block161==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=161;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(trUp);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		trUp=0;
		// (finish)
	
	block162(161);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #162 (Buy now) //
void block162(int _parent_=0)
{
	if (block162==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=162;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string OrdersGroup=""; // Group # (empty=Default)
	string SYMBOL=CurrentSymbol(); // Market
	string VolumeMode="fixed"; // Money management
	double VolumeSize=0.01; // Lot size
	double VolumeSizeRisk=50; // Amount of money to risk
	double VolumeRisk=2.5; // Risk percent
	double VolumePercent=100; // Volume size
	double VolumeBlockPercent=3; // Block % of Balance
	double FixedRatioUnitSize=0.01; // Fixed Ratio: Unit size
	double FixedRatioDelta=20; // Fixed Ratio: Delta parameter
	double mmMgInitialLots=0.1; // Initial volume
	double mmMgMultiplyOnLoss=2; // Multiply on loss
	double mmMgMultiplyOnProfit=1; // Multiply on profit
	double mmMgAddLotsOnLoss=0; // Add lots on loss
	double mmMgAddLotsOnProfit=0; // Add lots on profit
	int mmMgResetOnLoss=0; // Reset after how many losses?
	int mmMgResetOnProfit=1; // Reset after how many profits?
	double mm1326InitialLots=0.1; // Initial volume
	bool mm1326Reverse=false; // Reverse 1-3-2-6?
	double mmFiboInitialLots=0.1; // Initial volume
	double mmDalembertInitialLots=0.1; // Initial volume
	bool mmDalembertReverse=false; // Reverse D'Alembert
	double mmLabouchereInitialLots=0.1; // Initial volume
	string mmLabouchereList="1,2,3,4,5,6"; // List of numbers
	bool mmLabouchereReverse=false; // Reverse Labouchere
	double mmSeqBaseLots=0.1; // Base volume
	string mmSeqOnLoss="3,2,6"; // Sequence on loss
	string mmSeqOnProfit="1"; // Sequence on profit
	double mmSeqReverse=false; // Reverse system?
	double VolumeUpperLimit=0; // Volume upper limit
	string StopLossMode="none"; // Stop-Loss mode
	double StopLossPips=100; // in pips...
	double StopLossPercentTP=100; // % of Take-Profit
	string TakeProfitMode="none"; // Take-Profit mode
	double TakeProfitPips=100; // in pips...
	double TakeProfitPercentSL=100; // % of Stop-Loss
	double Slippage=4; // Slippage
	string MyComment="Long position"; // Comment
	
	///////////////
	// Main code //
	///////////////
	
	SetSymbol(SYMBOL);
	
	//-- stops ------------------------------------------------------------------
	double sll=0, slp=0, tpl=0, tpp=0;
	
	     if (StopLossMode=="fixed")        {slp=StopLossPips;}
	else if (StopLossMode=="dynamicPips")  {slp=_value(100);}
	else if (StopLossMode=="dynamicDigits"){slp=toPips(_value(0.0100),SYMBOL);}
	else if (StopLossMode=="dynamicLevel") {sll=_value(1);}
	
	     if (TakeProfitMode=="fixed")         {tpp=TakeProfitPips;}
	else if (TakeProfitMode=="dynamicPips")   {tpp=_value(100);}
	else if (TakeProfitMode=="dynamicDigits") {tpp=toPips(_value(0.0100),SYMBOL);}
	else if (TakeProfitMode=="dynamicLevel")  {tpl=_value(1);}
	
	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;}
	}
	
	//-- lots -------------------------------------------------------------------
	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)));
	
	     if (VolumeMode=="fixed")             {lots=DynamicLots(VolumeMode, VolumeSize);}
	else if (VolumeMode=="block-equity")      {lots=DynamicLots(VolumeMode, VolumeBlockPercent);}
	else if (VolumeMode=="block-balance")     {lots=DynamicLots(VolumeMode, VolumeBlockPercent);}
	else if (VolumeMode=="block-freemargin")  {lots=DynamicLots(VolumeMode, VolumeBlockPercent);}
	else if (VolumeMode=="equity")            {lots=DynamicLots(VolumeMode, VolumePercent);}
	else if (VolumeMode=="balance")           {lots=DynamicLots(VolumeMode, VolumePercent);}
	else if (VolumeMode=="freemargin")        {lots=DynamicLots(VolumeMode, VolumePercent);}
	else if (VolumeMode=="equityRisk")        {lots=DynamicLots(VolumeMode, VolumeRisk, pre_sl_pips);}
	else if (VolumeMode=="balanceRisk")       {lots=DynamicLots(VolumeMode, VolumeRisk, pre_sl_pips);}
	else if (VolumeMode=="freemarginRisk")    {lots=DynamicLots(VolumeMode, VolumeRisk, pre_sl_pips);}
	else if (VolumeMode=="fixedRisk")         {lots=DynamicLots(VolumeMode, VolumeSizeRisk, pre_sl_pips);}
	else if (VolumeMode=="fixedRatio")        {lots=DynamicLots(VolumeMode, FixedRatioUnitSize, FixedRatioDelta);}
	else if (VolumeMode=="dynamic")           {lots=AlignLots(_value(0.1));}
	else if (VolumeMode=="1326")              {lots=Bet1326(OrdersGroup, SYMBOL, mm1326InitialLots, mm1326Reverse);}
	else if (VolumeMode=="fibonacci")         {lots=BetFibonacci(OrdersGroup, SYMBOL, mmFiboInitialLots);}
	else if (VolumeMode=="dalembert")         {lots=BetDalembert(OrdersGroup, SYMBOL, mmDalembertInitialLots, mmDalembertReverse);}
	else if (VolumeMode=="labouchere")        {lots=BetLabouchere(OrdersGroup, SYMBOL, mmLabouchereInitialLots, mmLabouchereList, mmLabouchereReverse);}
	else if (VolumeMode=="martingale")        {lots=BetMartingale(OrdersGroup, SYMBOL, mmMgInitialLots, mmMgMultiplyOnLoss, mmMgMultiplyOnProfit, mmMgAddLotsOnLoss, mmMgAddLotsOnProfit, mmMgResetOnLoss, mmMgResetOnProfit);}
	else if (VolumeMode=="sequence")          {lots=BetSequence(OrdersGroup, SYMBOL, mmSeqBaseLots, mmSeqOnLoss, mmSeqOnProfit, mmSeqReverse);}
	
	lots = AlignLots(lots, 0, VolumeUpperLimit);
	
	//-- send -------------------------------------------------------------------
	bool success=BuyNow(SYMBOL, lots, sll, tpl, slp, tpp, Slippage, (MagicStart+(int)OrdersGroup), MyComment);
	
	if (success>0) {/* Orange output */} else {/* Gray output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #163 (Condition) //
void block163(int _parent_=0)
{
	if (block163==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=163;

	int crossover=1;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_iRSI(rsi, PRICE_CLOSE, CurrentSymbol(), CurrentTimeframe(), 1);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(70);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block164(163);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #164 (Condition) //
void block164(int _parent_=0)
{
	if (block164==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=164;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iMedian", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block159(164);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #165 (Condition) //
void block165(int _parent_=0)
{
	if (block165==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=165;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iMedian", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "FALL1", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block168(165);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #168 (GA &nbsp; &nbsp;TE) //
void block168(int _parent_=0)
{
	if (block168==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=168;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_value(trDn);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo==Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro==Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {
	
		// (adjust) Variables
		trDn=0;
		// (finish)
	
	block169(168);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #169 (Sell now) //
void block169(int _parent_=0)
{
	if (block169==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=169;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string OrdersGroup=""; // Group # (empty=Default)
	string SYMBOL=CurrentSymbol(); // Market
	string VolumeMode="fixed"; // Money management
	double VolumeSize=0.01; // Lot size
	double VolumeSizeRisk=50; // Amount of money to risk
	double VolumeRisk=2.5; // Risk percent
	double VolumePercent=100; // Volume size
	double VolumeBlockPercent=3; // Block % of Balance
	double FixedRatioUnitSize=0.01; // Fixed Ratio: Unit size
	double FixedRatioDelta=20; // Fixed Ratio: Delta parameter
	double mmMgInitialLots=0.1; // Initial volume
	double mmMgMultiplyOnLoss=2; // Multiply on loss
	double mmMgMultiplyOnProfit=1; // Multiply on profit
	double mmMgAddLotsOnLoss=0; // Add lots on loss
	double mmMgAddLotsOnProfit=0; // Add lots on profit
	int mmMgResetOnLoss=0; // Reset after how many losses?
	int mmMgResetOnProfit=1; // Reset after how many profits?
	double mm1326InitialLots=0.1; // Initial volume
	bool mm1326Reverse=false; // Reverse 1-3-2-6?
	double mmFiboInitialLots=0.1; // Initial volume
	double mmDalembertInitialLots=0.1; // Initial volume
	bool mmDalembertReverse=false; // Reverse D'Alembert
	double mmLabouchereInitialLots=0.1; // Initial volume
	string mmLabouchereList="1,2,3,4,5,6"; // List of numbers
	bool mmLabouchereReverse=false; // Reverse Labouchere
	double mmSeqBaseLots=0.1; // Base volume
	string mmSeqOnLoss="3,2,6"; // Sequence on loss
	string mmSeqOnProfit="1"; // Sequence on profit
	bool mmSeqReverse=false; // Reverse system?
	double VolumeUpperLimit=0; // Volume upper limit
	string StopLossMode="none"; // Stop-Loss mode
	double StopLossPips=100; // in pips...
	double StopLossPercentTP=100; // % of Take-Profit
	string TakeProfitMode="none"; // Take-Profit mode
	double TakeProfitPips=100; // in pips...
	double TakeProfitPercentSL=100; // % of Stop-Loss
	double Slippage=4; // Slippage
	string MyComment="Short position"; // Comment
	
	///////////////
	// Main code //
	///////////////
	
	SetSymbol(SYMBOL);
	
	//-- stops ------------------------------------------------------------------
	double sll=0, slp=0, tpl=0, tpp=0;
	
	     if (StopLossMode=="fixed")        {slp=StopLossPips;}
	else if (StopLossMode=="dynamicPips")  {slp=_value(100);}
	else if (StopLossMode=="dynamicDigits"){slp=toPips(_value(0.0100),SYMBOL);}
	else if (StopLossMode=="dynamicLevel") {sll=_value(1);}
	
	     if (TakeProfitMode=="fixed")         {tpp=TakeProfitPips;}
	else if (TakeProfitMode=="dynamicPips")   {tpp=_value(100);}
	else if (TakeProfitMode=="dynamicDigits") {tpp=toPips(_value(0.0100),SYMBOL);}
	else if (TakeProfitMode=="dynamicLevel")  {tpl=_value(1);}
	
	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;}
	}
	
	//-- lots -------------------------------------------------------------------
	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));
	
	     if (VolumeMode=="fixed")             {lots=DynamicLots(VolumeMode, VolumeSize);}
	else if (VolumeMode=="block-equity")      {lots=DynamicLots(VolumeMode, VolumeBlockPercent);}
	else if (VolumeMode=="block-balance")     {lots=DynamicLots(VolumeMode, VolumeBlockPercent);}
	else if (VolumeMode=="block-freemargin")  {lots=DynamicLots(VolumeMode, VolumeBlockPercent);}
	else if (VolumeMode=="equity")            {lots=DynamicLots(VolumeMode, VolumePercent);}
	else if (VolumeMode=="balance")           {lots=DynamicLots(VolumeMode, VolumePercent);}
	else if (VolumeMode=="freemargin")        {lots=DynamicLots(VolumeMode, VolumePercent);}
	else if (VolumeMode=="equityRisk")        {lots=DynamicLots(VolumeMode, VolumeRisk, pre_sl_pips);}
	else if (VolumeMode=="balanceRisk")       {lots=DynamicLots(VolumeMode, VolumeRisk, pre_sl_pips);}
	else if (VolumeMode=="freemarginRisk")    {lots=DynamicLots(VolumeMode, VolumeRisk, pre_sl_pips);}
	else if (VolumeMode=="fixedRisk")         {lots=DynamicLots(VolumeMode, VolumeSizeRisk, pre_sl_pips);}
	else if (VolumeMode=="fixedRatio")        {lots=DynamicLots(VolumeMode, FixedRatioUnitSize, FixedRatioDelta);}
	else if (VolumeMode=="dynamic")           {lots=AlignLots(_value(0.1));}
	else if (VolumeMode=="1326")              {lots=Bet1326(OrdersGroup, SYMBOL, mm1326InitialLots, mm1326Reverse);}
	else if (VolumeMode=="fibonacci")         {lots=BetFibonacci(OrdersGroup, SYMBOL, mmFiboInitialLots);}
	else if (VolumeMode=="dalembert")         {lots=BetDalembert(OrdersGroup, SYMBOL, mmDalembertInitialLots, mmDalembertReverse);}
	else if (VolumeMode=="labouchere")        {lots=BetLabouchere(OrdersGroup, SYMBOL, mmLabouchereInitialLots, mmLabouchereList, mmLabouchereReverse);}
	else if (VolumeMode=="martingale")        {lots=BetMartingale(OrdersGroup, SYMBOL, mmMgInitialLots, mmMgMultiplyOnLoss, mmMgMultiplyOnProfit, mmMgAddLotsOnLoss, mmMgAddLotsOnProfit, mmMgResetOnLoss, mmMgResetOnProfit);}
	else if (VolumeMode=="sequence")          {lots=BetSequence(OrdersGroup, SYMBOL, mmSeqBaseLots, mmSeqOnLoss, mmSeqOnProfit, mmSeqReverse);}
	
	lots = AlignLots(lots, 0, VolumeUpperLimit);
	
	//-- send -------------------------------------------------------------------
	bool success=SellNow(SYMBOL, lots, sll, tpl, slp, tpp, Slippage, (MagicStart+(int)OrdersGroup), MyComment);
	
	if (success>0) {/* Orange output */} else {/* Gray output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #171 (Draw Line&nbsp;) //
void block171(int _parent_=0)
{
	if (block171==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=171;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="FALLtgt"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrRed; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_DOT; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","171","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorH, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 5, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=(_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, anchorH)-(atr2*0.5)); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=(_OBJECT("name", "FALL2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5)-(atr2*0.5)); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	block190(171);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #190 (Draw Line&nbsp;) //
void block190(int _parent_=0)
{
	if (block190==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=190;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	bool ObjectPerBar=false; // This block can create 1 object per bar
	bool ObjectUpdate=true; // Redraw the current object
	string ObjName="RISEtgt"; // Object name/prefix (optional)
	int ObjectType=OBJ_TREND; // Object type
	double ObjAngle=45; // Angle
	bool ObjRay=true; // Ray
	bool ObjRayLeft=false; // Ray left
	bool ObjRayRight=true; // Ray right
	color ObjColor=clrDeepSkyBlue; // Color
	ENUM_LINE_STYLE ObjStyle=STYLE_DOT; // Line style
	int ObjWidth=1; // Width
	bool ObjBack=false; // In the background
	bool ObjSelectable=false; // Selectable
	bool ObjSelected=false; // Selected
	bool ObjHidden=false; // Visibility
	int ObjZorder=0; // Z-order
	string ObjChartSubWindow=""; // Chart Sub-Window
	
	///////////////
	// Main code //
	///////////////
	
	long ObjChartID = 0;
	int subwindow_id = WindowFindVisible(ObjChartID, ObjChartSubWindow);
	
	if (subwindow_id >= 0)
	{
	   double p1=0, p2=0;
	   datetime t1=0, t2=0;
	   string name          = "";
	   string name_base     = "";
	   static int count     = 0;
	   static datetime time0= 0;
	   bool get_new_name    = false;
	   bool do_update       = true;
	   
	   if (ObjectPerBar==true) {
	      datetime time=iTime(Symbol(),0,0);
	      if (time0 < time) {
	         time0 = time;
	         get_new_name = true;
	      } else {
	         if (ObjectUpdate==false) {do_update = false;}
	      }
	   }
	   else {
	      if (ObjectUpdate==false) {get_new_name = true;}
	   }
	   
	   if (do_update)
	   {
	      if (ObjName!="") {name_base=ObjName;} else {StringConcatenate(name_base, "fxd_line_","190","_");}
	      if (get_new_name == false) {
	         StringConcatenate(name, name_base,count);
	      } else {
	         while(true) {
	            count++;
	            StringConcatenate(name, name_base,count);
	            if (ObjectFind(ObjChartID,name)<0) {break;}
	         }
	      }
	      if (ObjName!="" && count==0) {name = ObjName;}
	   
	      if(ObjectFind(ObjChartID,name)<0 && !ObjectCreate(ObjChartID,name,(ENUM_OBJECT)ObjectType,subwindow_id,t1,p1,t2,p2))
	      {
	         Print(__FUNCTION__,": failed to create line object! Error code = ",GetLastError());
	      }
	   
	      switch(ObjectType)
	      {
	         case OBJ_VLINE: {t1=1; break;}
	         case OBJ_HLINE: {p1=1; break;}
	         case OBJ_TREND: {t1=1; p1=1; t2=1; p2=1; break;}
	         case OBJ_TRENDBYANGLE: {t1=1; p1=1; break;}
	         case OBJ_CYCLES: {t1=1; p1=1; t2=1; p2=1; break;}
	      }
	      
	      if (t1==1) {t1=_time(3, 0, "00:00", anchorL, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,0,t1);}
	      if (t2==1) {t2=_time(3, 0, "00:00", 5, "", 0, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false); ObjectSetInteger(ObjChartID,name,OBJPROP_TIME,1,t2);}
	      if (p1==1) {p1=(_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, anchorL)+(atr2*0.5)); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,0,p1);}
	      if (p2==1) {p2=(_OBJECT("name", "RISE2", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 5)+(atr2*0.5)); ObjectSetDouble(ObjChartID,name,OBJPROP_PRICE,1,p2);}
	      
	      ObjectSetInteger(ObjChartID,name,OBJPROP_STYLE,ObjStyle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_COLOR,ObjColor);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_BACK,ObjBack);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_WIDTH,ObjWidth);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTABLE,ObjSelectable);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_SELECTED,ObjSelected);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_HIDDEN,ObjHidden);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_ZORDER,ObjZorder);
	      
	      ObjectSetDouble(ObjChartID,name,OBJPROP_ANGLE,ObjAngle);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY,ObjRay);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_LEFT,ObjRayLeft);
	      ObjectSetInteger(ObjChartID,name,OBJPROP_RAY_RIGHT,ObjRayRight);
	      
	      ChartRedraw();
	   }
	}
	/* Orange output */
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #191 (Condition) //
void block191(int _parent_=0)
{
	if (block191==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=191;

	int crossover=1;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_iRSI(rsi, PRICE_CLOSE, CurrentSymbol(), CurrentTimeframe(), 1);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(70);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block192(191);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #192 (Condition) //
void block192(int _parent_=0)
{
	if (block192==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=192;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iMedian", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "RISEtgt", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block193(192);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #193 (BuyRun) //
void block193(int _parent_=0)
{
	if (block193==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=193;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string OrdersScope="all"; // Group mode
	string OrdersGroup=""; // Group # (empty=Default)
	string SymbolScope="symbol"; // Market mode
	string SYMBOL=CurrentSymbol(); // Market
	string BuysOrSells="buys"; // Filter by type
	
	///////////////
	// Main code //
	///////////////
	
	bool exist=false;
	for (int pos=PositionsTotal()-1; pos>=0; pos--) {
	   if (LoadOrder(PositionGetSymbol(pos))) {
	      if (FilterOrderBy(OrdersScope,OrdersGroup, SymbolScope,SYMBOL, BuysOrSells)) {
	         exist=true; break;
	      }
	   }
	}
	
	if (exist==true) {block168(193);} else {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #194 (Condition) //
void block194(int _parent_=0)
{
	if (block194==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=194;

	int crossover=1;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_iRSI(rsi, PRICE_CLOSE, CurrentSymbol(), CurrentTimeframe(), 1);
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_value(30);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo>Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro>Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block195(194);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #195 (Condition) //
void block195(int _parent_=0)
{
	if (block195==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=195;

	int crossover=0;
	int crosswidth=1;
	bool o1=false, o2=false;
	
	for (int i=0; i<=crossover; i++)
	{
	   // i=0 - normal pass, i=1 - crossover pass
	
	   // Left operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Lo=_candles("iMedian", "id", 1, "00:00", CurrentSymbol(), CurrentTimeframe());
	   if (MathAbs(Lo) == EMPTY_VALUE) {return;}
	   
	   // Right operand of the condition
	   IndicatorMoreShift(true,i*crosswidth);
	   double Ro=_OBJECT("name", "FALLtgt", OBJPROP_TL_PRICE_BY_SHIFT, 0, 1.2, 1);
	   if (MathAbs(Ro) == EMPTY_VALUE) {return;}
	   
	   // Conditions
	   if (Lo<Ro) {if(i==0){o1=true;}}else{if(i==0){o2=true;}else{o2=false;}}
	   if (crossover==1) {if (Ro<Lo) {if(i==0){o2=true;}}else{if(i==1){o1=false;}}}
	}
	IndicatorMoreShift(true,0); // reset
	// Outputs
	if (o1==true) {block196(195);} else if (o2==true) {/* Yellow output */}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// fxDreema block #196 (SellRun) //
void block196(int _parent_=0)
{
	if (block196==false || FXD_BREAK==true) {return;}
	FXD_CURRENT_FUNCTION_ID=196;

	//////////////////////
	// Input parameters //
	//////////////////////
	
	string OrdersScope="all"; // Group mode
	string OrdersGroup=""; // Group # (empty=Default)
	string SymbolScope="symbol"; // Market mode
	string SYMBOL=CurrentSymbol(); // Market
	string BuysOrSells="sells"; // Filter by type
	
	///////////////
	// Main code //
	///////////////
	
	bool exist=false;
	for (int pos=PositionsTotal()-1; pos>=0; pos--) {
	   if (LoadOrder(PositionGetSymbol(pos))) {
	      if (FilterOrderBy(OrdersScope,OrdersGroup, SymbolScope,SYMBOL, BuysOrSells)) {
	         exist=true; break;
	      }
	   }
	}
	
	if (exist==true) {block161(196);} else {/* Yellow output */}
}


/************************************************************************************************************************/
// +------------------------------------------------------------------------------------------------------------------+ //
// |                                                  API FUNCTIONS                                                   | //
// |                                 System and Custom functions used in the program                                  | //
// +------------------------------------------------------------------------------------------------------------------+ //
/************************************************************************************************************************/

// System functions
double AccountBalance() {return(AccountInfoDouble(ACCOUNT_BALANCE));}
double AccountBalanceAtStart()
{
   // This function MUST be run once at pogram's start
   static double memory=0;
   if (memory==0) {memory=AccountInfoDouble(ACCOUNT_BALANCE);}
   return(memory);
}
double AccountEquity() {return(AccountInfoDouble(ACCOUNT_EQUITY));}
double AccountFreeMargin() {return(AccountInfoDouble(ACCOUNT_FREEMARGIN));}
double AlignLots(double lots, double lowerlots=0, double upperlots=0)
{
   string symbol=GetSymbol();

   double LotStep=SymbolLotStep(symbol);
   double LotSize=SymbolLotSize(symbol);
   double MinLots=SymbolMinLot(symbol);
   double MaxLots=SymbolMaxLot(symbol);
   
   //if (lots>MaxLots) {lots=lots/LotSize;}
   
   //double stepsize=0;
   //while(lots+0.000000001>stepsize){stepsize+=LotStep;}
   //lots=stepsize-LotStep;
   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 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);} // no sl - 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;

   //-- buy-sell identifier ---------------------------------------------
   int bs=1;
   if (
      type==ORDER_TYPE_BUY
      || type==ORDER_TYPE_BUY_STOP
      || type==ORDER_TYPE_BUY_LIMIT
      || type==ORDER_TYPE_BUY_STOP_LIMIT
      )
   {
      bs=1;
   }
   else if (
      type==ORDER_TYPE_SELL
      || type==ORDER_TYPE_SELL_STOP
      || type==ORDER_TYPE_SELL_LIMIT
      || type==ORDER_TYPE_SELL_STOP_LIMIT
      )
   {
      bs=-1;
   }
   
   //-- prices that will be used ----------------------------------------
   double askbid=price;
   double bidask=price;
   
   if (type==ORDER_TYPE_BUY || type==ORDER_TYPE_SELL)
   {
      double ask =SymbolInfoDouble(symbol,SYMBOL_ASK);
      double bid =SymbolInfoDouble(symbol,SYMBOL_BID);
      
      askbid=ask;
      bidask=bid;
      if (bs<0) {
        askbid=bid;
        bidask=ask;
      }
   }
   
   //-- build sl level -------------------------------------------------- 
   if (sll==0 && slp!=0) {sll=price;}
   
   if (sll>0) {sl=sll-slp*bs;}
   
   if (sl<0) {return(-1);}
      
   sl=NormalizeDouble(sl,digits);
   
   //-- build limit levels ----------------------------------------------
   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
   
   //-- check and align sl, print errors --------------------------------
   if (sl>0) {
      /*if (sl==askbid)
      {
         sl=0;
      }
      else */
      if ((bs>0 && sl>askbid) || (bs<0 && sl<askbid))
      {
         string abstr="";
         if (bs>0) {abstr="Ask";} else {abstr="Bid";}
         Print(
            "Error: Invalid SL requested (",
            DoubleToStr(sl,digits),
            " for ",abstr," price ",
            askbid,
            ")"
            );
         return(-1);
      }
      else if ((bs>0 && sl>sllimit) || (bs<0 && sl<sllimit))
      {
         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);
      }
   }
   return(sl);
}
double AlignTakeProfit(
   string symbol,
   int type,
   double price,
   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);} // no tp - 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;
   
   //-- buy-sell identifier ---------------------------------------------
   int bs=1;
   if (
      type==ORDER_TYPE_BUY
      || type==ORDER_TYPE_BUY_STOP
      || type==ORDER_TYPE_BUY_LIMIT
      || type==ORDER_TYPE_BUY_STOP_LIMIT
      )
   {
      bs=1;
   }
   else if (
      type==ORDER_TYPE_SELL
      || type==ORDER_TYPE_SELL_STOP
      || type==ORDER_TYPE_SELL_LIMIT
      || type==ORDER_TYPE_SELL_STOP_LIMIT
      )
   {
      bs=-1;
   }
   
   //-- prices that will be used ----------------------------------------
   double askbid=price;
   double bidask=price;
   
   if (type==ORDER_TYPE_BUY || type==ORDER_TYPE_SELL)
   {
      double ask =SymbolInfoDouble(symbol,SYMBOL_ASK);
      double bid =SymbolInfoDouble(symbol,SYMBOL_BID);
      
      askbid=ask;
      bidask=bid;
      if (bs<0) {
        askbid=bid;
        bidask=ask;
      }
   }
   
   //-- build tp level --------------------------------------------------- 
   if (tpl==0 && tpp!=0) {tpl=price;}

   if (tpl>0) {tp=tpl+tpp*bs;}
   
   if (tp<0) {return(-1);}

   tp=NormalizeDouble(tp,digits);
   
   //-- build limit levels ----------------------------------------------
   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
   
   //-- check and align tp, print errors --------------------------------
   if (tp>0) {
      /*if (tp==askbid)
      {
         tp=0;
      }
      else */
      if ((bs>0 && tp<askbid) || (bs<0 && tp>askbid))
      {
         string abstr="";
         if (bs>0) {abstr="Ask";} else {abstr="Bid";}
         Print(
            "Error: Invalid TP requested (",
            DoubleToStr(tp,digits),
            " for ",abstr," price ",
            askbid,
            ")"
            );
         return(-1);
      }
      else if ((bs>0 && tp<tplimit) || (bs<0 && tp>tplimit))
      {
         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);
      }
   }
   return(tp);
}
int ArraySearch(int &array[], int value)
{
   bool founded=false;
   int index=-1;
   int size=ArraySize(array);
   if (size>0)
   {
      for (int i=0; i<size; i++) {
         if (array[i]==value) {
            founded=true;
            index=i;
            break;
         }  
   	}
   }
   if (founded==true) {return (index);} else {return (-1);}
}
int ArraySearch(double &array[], double value)
{
   bool founded=false;
   int index=-1;
   int size=ArraySize(array);
   if (size>0)
   {
      for (int i=0; i<size; i++) {
         if (array[i]==value) {
            founded=true;
            index=i;
            break;
         }  
      }
   }
   if (founded==true) {return (index);} else {return (-1);}
}
int ArraySearch(string &array[], string value)
{
   bool founded=false;
   int index=-1;
   int size=ArraySize(array);
   if (size>0)
   {
      for (int i=0; i<size; i++) {
         if (array[i]==value) {
            founded=true;
            index=i;
            break;
         }  
      }
   }
   if (founded==true) {return (index);} else {return (-1);}
}
bool ArrayStripKey(double &array[], double key)
{
   bool stripped=false;
   int size=ArraySize(array);
   if (size>0)
   {
      int i=0; int x=0;
      for (i=0; i<size; i++)
      {
         if (i!=key)
         {
            array[x]=array[i];
            x++;
         } else {
            stripped=true;  
         }
      }
      ArrayResize(array,x);
   }
   return (stripped);
}
bool ArrayStripKey(int &array[], int key)
{
   bool stripped=false;
   int size=ArraySize(array);
   if (size>0)
   {
      int i=0; int x=0;
      for (i=0; i<size; i++)
      {
         if (i!=key)
         {
            array[x]=array[i];
            x++;
         } else {
            stripped=true;  
         }
      }
      ArrayResize(array,x);
   }
   return (stripped);
}
bool ArrayStripKey(string &array[], int key)
{
   bool stripped=false;
   int size=ArraySize(array);
   if (size>0)
   {
      int i=0; int x=0;
      for (i=0; i<size; i++)
      {
         if (i!=key)
         {
            array[x]=array[i];
            x++;
         } else {
            stripped=true;  
         }
      }
      ArrayResize(array,x);
   }
   return (stripped);
}
double Bet1326(string 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
   
   //-- try to get last lot size from running trades
   if (LoadOrder(symbol)) {
      lots=attrLots();
   }
   
   //-- if no running trade was found, search in history trades
   if (lots==0)
   {
      HistorySelect(0,TimeCurrent());
      total=HistoryDealsTotal();
      
      for (pos=total-1; pos>=0; pos--)
      {
         if (!LoadHistoryOrder(pos,"select_by_pos")) {continue;}
         if (LoadedType()!=3) {continue;}
         //if (OrderMagicNumber() != MagicStart+group) {continue;}
         if (OrderSymbol() != symbol) {continue;}
         if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
   
         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 < SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN)) {
      initial_lots = SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);  
   }

   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(string 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
   
   //-- try to get last lot size from running trades
   if (LoadOrder(symbol)) {
      lots=attrLots();
   }
   
   //-- if no running trade was found, search in history trades
   if (lots==0)
   {
      HistorySelect(0,TimeCurrent());
      total=HistoryDealsTotal();
      
      for (pos=total-1; pos>=0; pos--)
      {
         if (!LoadHistoryOrder(pos,"select_by_pos")) {continue;}
         if (LoadedType()!=3) {continue;}
         //if (OrderMagicNumber() != MagicStart+group) {continue;}
         if (OrderSymbol() != symbol) {continue;}
         if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
   
         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 < SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN)) {
      initial_lots = SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);  
   }

   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(
   string 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
   
   //-- try to get last lot size from running trades
   if (LoadOrder(symbol)) {
      lots=attrLots();
   }
   
   //-- if no running trade was found, search in history trades
   if (lots==0)
   {
      HistorySelect(0,TimeCurrent());
      total=HistoryDealsTotal();
      
      for (pos=total-1; pos>=0; pos--)
      {
         if (!LoadHistoryOrder(pos,"select_by_pos")) {continue;}
         if (LoadedType()!=3) {continue;}
         //if (OrderMagicNumber() != MagicStart+group) {continue;}
         if (OrderSymbol() != symbol) {continue;}
         if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
   
         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 < SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN)) {
      initial_lots = SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);  
   }

   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;}
      }
      //Print("("+fibo1 + "+" + fibo2+"+"+fibo3+") > "+div);
      if (profit_or_loss==1)
      {
         if (fibo4<=0) {fibo4=1;}
         //Print("Profit "+lots+"*"+fibo4);
         lots=initial_lots*(fibo4);
      }
      else {
         //Print("Loss "+lots+"*"+fibo1+"+"+fibo2);
         lots=initial_lots*(fibo1);
      }
   }
   
   lots=NormalizeDouble(lots, 2);
   return lots;
}
double BetLabouchere(string s_group, string symbol, double initial_lots, string list_of_numbers, double reverse=false)
{   
   int group = (int)StringToInteger(s_group);
   
   int pos=0;
   int total=0;
   double lots=0;
   double profit=0;
   int profit_or_loss=0; // 0 - unknown, 1 - profit, -1 - loss
   
   //-- try to get last lot size from running trades
   if (LoadOrder(symbol)) {
      lots=attrLots();
   }
   
   //-- if no running trade was found, search in history trades
   if (lots==0)
   {
      HistorySelect(0,TimeCurrent());
      total=HistoryDealsTotal();
      
      for (pos=total-1; pos>=0; pos--)
      {
         if (!LoadHistoryOrder(pos,"select_by_pos")) {continue;}
         if (LoadedType()!=3) {continue;}
         //if (OrderMagicNumber() != MagicStart+group) {continue;}
         if (OrderSymbol() != symbol) {continue;}
         if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
   
         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;
      }
   }
   
   //-- Labouchere stuff
   static int mem_group[];
   static string mem_list[];
   static int mem_ticket[];
   int start_again=false;
   
   //- get the list of numbers as it is stored in the memory, or store it
   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]==(int)OrderTicket()) {
      // the last known ticket (mem_ticket[id]) should be different than OderTicket() normally
      // when failed to create a new trade - the last ticket remains the same
      // so we need to reset
      mem_list[id]=list_of_numbers;
   }
   mem_ticket[id]=(int)OrderTicket();
   
   //- now turn the string into integer array
   int list[];
   string listS[];
   StringExplode(",", mem_list[id], listS);
   ArrayResize(list, ArraySize(listS), ArraySize(listS));
   for (int s=0; s<ArraySize(listS); s++) {
      list[s]=(int)StringToInteger(StringTrim(listS[s]));  
   }

   //-- 
   int size = ArraySize(list);

   if (initial_lots < SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN)) {
      initial_lots = SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);  
   }

   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, 0);
         }
         else if (size==2) {
            lots = initial_lots*(list[0]+list[1]);
            ArrayResize(list, 0, 0);
         }
         else if (size>2) {
            lots = initial_lots*(list[0]+list[size-1]);
            // Cancel first and last numbers in our list
            // shift array 1 step left
            for(pos=0; pos<size-1; pos++) {
               list[pos]=list[pos+1];
            }
            ArrayResize(list,ArraySize(list)-2, ArraySize(list)-2); // remove last 2 elements   	
         }
         if (lots < initial_lots) {lots = initial_lots;}
      }
      else {
         if (size>1)
         {
            ArrayResize(list, size+1, 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(
   string 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;
   
   //-- try to get last lot size from running trades
   if (LoadOrder(symbol)) {
      lots=attrLots();
      in_a_row++;
   }
   
   //-- if no running trade was found, search in history trades
   if (lots==0)
   {
      HistorySelect(0,TimeCurrent());
      total=HistoryDealsTotal();
      
      for (pos=total-1; pos>=0; pos--)
      {
         if (!LoadHistoryOrder(pos,"select_by_pos")) {continue;}
         if (LoadedType()!=3) {continue;}
         //if (OrderMagicNumber() != MagicStart+group) {continue;}
         if (OrderSymbol() != symbol) {continue;}
         if (TimeCurrent() - OrderOpenTime() < 3) {continue;}

         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) {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(string s_group, string symbol, double initial_lots, string sequence_on_loss, string sequence_on_profit, bool reverse=false)
{
   int group = (int)StringToInteger(s_group);
   
   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
   
   //-- try to get last lot size from running trades
   if (LoadOrder(symbol)) {
      lots=attrLots();
   }
   
   //-- if no running trade was found, search in history trades
   if (lots==0)
   {
      HistorySelect(0,TimeCurrent());
      total=HistoryDealsTotal();
      
      for (pos=total-1; pos>=0; pos--)
      {
         if (!LoadHistoryOrder(pos,"select_by_pos")) {continue;}
         if (LoadedType()!=3) {continue;}
         //if (OrderMagicNumber() != MagicStart+group) {continue;}
         if (OrderSymbol() != symbol) {continue;}
         if (TimeCurrent() - OrderOpenTime() < 3) {continue;}
   
         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;
      }
   }
   
   //-- Sequence stuff
   static int mem_group[];
   static string mem_list_loss[];
   static string mem_list_profit[];
   static int mem_ticket[];
   
   //- get the list of numbers as it is stored in the memory, or store it
   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]==(int)OrderTicket()) {
      // the last known ticket (mem_ticket[id]) should be different than OderTicket() normally
      // when failed to create a new trade - the last ticket remains the same
      // so we need to reset
      mem_list_loss[id]=sequence_on_loss;
      mem_list_profit[id]=sequence_on_profit;
   }
   mem_ticket[id]=(int)OrderTicket();
   
   //- now turn the string into integer array
   int s=0;
   int list_loss[];
   int 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]=(int)StringToInteger(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]=(int)StringToInteger(StringTrim(listS[s]));  
   }

   //--
   if (initial_lots < SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN)) {
      initial_lots = SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);  
   }

   if (lots==0) {lots = initial_lots;}
   else
   {
      if ((reverse==false && profit_or_loss==1) || (reverse==true && profit_or_loss==-1))
      {
         lots = initial_lots*list_profit[0];
         // shift array 1 step left
         size=ArraySize(list_profit);
         for(pos=0; pos<size-1; pos++) {
            list_profit[pos]=list_profit[pos+1];
         }
         if (size>0) {
            ArrayResize(list_profit, size-1, size-1);
            mem_list_profit[id]=StringImplode(",", list_profit);
         }
         // reset the opposite sequence
         //mem_list_loss[id]="";
      }
      else {
         
         lots = initial_lots*list_loss[0];
         // shift array 1 step left
         size=ArraySize(list_loss);
         for(pos=0; pos<size-1; pos++) {
            list_loss[pos]=list_loss[pos+1];
         }
         if (size>0) {
            ArrayResize(list_loss, size-1, size-1);
            mem_list_loss[id]=StringImplode(",", list_loss);
         }
         // reset the opposite sequence
         //mem_list_profit[id]="";
      }
   }
   
   return lots;
}
int BuildOrdersList(order &list[])
{
   int last_error=0;
   int total=OrdersTotal();

   int temp_value=(int)MathMax(total,1);
   ArrayResize(list,temp_value);

   int orders_count=0;
   for(int i=total-1; i>=0; i--)
     {
      if(!OrderGetTicket(i))
        {
         last_error=GetLastError();
         Print("BuildOrdersList() - Error #",last_error);
         continue;
        }
      else
        {
        list[i].ticket          =OrderGetTicket(i);
        list[i].time_setup      =(datetime)OrderGetInteger(ORDER_TIME_SETUP);
        list[i].time_expiration =(datetime)OrderGetInteger(ORDER_TIME_EXPIRATION);
        list[i].time_done       =(datetime)OrderGetInteger(ORDER_TIME_DONE);
        list[i].type            =OrderGetInteger(ORDER_TYPE);
        
        list[i].state           =OrderGetInteger(ORDER_STATE);
        list[i].type_filling    =OrderGetInteger(ORDER_TYPE_FILLING);
        list[i].type_time       =OrderGetInteger(ORDER_TYPE_TIME);
        list[i].magic           =OrderGetInteger(ORDER_MAGIC);
        list[i].position_id     =OrderGetInteger(ORDER_POSITION_ID);
        
        list[i].volume_initial  =OrderGetDouble(ORDER_VOLUME_INITIAL);
        list[i].volume_current  =OrderGetDouble(ORDER_VOLUME_CURRENT);
        list[i].price_open      =OrderGetDouble(ORDER_PRICE_OPEN);
        list[i].sl              =OrderGetDouble(ORDER_SL);
        list[i].tp              =OrderGetDouble(ORDER_TP);
        list[i].price_current   =OrderGetDouble(ORDER_PRICE_CURRENT);
        list[i].price_stoplimit =OrderGetDouble(ORDER_PRICE_STOPLIMIT);
        
        list[i].symbol          =OrderGetString(ORDER_SYMBOL);
        list[i].comment         =OrderGetString(ORDER_COMMENT);
        
        orders_count++;
        }
     }

   temp_value=(int)MathMax(orders_count,1);
   ArrayResize(list,temp_value);
   return(orders_count);
}
int BuildPositionsList(position &list[])
{
   int last_error=0;
   int total=PositionsTotal();

   int temp_value=(int)MathMax(total,1);
   ArrayResize(list, temp_value);

   int positions_count=0;
   for(int i=total-1; i>=0; i--)
     {
      if(!PositionSelect(PositionGetSymbol(i)))
        {
         last_error=GetLastError();
         Print("PositionSelect() - Error #",last_error);
         continue;
        }
      else
        {
            // If the position is found, then put its info to the array
            list[i].position_id   =PositionGetInteger(POSITION_IDENTIFIER);
            list[i].type          =PositionGetInteger(POSITION_TYPE);
            list[i].time          =(datetime)PositionGetInteger(POSITION_TIME);
            list[i].magic         =PositionGetInteger(POSITION_MAGIC);
            list[i].volume        =PositionGetDouble(POSITION_VOLUME);
            list[i].price_open    =PositionGetDouble(POSITION_PRICE_OPEN);
            list[i].sl            =PositionGetDouble(POSITION_SL);
            list[i].tp            =PositionGetDouble(POSITION_TP);
            list[i].price_current =PositionGetDouble(POSITION_PRICE_CURRENT);
            list[i].comission     =PositionGetDouble(POSITION_COMMISSION);
            list[i].swap          =PositionGetDouble(POSITION_SWAP);
            list[i].profit        =PositionGetDouble(POSITION_PROFIT);
            list[i].symbol        =PositionGetString(POSITION_SYMBOL);
            list[i].comment       =PositionGetString(POSITION_COMMENT);
            positions_count++;
        }
     }

   temp_value=(int)MathMax(positions_count,1);
   ArrayResize(list,temp_value);
   return(positions_count);
}
int BuyNow(
   string symbol,
   double lots,
   double sll,
   double tpl,
   double slp,
   double tpp,
   double slippage=0,
   int magic=0,
   string comment=""
   )
{
   bool success=OrderCreate(
      symbol,
      POSITION_TYPE_BUY,
      lots,
      0,
      sll,
      tpl,
      slp,
      tpp,
      slippage,
      magic,
      comment,
      0
      );
   return(success);
}
double ChartEventParameterDouble(int cmd=0,double inp=-1) {static double mem=-1; if(cmd==1){mem=inp;} return(mem);}
long ChartEventParameterLong(int cmd=0,long inp=-1) {static long mem=-1; if(cmd==1){mem=inp;} return(mem);}
string ChartEventParameterString(int cmd=0,string inp="") {static string mem=""; if(cmd==1){mem=inp;} return(mem);}
int ChartEventType(int cmd=0,int inp=-1) {static int mem=-1; if(cmd==1){mem=inp;} return(mem);}
int CheckForTradingError(int error_code=-1, string msg_prefix="")
{
   // return 0 -> no error
   // return 1 -> overcomable error
   // return 2 -> fatal error
   
   int retval=0;
   static int tryouts=0;
   
   //-- error check -----------------------------------------------------
   switch(error_code)
   {
      //-- no error
      case 0:
         retval=0;
         break;
      //-- overcomable errors
      case TRADE_RETCODE_REQUOTE:
      case TRADE_RETCODE_REJECT:
      case TRADE_RETCODE_ERROR:
      case TRADE_RETCODE_TIMEOUT:
      case TRADE_RETCODE_INVALID_VOLUME:
      case TRADE_RETCODE_INVALID_PRICE:
      case TRADE_RETCODE_INVALID_STOPS:
      case TRADE_RETCODE_INVALID_EXPIRATION:
      case TRADE_RETCODE_PRICE_CHANGED:
      case TRADE_RETCODE_PRICE_OFF:
      case TRADE_RETCODE_TOO_MANY_REQUESTS:
      case TRADE_RETCODE_NO_CHANGES:
      case TRADE_RETCODE_CONNECTION:
         retval=1;
         break;
      //-- critical errors
      default:
         retval=2;
         break;
   }
   
   if (error_code > 0)
   {
      string msg = "";
      if (retval == 1)
      {
         StringConcatenate(msg, msg_prefix,": ",ErrorMessage(error_code),". Retrying in 5 seconds..");
         Sleep(500); 
      }
      else if (retval == 2)
      {
         StringConcatenate(msg, msg_prefix,": ",ErrorMessage(error_code));
      }
      Print(msg);
   }
   
   if (retval==0)
   {
      tryouts=0;
   }
   else if (retval==1)
   {
      tryouts++;
      if (tryouts>=10)
      {
         tryouts=0;
         retval=2;
      }
      else
      {
         Print("retry #"+(string)tryouts+" of 10");
      }
   }
   
   return(retval);
}
string CurrentSymbol(string symbol="")
{
   static string memory="";
   if (symbol!="") {memory=symbol;} else
   if (memory=="") {memory=Symbol();}
   return(memory);
}
ENUM_TIMEFRAMES CurrentTimeframe(ENUM_TIMEFRAMES tf=-1)
{
   static ENUM_TIMEFRAMES memory=0;
   if (tf>=0) {memory=tf;}
   return(memory);
}
string DoubleToStr(double d, int dig){return(DoubleToString(d,dig));}
void DrawSpreadInfo()
{
   static bool allow_draw = true;
   if (allow_draw==false) {return;}
   if (MQLInfoInteger(MQL_TESTER) && !MQLInfoInteger(MQL_VISUAL_MODE)) {allow_draw=false;} // Allowed to draw only once in testing mode

   static bool passed         = false;
   static double max_spread   = 0;
   static double min_spread   = EMPTY_VALUE;
   static double avg_spread   = 0;
   static double avg_add      = 0;
   static double avg_cnt      = 0;

   double current_spread = (SymbolInfoDouble(Symbol(),SYMBOL_ASK)-SymbolInfoDouble(Symbol(),SYMBOL_BID))/(CustomPoint(Symbol()));
   if (current_spread > max_spread) {max_spread = current_spread;}
   if (current_spread < min_spread) {min_spread = current_spread;}
   
   avg_cnt++;
   avg_add     = avg_add + current_spread;
   avg_spread  = avg_add / avg_cnt;

   int x=0; int y=0;
   string name;

   // create objects
   if (passed == false)
   {
      passed=true;
      
      name="fxd_spread_current_label";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+1);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 18);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "Spread:");
      }
      name="fxd_spread_max_label";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+148);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+17);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrOrangeRed);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "max:");
      }
      name="fxd_spread_avg_label";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+148);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+9);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "avg:");
      }
      name="fxd_spread_min_label";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+148);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrGold);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "min:");
      }
      name="fxd_spread_current";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+93);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 18);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "0");
      }
      name="fxd_spread_max";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+173);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+17);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrOrangeRed);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "0");
      }
      name="fxd_spread_avg";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+173);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+9);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrDarkOrange);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "0");
      }
      name="fxd_spread_min";
      if (ObjectFind(0, name)==-1) {
         ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
         ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x+173);
         ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y+1);
         ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
         ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
         ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 7);
         ObjectSetInteger(0, name, OBJPROP_COLOR, clrGold);
         ObjectSetString(0, name, OBJPROP_FONT, "Arial");
         ObjectSetString(0, name, OBJPROP_TEXT, "0");
      }
   }
   
   ObjectSetString(0, "fxd_spread_current", OBJPROP_TEXT, DoubleToStr(current_spread,2));
   ObjectSetString(0, "fxd_spread_max", OBJPROP_TEXT, DoubleToStr(max_spread,2));
   ObjectSetString(0, "fxd_spread_avg", OBJPROP_TEXT, DoubleToStr(avg_spread,2));
   ObjectSetString(0, "fxd_spread_min", OBJPROP_TEXT, DoubleToStr(min_spread,2));
}
string DrawStatus(string text="")
{
   static string memory;
   if (text=="") {
      return(memory);
   }
   
   static bool passed = false;
   int x=210; int y=0;
   string name;

   //-- draw the objects once
   if (passed == false)
   {
      passed = true;
      name="fxd_status_title";
      ObjectCreate(0,name, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0,name, OBJPROP_BACK, false);
      ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
      ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
      ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
      ObjectSetInteger(0,name, OBJPROP_XDISTANCE, x);
      ObjectSetInteger(0,name, OBJPROP_YDISTANCE, y+17);
      ObjectSetString(0,name, OBJPROP_TEXT, "Status");
      ObjectSetString(0,name, OBJPROP_FONT, "Arial");
      ObjectSetInteger(0,name, OBJPROP_FONTSIZE, 7);
      ObjectSetInteger(0,name, OBJPROP_COLOR, clrGray);
      
      name="fxd_status_text";
      ObjectCreate(0,name, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0,name, OBJPROP_BACK, false);
      ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_LOWER);
      ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_LEFT_LOWER);
      ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
      ObjectSetInteger(0,name, OBJPROP_XDISTANCE, x+2);
      ObjectSetInteger(0,name, OBJPROP_YDISTANCE, y+1);
      ObjectSetString(0,name, OBJPROP_FONT, "Arial");
      ObjectSetInteger(0,name, OBJPROP_FONTSIZE, 12);
      ObjectSetInteger(0,name, OBJPROP_COLOR, clrAqua);
   }

   //-- update the text when needed
   if (text != memory) {
      memory=text;
      ObjectSetString(0,"fxd_status_text", OBJPROP_TEXT, text);
   }
   
   return(text);
}
double DynamicLots(string mode="balance", double value=0, double sl=0, string align="align")
{
   double size=0;
   string symbol=GetSymbol();
   double LotStep=SymbolLotStep(symbol);
   double LotSize=SymbolLotSize(symbol);
   double MinLots=SymbolMinLot(symbol);
   double MaxLots=SymbolMaxLot(symbol);
   double TickValue=SymbolInfoDouble(symbol,SYMBOL_TRADE_TICK_VALUE);
   double margin_required=0;
   bool ocm = OrderCalcMargin(ORDER_TYPE_BUY,symbol,1,ask(symbol),margin_required); // This is the MODE_MARGINREQUIRED analog in MQL5
   //if (value>MaxLots) {value=value/LotSize;} // Money-to-Lot conversion
   
        if (mode=="fixed" || mode=="lots") {size=value;}
   else if (mode=="block-equity")     {size=(value/100)*AccountEquity()/margin_required;}
   else if (mode=="block-balance")    {size=(value/100)*AccountBalance()/margin_required;}
   else if (mode=="block-freemargin") {size=(value/100)*AccountFreeMargin()/margin_required;}
   else if (mode=="equity")     {size=(value/100)*AccountEquity()/(LotSize*TickValue);}
   else if (mode=="balance")    {size=(value/100)*AccountBalance()/(LotSize*TickValue);}
   else if (mode=="freemargin") {size=(value/100)*AccountFreeMargin()/(LotSize*TickValue);}
   else if (mode=="equityRisk") {size=((value/100)*AccountEquity())/(sl*TickValue*PipValue(symbol));}
   else if (mode=="balanceRisk"){size=((value/100)*AccountBalance())/(sl*TickValue*PipValue(symbol));}
   else if (mode=="freemarginRisk") {size=((value/100)*AccountFreeMargin())/(sl*TickValue*PipValue(symbol));}
   else if (mode=="fixedRisk")   {size=(value)/(sl*TickValue*PipValue(symbol));}
   else if (mode=="fixedRatio" || mode=="RJFR") { 
      /////
      // Ryan Jones Fixed Ratio MM static data
      static double RJFR_start_lots=0;
      static double RJFR_delta=0;
      static double RJFR_units=1;
      static double RJFR_target_lower=0;
      static double RJFR_target_upper=0;
      /////
      
      if (RJFR_start_lots<=0) {RJFR_start_lots=value;}
      if (RJFR_start_lots<MinLots) {RJFR_start_lots=MinLots;}
      if (RJFR_delta<=0) {RJFR_delta=sl;}
      if (RJFR_target_upper<=0) {
         RJFR_target_upper=AccountEquity()+(RJFR_units*RJFR_delta);
         Print("Fixed Ratio MM: Units=>",RJFR_units,"; Delta=",RJFR_delta,"; Upper Target Equity=>",RJFR_target_upper);
      }
      if (AccountEquity()>=RJFR_target_upper)
      {
         while(true) {
            Print("Fixed Ratio MM going up to ",(RJFR_start_lots*(RJFR_units+1))," lots: Equity is above Upper Target Equity (",AccountEquity(),">=",RJFR_target_upper,")");
            RJFR_units++;
            RJFR_target_lower=RJFR_target_upper;
            RJFR_target_upper=RJFR_target_upper+(RJFR_units*RJFR_delta);
            Print("Fixed Ratio MM: Units=>",RJFR_units,"; Delta=",RJFR_delta,"; Lower Target Equity=>",RJFR_target_lower,"; Upper Target Equity=>",RJFR_target_upper);
            if (AccountEquity()<RJFR_target_upper) {break;}
         }
      }
      else if (AccountEquity()<=RJFR_target_lower)
      {
         while(true) {
         if (AccountEquity()>RJFR_target_lower) {break;}
            if (RJFR_units>1) {         
               Print("Fixed Ratio MM going down to ",(RJFR_start_lots*(RJFR_units-1))," lots: Equity is below Lower Target Equity | ", AccountEquity()," <= ",RJFR_target_lower,")");
               RJFR_target_upper=RJFR_target_lower;
               RJFR_target_lower=RJFR_target_lower-((RJFR_units-1)*RJFR_delta);
               RJFR_units--;
               Print("Fixed Ratio MM: Units=>",RJFR_units,"; Delta=",RJFR_delta,"; Lower Target Equity=>",RJFR_target_lower,"; Upper Target Equity=>",RJFR_target_upper);
            } else {break;}
         }
      }
      size=RJFR_start_lots*RJFR_units;
   }
   
   static bool alert_min_lots=false;
   if (size<MinLots && alert_min_lots==false) {alert_min_lots=true;
      Alert("You want to trade ",size," lot, but your broker's minimum is ",MinLots," lot. The trade/order will continue with ",MinLots," lot instead of ",size," lot. The same rule will be applied for next trades/orders with desired lot size lower than the minimum. You will not see this message again until you restart the program.");
   }

   //double stepsize=0;
   //while(size+0.000000001>stepsize){stepsize+=LotStep;}
   //size=stepsize-LotStep;
   size=MathRound(size/LotStep)*LotStep;
   
   if (align=="align") {
      if (size<MinLots) {size=MinLots;}
      if (size>MaxLots) {size=MaxLots;}
   }
   
   return (size);
}
string ErrorMessage(int error_code=-1)
{
   if (error_code<0) {error_code=GetLastError();}
   string error_string="";

   switch(error_code)
   {
      //--- Runtime
      case 0: return("");
      case 4001: error_string="Unexpected internal error"; break;
      case 4002: error_string="Wrong parameter in the inner call of the client terminal function"; break;
      case 4003: error_string="Wrong parameter when calling the system function"; break;
      case 4004: error_string="Not enough memory to perform the system function"; break;
      case 4005: error_string="The structure contains objects of strings and/or dynamic arrays and/or structure of such objects and/or classes"; break;
      case 4006: error_string="Array of a wrong type, wrong size, or a damaged object of a dynamic array"; break;
      case 4007: error_string="Not enough memory for the relocation of an array, or an attempt to change the size of a static array"; break;
      case 4008: error_string="Not enough memory for the relocation of string"; break;
      case 4009: error_string="Not initialized string"; break;
      case 4010: error_string="Invalid date and/or time"; break;
      case 4011: error_string="Requested array size exceeds 2 GB"; break;
      case 4012: error_string="Wrong pointer"; break;
      case 4013: error_string="Wrong type of pointer"; break;
      case 4014: error_string="System function is not allowed to call"; break;
      //-- Charts
      case 4101: error_string="Wrong chart ID"; break;
      case 4102: error_string="Chart does not respond"; break;
      case 4103: error_string="Chart not found"; break;
      case 4104: error_string="No Expert Advisor in the chart that could handle the event"; break;
      case 4105: error_string="Chart opening error"; break;
      case 4106: error_string="Failed to change chart symbol and period"; break;
      case 4107: error_string="Wrong parameter for timer"; break;
      case 4108: error_string="Failed to create timer"; break;
      case 4109: error_string="Wrong chart property ID"; break;
      case 4110: error_string="Error creating screenshots"; break;
      case 4111: error_string="Error navigating through chart"; break;
      case 4112: error_string="Error applying template"; break;
      case 4113: error_string="Subwindow containing the indicator was not found"; break;
      case 4114: error_string="Error adding an indicator to chart"; break;
      case 4115: error_string="Error deleting an indicator from the chart"; break;
      case 4116: error_string="Indicator not found on the specified chart"; break;
      //-- Graphical Objects
      case 4201: error_string="Error working with a graphical object"; break;
      case 4202: error_string="Graphical object was not found"; break;
      case 4203: error_string="Wrong ID of a graphical object property"; break;
      case 4204: error_string="Unable to get date corresponding to the value"; break;
      case 4205: error_string="Unable to get value corresponding to the date"; break;
      //-- Market Info
      case 4301: error_string="Unknown symbol"; break;
      case 4302: error_string="Symbol is not selected in MarketWatch"; break;
      case 4303: error_string="Wrong identifier of a symbol property"; break;
      case 4304: error_string="Time of the last tick is not known (no ticks)"; break;
      case 4305: error_string="Error adding or deleting a symbol in MarketWatch"; break;
      //-- History Access
      case 4401: error_string="Requested history not found"; break;
      case 4402: error_string="Wrong ID of the history property"; break;
      //-- Global Variables
      case 4501: error_string="Global variable of the client terminal is not found"; break;
      case 4502: error_string="Global variable of the client terminal with the same name already exists"; break;
      case 4510: error_string="Email sending failed"; break;
      case 4511: error_string="Sound playing failed"; break;
      case 4512: error_string="Wrong identifier of the program property"; break;
      case 4513: error_string="Wrong identifier of the terminal property"; break;
      case 4514: error_string="File sending via ftp failed"; break;
      //-- Custom Indicator Buffers
      case 4601: error_string="Not enough memory for the distribution of indicator buffers"; break;
      case 4602: error_string="Wrong indicator buffer index"; break;
      //-- Custom Indicator Properties
      case 4603: error_string="Wrong ID of the custom indicator property"; break;
      //-- Account
      case 4701: error_string="Wrong account property ID"; break;
      case 4751: error_string="Wrong trade property ID"; break;
      case 4752: error_string="Trading by Expert Advisors prohibited"; break;
      case 4753: error_string="Position not found"; break;
      case 4754: error_string="Order not found"; break;
      case 4755: error_string="Deal not found"; break;
      case 4756: error_string="Trade request sending failed"; break;
      //-- Indicators
      case 4801: error_string="Unknown symbol"; break;
      case 4802: error_string="Indicator cannot be created"; break;
      case 4803: error_string="Not enough memory to add the indicator"; break;
      case 4804: error_string="The indicator cannot be applied to another indicator"; break;
      case 4805: error_string="Error applying an indicator to chart"; break;
      case 4806: error_string="Requested data not found"; break;
      case 4807: error_string="Wrong indicator handle"; break;
      case 4808: error_string="Wrong number of parameters when creating an indicator"; break;
      case 4809: error_string="No parameters when creating an indicator"; break;
      case 4810: error_string="The first parameter in the array must be the name of the custom indicator"; break;
      case 4811: error_string="Invalid parameter type in the array when creating an indicator"; break;
      case 4812: error_string="Wrong index of the requested indicator buffer"; break;
      //-- Depth of Market
      case 4901: error_string="Depth Of Market can not be added"; break;
      case 4902: error_string="Depth Of Market can not be removed"; break;
      case 4903: error_string="The data from Depth Of Market can not be obtained"; break;
      case 4904: error_string="Error in subscribing to receive new data from Depth Of Market"; break;
      //-- File Operations
      case 5001: error_string="More than 64 files cannot be opened at the same time"; break;
      case 5002: error_string="Invalid file name"; break;
      case 5003: error_string="Too long file name"; break;
      case 5004: error_string="File opening error"; break;
      case 5005: error_string="Not enough memory for cache to read"; break;
      case 5006: error_string="File deleting error"; break;
      case 5007: error_string="A file with this handle was closed, or was not opening at all"; break;
      case 5008: error_string="Wrong file handle"; break;
      case 5009: error_string="The file must be opened for writing"; break;
      case 5010: error_string="The file must be opened for reading"; break;
      case 5011: error_string="The file must be opened as a binary one"; break;
      case 5012: error_string="The file must be opened as a text"; break;
      case 5013: error_string="The file must be opened as a text or CSV"; break;
      case 5014: error_string="The file must be opened as CSV"; break;
      case 5015: error_string="File reading error"; break;
      case 5016: error_string="String size must be specified, because the file is opened as binary"; break;
      case 5017: error_string="A text file must be for string arrays, for other arrays - binary"; break;
      case 5018: error_string="This is not a file, this is a directory"; break;
      case 5019: error_string="File does not exist"; break;
      case 5020: error_string="File can not be rewritten"; break;
      case 5021: error_string="Wrong directory name"; break;
      case 5022: error_string="Directory does not exist"; break;
      case 5023: error_string="This is a file, not a directory"; break;
      case 5024: error_string="The directory cannot be removed"; break;
      case 5025: error_string="Failed to clear the directory (probably one or more files are blocked and removal operation failed)"; break;
      case 5026: error_string="Failed to write a resource to a file"; break;
      //-- String Casting
      case 5030: error_string="No date in the string"; break;
      case 5031: error_string="Wrong date in the string"; break;
      case 5032: error_string="Wrong time in the string"; break;
      case 5033: error_string="Error converting string to date"; break;
      case 5034: error_string="Not enough memory for the string"; break;
      case 5035: error_string="The string length is less than expected"; break;
      case 5036: error_string="Too large number, more than ULONG_MAX"; break;
      case 5037: error_string="Invalid format string"; break;
      case 5038: error_string="Amount of format specifiers more than the parameters"; break;
      case 5039: error_string="Amount of parameters more than the format specifiers"; break;
      case 5040: error_string="Damaged parameter of string type"; break;
      case 5041: error_string="Position outside the string"; break;
      case 5042: error_string="0 added to the string end, a useless operation"; break;
      case 5043: error_string="Unknown data type when converting to a string"; break;
      case 5044: error_string="Damaged string object"; break;
      //-- Operations with Arrays
      case 5050: error_string="Copying incompatible arrays. String array can be copied only to a string array, and a numeric array - in numeric array only"; break;
      case 5051: error_string="The receiving array is declared as AS_SERIES, and it is of insufficient size"; break;
      case 5052: error_string="Too small array, the starting position is outside the array"; break;
      case 5053: error_string="An array of zero length"; break;
      case 5054: error_string="Must be a numeric array"; break;
      case 5055: error_string="Must be a one-dimensional array"; break;
      case 5056: error_string="Timeseries cannot be used"; break;
      case 5057: error_string="Must be an array of type double"; break;
      case 5058: error_string="Must be an array of type float"; break;
      case 5059: error_string="Must be an array of type long"; break;
      case 5060: error_string="Must be an array of type int"; break;
      case 5061: error_string="Must be an array of type short"; break;
      case 5062: error_string="Must be an array of type char"; break;
      //-- trading errors
      case 10004: error_string="Requote occured"; break;
      case 10006: error_string="Order is not accepted by the server"; break;
      case 10007: error_string="Request canceled by trader"; break;
      case 10010: error_string="Only part of the request was completed"; break;
      case 10011: error_string="Request processing error"; break;
      case 10012: error_string="Request canceled by timeout"; break;
      case 10013: error_string="Invalid request"; break;
      case 10014: error_string="Invalid volume"; break;
      case 10015: error_string="Invalid price"; break;
      case 10016: error_string="Invalid SL or TP"; break;
      case 10017: error_string="Trading is disabled"; break;
      case 10018: error_string="Market is closed"; break;
      case 10019: error_string="Not enough money to trade"; break;
      case 10020: error_string="Prices changed"; break;
      case 10021: error_string="There are no quotes to process the request"; break;
      case 10022: error_string="Invalid expiration date in the order request"; break;
      case 10023: error_string="Order state changed"; break;
      case 10024: error_string="Too frequent requests"; break;
      case 10025: error_string="No changes in request"; break;
      case 10026: error_string="Autotrading is disabled by the server"; break;
      case 10027: error_string="Autotrading is disabled by the client terminal"; break;
      case 10028: error_string="Request locked for processing"; break;
      case 10029: error_string="Order or trade frozen"; break;
      case 10030: error_string="Invalid order filling type"; break;
      case 10031: error_string="No connection with the trade server"; break;
      case 10032: error_string="Operation is allowed only for live accounts"; break;
      case 10033: error_string="The number of pending orders has reached the limit"; break;
      case 10034: error_string="The volume of orders and trades for the symbol has reached the limit"; break;
      case 10035: error_string="Incorrect or prohibited order type"; break;
      case 10036: error_string="Position with the specified POSITION_IDENTIFIER has already been closed"; break;
      //-- User-Defined Errors
      case 65536: error_string="User defined errors"; break;
      default:   error_string="Unknown error";
   }

   //if (error_code>0) {error_string="("+(string)error_code+") "+error_string);}
   StringConcatenate(error_string, error_string," (",error_code,")");
   return(error_string);
}
bool FilterOrderBy(string group_mode="all", string group="0", string market_mode="all", string market="", string BuysOrSells="both", string LimitsOrStops="")
{
   bool type_pass = false;
   
   static string market0="-";
   static string markets[];
   static int markets_size=0;
   bool market_pass=false;
   
   static string group0="-";
   static string groups[];
   static int groups_size=0;
   bool group_pass=false;

   int i=0;
   
   // Trades && History trades
   if (LimitsOrStops=="")
   {
      if (
            (BuysOrSells=="both"  && (IsOrderTypeBuy() || IsOrderTypeSell()))
         || (BuysOrSells=="buys"  && IsOrderTypeBuy())
         || (BuysOrSells=="sells" && IsOrderTypeSell())
         )
      {
         type_pass = true;
      }
   }
   // Pending orders
   else
   {
      //if (market_mode=="all" || OrderGetString(ORDER_SYMBOL)==markets[i]) {
      long type = OrderGetInteger(ORDER_TYPE);
      if (
         ((BuysOrSells=="buys"||BuysOrSells=="both") && (type==ORDER_TYPE_BUY_LIMIT || type==ORDER_TYPE_BUY_STOP))
         ||
         ((BuysOrSells=="sells"||BuysOrSells=="both") && (type==ORDER_TYPE_SELL_LIMIT || type==ORDER_TYPE_SELL_STOP))
         )
      {
         if (
               ((LimitsOrStops=="limits"||LimitsOrStops=="both") && (type==ORDER_TYPE_BUY_LIMIT || type==ORDER_TYPE_SELL_LIMIT))
            || ((LimitsOrStops=="stops"||LimitsOrStops=="both") && (type==ORDER_TYPE_BUY_STOP || type==ORDER_TYPE_SELL_STOP))
            )
         {
            type_pass = true;
         }
      }
   }
   if (type_pass == false) {return false;}
   
   //-- check group
   if (group_mode=="group")
   {
      if (group0!=group)
      {
         group0=group;
         StringExplode(",",group,groups);
         groups_size = ArraySize(groups);
         for(i=0; i<groups_size; i++)
         {
            groups[i]=StringTrim(groups[i]);
            if (groups[i]=="") {groups[i]="0";}
         }
      }
      for(i=0; i<groups_size; i++)
      {
         if (OrderMagicNumber()==(MagicStart+(int)groups[i]))
         {
            group_pass=true;
            break;
         }
      }
   }
   else if (group_mode=="all" || (group_mode=="manual" && OrderMagicNumber()==0)) {
      group_pass = true;  
   }
   if (group_pass == false) {return false;}
   
   // check market
   if (market_mode=="all") {
      market_pass=true;
      
   }
   else {
      if (market0!=market)
      {
         market0=market;
         if (market=="")
         {
            markets_size = 1;
            ArrayResize(markets,1);
            markets[0]=Symbol();
         }
         else
         {
            StringExplode(",",market,markets);
            markets_size = ArraySize(markets);
            for(i=0; i<markets_size; i++)
            {
               markets[i]=StringTrim(markets[i]);
               if (markets[i]=="") {markets[i]=Symbol();}
            }
         }
      }
      for(i=0; i<markets_size; i++) {
         if (OrderSymbol()==markets[i]) {
            market_pass = true;
            break;
         }
      }
   }
   if (market_pass == false) {return false;}
 
   return(true);
}
string GetSymbol(string symbol="")
{
   static string memory="";
   if (symbol=="") {
      if (memory=="") {memory=Symbol();}
   }
   else {memory=symbol;}
   return(memory);
}
double IndicatorGetValue(int handle, int mode=0, int shift=0)
{
   static double buffer[1];
   
   if (handle<0) {
      Print("Error: Indicator not handled. (handle=",handle," | error code=",GetLastError(),")");
      return(0);
   }
   
   int tryouts=0;
   
   while(true) {
      if (BarsCalculated(handle)>0) {break;}
      else {
         tryouts++;
         if (MQL5InfoInteger(MQL5_TESTING)) {
            Sleep(10);
         }
         else {
            if (tryouts>10) {
               Print("Error: Indicator cannot load (handle=",handle," | error code=",GetLastError(),")");
               break;
            }
            Sleep(100);
         }
      }
   }
   int success=CopyBuffer(handle,mode,shift,1,buffer);
   if (success<0) {
      Print("Error: Cannot get value from an indicator. (handle=",handle," | error code=",GetLastError(),")");
      return(0);
   }
   //ArraySetAsSeries(buffer,true);

   return(buffer[0]);
}
int IndicatorMoreShift(bool set=false, int shift=0)
{
   static int mem;
   if (set==true) {mem=shift;}
   else {
      int return_val=mem; mem=0; // reset
      return(return_val);
   }
   return(mem);
}
bool IsFillingTypeAllowed(string symbol,int fill_type)
  {
//--- Obtain the value of the property that describes allowed filling modes
   int filling=(int)SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE);
//--- Return true, if mode fill_type is allowed
   return((filling & fill_type)==fill_type);
  }
bool IsOrderTypeBuy() {
   if (LoadedType()==1){
      if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) {return(true);} else {return(false);}
   }
   if (LoadedType()==3) {
      if (
      HistoryOrderGetInteger(OrderTicket(),ORDER_TYPE)==ORDER_TYPE_BUY
      ) {return(true);} else {return(false);}
   }
   if (LoadedType()==4) {
      if (
      HistoryOrderGetInteger(OrderTicket(),ORDER_TYPE)==ORDER_TYPE_BUY_LIMIT
      ||
      HistoryOrderGetInteger(OrderTicket(),ORDER_TYPE)==ORDER_TYPE_BUY_STOP
      ) {return(true);} else {return(false);}
   }
   if (
      OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_LIMIT
      ||
      OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_BUY_STOP
      ) {return(true);} else {return(false);}
   return(false);
}
bool IsOrderTypeSell() {
   if (LoadedType()==1){if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) {return(true);} else {return(false);}}
   if (LoadedType()==3) {
      if (
      HistoryOrderGetInteger(OrderTicket(),ORDER_TYPE)==ORDER_TYPE_SELL
      ) {return(true);} else {return(false);}
   }
   if (LoadedType()==4) {
      if (
      HistoryOrderGetInteger(OrderTicket(),ORDER_TYPE)==ORDER_TYPE_SELL_LIMIT
      ||
      HistoryOrderGetInteger(OrderTicket(),ORDER_TYPE)==ORDER_TYPE_SELL_STOP
      ) {return(true);} else {return(false);}
   }
   if (
      OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_LIMIT
      ||
      OrderGetInteger(ORDER_TYPE)==ORDER_TYPE_SELL_STOP
      ) {return(true);} else {return(false);}
   return(false);
}
int LastIndicatorShift(bool set=false, int shift=0)
{
   static int mem;
   if (set==true) {mem=shift;}
   return(mem);
}
string LastIndicatorSymbol(bool set=false, string symbol="")
{
   static string mem;
   if (set==true) {mem=symbol;}
   return(mem);
}
int LastIndicatorTimeframe(bool set=false, int timeframe=0)
{
   static int mem;
   if (set==true) {mem=timeframe;}
   return(mem);
}
double LastIndicatorValue(bool set=false, double value=0)
{
   static double mem;
   if (set==true) {mem=value;}
   return(mem);
}
bool LoadHistoryOrder(int index, string selectby="select_by_pos")
{
   if (selectby=="select_by_pos") {
      ulong ticket=HistoryDealGetTicket(index);
      ulong oticket=0; //HistoryOrderGetTicket(index);
      oticket=HistoryDealGetInteger(ticket, DEAL_ORDER);
      if (ticket>0 || oticket>0) {
         if (HistoryOrderGetInteger(oticket,ORDER_TYPE)>=2 && HistoryOrderSelect(oticket))
         {
            OrderTicket(oticket);
            LoadedType(4);
            return(true);
         }
         else if (
            HistoryOrderGetInteger(oticket,ORDER_TYPE)<2
            &&
            HistoryOrderSelect(HistoryDealGetInteger(ticket,DEAL_POSITION_ID))
            &&
            (ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT
            )
         {
            OrderTicket(ticket);
            LoadedType(3);
            return(true);
         }
      }
   }
   if (selectby=="select_by_ticket") {
      if (HistoryOrderSelect(index)) {
         HistoryDealSelect(index); // Select deal, it will be just one with pos=0
         HistoryDealGetTicket(0); // Load the one and only selected deal
         OrderTicket(index);
         if (HistoryOrderGetInteger(index,ORDER_TYPE)>=2) {
            LoadedType(4); return(true);
         }
         else {
            LoadedType(3); return(true);
         }
      }
   }
   return(false);
}
bool LoadOrder(ulong ticket)
{
   LoadedType(2);
   bool success=OrderSelect(ticket);
   if (success) {OrderTicket(ticket);}
   return(success);
}
bool LoadOrder(string symbol)
{
   LoadedType(1);
   bool success=PositionSelect(symbol);
   if (success) {OrderTicket((ulong)PositionGetInteger(POSITION_IDENTIFIER));}
   return(success);
}
string LoadedObjectName(string name="") {static string memory=""; if (name!="") {memory=name;} return(memory);}
int LoadedType(int type=0)
{
   // 1 - position
   // 2 - pending order
   // 3 - history position
   // 4 - history pending order
	static int memory;
   if (type>0) {memory=type;}
   return(memory);
}
int ObjectGetShiftByValue(string name, double value) {
   ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);
   datetime Arr[];
   MqlRates mql4[];
   if(ObjectGetTimeByValue(0,name,value)<0) {return(-1);}
   CopyRates(NULL,timeframe,0,1,mql4);
      if(CopyTime(NULL, timeframe, mql4[0].time, ObjectGetTimeByValue(0,name,value), Arr)>0) {return(ArraySize(Arr)-1);}
      else {return(-1);}
}

int ObjectGetShiftByValue(long chart_id, string name, double value) {
   ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);
   datetime Arr[];
   MqlRates mql4[];
   if(ObjectGetTimeByValue(chart_id,name,value)<0) {return(-1);}
   CopyRates(NULL, timeframe, 0, 1, mql4);
   if(CopyTime(NULL, timeframe, mql4[0].time, ObjectGetTimeByValue(chart_id,name,value),Arr)>0) {return(ArraySize(Arr)-1);}
   else {return(-1);}
}
double ObjectGetValueByShift(string name,
                               int shift)
{
 ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);
 MqlRates mql4[];
 CopyRates(NULL,timeframe,shift,1,mql4);
 return(ObjectGetValueByTime(0,name,mql4[0].time,0));
}

double ObjectGetValueByShift(long ctart_id, string name, int shift)
{
 ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);
 MqlRates mql4[];
 CopyRates(NULL,timeframe,shift,1,mql4);
 return(ObjectGetValueByTime(ctart_id,name,mql4[0].time,0));
}
bool OnTimerSet(double seconds)
{
   if (seconds<=0) {
      EventKillTimer();
   }
   else if (seconds < 1) {
      return (EventSetMillisecondTimer((int)(seconds*1000)));  
   }
   else {
      return (EventSetTimer((int)seconds));
   }
   
   return true;
}
bool OnTradeDetector() {

   static int lastOrdersTotal    =OrdersTotal();      // Number of orders at the time of previous OnTrade() call
   static int lastPositionsTotal =PositionsTotal();   // Number of positions at the time of previous OnTrade() call
   
   int i=0;
   ulong ticket=0;
   int last_error=0;
   long state=0;
   bool event=false;
   int positions_count  =BuildPositionsList(EGV_PositionsList);
   int orders_count     =BuildOrdersList(EGV_OrderList);
   HistorySelect(0, TimeCurrent());

   if (lastOrdersTotal < OrdersTotal())
   {
      ticket=OrderGetTicket(OrdersTotal()-1); // Select the last order
      bool success = OrderSelect(ticket);
      state = OrderGetInteger(ORDER_STATE);
      
      if (state == ORDER_STATE_STARTED) {
         //Print("Order #",ticket," has arrived for processing");
      }
      else if (state == ORDER_STATE_PLACED) {
         // Event: New order created
         Print("Pending order type ",(int)OrderGetInteger(ORDER_TYPE)," #", ticket," accepted!");
         UpdateEventValues(EGV_OrderList[OrdersTotal()-1],"new","");
         event=true;
      }
   }
   else if(lastOrdersTotal > OrdersTotal())
   {
      // Select the order that is missing in the new list
      int size=ArraySize(EGV_OrderList);
      int size0=ArraySize(EGV_OrderList0);
      for (i=size0-1; i>=0; i--) {
         ticket=EGV_OrderList0[i].ticket;
         bool found=false;
         for (int j=size-1; j>=0; j--) {
            if (ticket==EGV_OrderList[j].ticket) {found=true;break;}
         }
         if (found==false) {
            break;
         }
      }
      if (i<0) {i=0;}
      
      // Now load that order
      HistoryOrderSelect(ticket);
      state = HistoryOrderGetInteger(ticket,ORDER_STATE);
      if (state==0 && GetLastError()==ERR_TRADE_ORDER_NOT_FOUND) {state=2;}
      
      //Print("Last order ticket = ",ticket, "| state = ",state, "| GetLastError= ",GetLastError());
      
      // If order is not found, generate an error
      ResetLastError();
      last_error=GetLastError();
      if (last_error>0){Print("Error #",last_error," Order ",ticket," was not found!");}
      ResetLastError();
   
      if (state == ORDER_STATE_CANCELED)
      {
         Print("Order #",ticket," has been cancelled.");
         UpdateEventValues(EGV_OrderList0[i],"close","");
         event=true;
      }
      else if (state == ORDER_STATE_EXPIRED)
      {
         Print("Order #",ticket," expired.");
         UpdateEventValues(EGV_OrderList0[i],"expire","");
         event=true;
      }
      else
      // If order is fully executed, analyze the last deal
      if (state == ORDER_STATE_FILLED)
      {
         ulong deal_ticket=HistoryDealGetTicket(HistoryDealsTotal()-1);
         long deal_type=HistoryDealGetInteger(deal_ticket,DEAL_TYPE); // 0 - BUY, 1 - SELL
         string text="";
         
         switch((int)HistoryDealGetInteger(deal_ticket,DEAL_ENTRY))
         {
            // Entering the market
            case DEAL_ENTRY_IN:
               
               if (deal_type==DEAL_TYPE_BUY) {text="Buy";}
               else if (deal_type==DEAL_TYPE_SELL) {text="Sell";}
               
               Print(" Order #",HistoryDealGetInteger(deal_ticket,DEAL_ORDER)," invoked deal #",deal_ticket);
               if (PositionSelect(HistoryDealGetString(deal_ticket,DEAL_SYMBOL))) { 
                  // Position has just been opened
                  if (PositionGetDouble(POSITION_VOLUME) == HistoryDealGetDouble(deal_ticket,DEAL_VOLUME))
                  {
                     Print(text," position has been opened on pair ",HistoryDealGetString(deal_ticket,DEAL_SYMBOL));
                     UpdateEventValues(deal_ticket,"new","fromorder");
                     event=true;
                  }
                  else
                  // Position has been incremented
                  if (PositionGetDouble(POSITION_VOLUME) > HistoryDealGetDouble(deal_ticket,DEAL_VOLUME))
                  {
                     Print(text," position has incremented on pair ",HistoryDealGetString(deal_ticket,DEAL_SYMBOL));
                     UpdateEventValues(deal_ticket,"increment","fromorder");
                     event=true;
                  }
                  else
                  // Position has been decremented
                  if (PositionGetDouble(POSITION_VOLUME) < HistoryDealGetDouble(deal_ticket,DEAL_VOLUME))
                  {
                     Print(text," position has decremented on pair ",HistoryDealGetString(deal_ticket,DEAL_SYMBOL));
                     UpdateEventValues(deal_ticket,"decrement","fromorder");
                     event=true;
                  }
               }
            break;
            
            // Exiting the market
            case DEAL_ENTRY_OUT:
            
               if (deal_type==DEAL_TYPE_BUY) {text="Sell";}
               else if (deal_type==DEAL_TYPE_SELL) {text="Buy";}
               
               Print(HistoryDealGetInteger(deal_ticket,DEAL_ORDER)," order invoked deal #",deal_ticket);
               
               // If position, we tried to close, is still present, then we have closed only part of it
               if (PositionSelect(HistoryDealGetString(deal_ticket,DEAL_SYMBOL)) == true)
               {
                  Print("Part of ",text," position has been closed on pair ",HistoryDealGetString(deal_ticket,DEAL_SYMBOL)," with profit = ",HistoryDealGetDouble(deal_ticket,DEAL_PROFIT));
                  UpdateEventValues(deal_ticket,"closepart","fromorder");
                  event=true;
               }
               else
               // If position is not found, then it is fully closed
               {
                  Print(text," position has been closed on pair ",HistoryDealGetString(deal_ticket,DEAL_SYMBOL)," with profit = ",HistoryDealGetDouble(deal_ticket,DEAL_PROFIT));
                  UpdateEventValues(deal_ticket,"close","fromorder");
                  event=true;
               }
            break;
            
            // Reverse
            case DEAL_ENTRY_INOUT:
            
               Print(HistoryDealGetInteger(deal_ticket,DEAL_ORDER)," order invoked deal #",deal_ticket);
               
               switch((int)deal_type)
               {
                  case 0:
                     Print("Sell is reversed to Buy on pair ",HistoryDealGetString(deal_ticket,DEAL_SYMBOL)," resulting profit = ",HistoryDealGetDouble(deal_ticket,DEAL_PROFIT)); 
                  break;
                  
                  case 1:
                     Print("Buy is reversed to Sell on pair ",HistoryDealGetString(deal_ticket,DEAL_SYMBOL)," resulting profit = ",HistoryDealGetDouble(deal_ticket,DEAL_PROFIT)); 
                  break;
                  
                  default:
                     Print("Unprocessed code of type: ",deal_type);
                  break;
               }
               UpdateEventValues(deal_ticket,"reverse","fromorder");
               event=true;
            break;
            
            // Indicates the state record
            case DEAL_ENTRY_STATE:
               //Print("Unprocessed code of direction: ",HistoryDealGetInteger(deal_ticket,DEAL_TYPE));
            break;
         }
      }
   }
   else if (lastPositionsTotal<PositionsTotal()) {
      ulong deal_ticket=HistoryDealGetTicket(HistoryDealsTotal()-1);
      // New position opened
      UpdateEventValues(deal_ticket,"new","");
      event=true;
   }
   else if (lastPositionsTotal>PositionsTotal()) {
      ulong deal_ticket=HistoryDealGetTicket(HistoryDealsTotal()-1);
      // Position closed
      UpdateEventValues(deal_ticket,"close","");
      e_attrMagicNumber(true, EGV_PositionsList0[i].magic); // for some reason magic number can be get only once in the normal way
      event=true;
   }
   
   if ((lastPositionsTotal == PositionsTotal()) && (lastOrdersTotal == OrdersTotal()))
   {  
      for (i=0; i<positions_count; i++)
      {
         // Position reverse
         if (EGV_PositionsList0[i].type != EGV_PositionsList[i].type)
         {
            Print(EGV_PositionsList[i].symbol+" volume reversed from "+ (string)EGV_PositionsList0[i].type +" to "+ (string)EGV_PositionsList[i].type);
            UpdateEventValues(EGV_PositionsList[i],"reverse","");
            event=true;
         }
         // Position modified SL and/or TP
         if ((EGV_PositionsList0[i].sl != EGV_PositionsList[i].sl) && (EGV_PositionsList0[i].tp != EGV_PositionsList[i].tp)) {
            Print(EGV_PositionsList[i].symbol+" Stop Loss changed from "+ (string)EGV_PositionsList0[i].sl +" to "+ (string)EGV_PositionsList[i].sl);
            Print(EGV_PositionsList[i].symbol+" Take Profit changed from "+ (string)EGV_PositionsList0[i].tp +" to "+ (string)EGV_PositionsList[i].tp);
            UpdateEventValues(EGV_PositionsList[i],"modify","sltp");
            event=true;
         } else {
            if (EGV_PositionsList0[i].sl != EGV_PositionsList[i].sl)
            {
               Print(EGV_PositionsList[i].symbol+" Stop Loss changed from "+ (string)EGV_PositionsList0[i].sl +" to "+ (string)EGV_PositionsList[i].sl);
               UpdateEventValues(EGV_PositionsList[i],"modify","sl");
               event=true;
            }
            if (EGV_PositionsList0[i].tp != EGV_PositionsList[i].tp)
            {
               Print(EGV_PositionsList[i].symbol+" Take Profit changed from "+ (string)EGV_PositionsList0[i].tp +" to "+ (string)EGV_PositionsList[i].tp);
               UpdateEventValues(EGV_PositionsList[i],"modify","tp");
               event=true;
            }
         }
         // Check position increment/decrement
         if (EGV_PositionsList0[i].volume < EGV_PositionsList[i].volume)
         {
            Print(EGV_PositionsList[i].symbol+" volume incremented from "+ (string)EGV_PositionsList0[i].volume +" to "+ (string)EGV_PositionsList[i].volume);
            UpdateEventValues(EGV_PositionsList[i],"increment","");
            event=true;
         }
         else if (EGV_PositionsList0[i].volume > EGV_PositionsList[i].volume)
         {
            Print(EGV_PositionsList[i].symbol+" volume decremented from "+ (string)EGV_PositionsList0[i].volume +" to "+ (string)EGV_PositionsList[i].volume);
            UpdateEventValues(EGV_PositionsList[i],"decrement","");
            event=true;
         }
      }
      
      for (i=0; i<orders_count; i++)
      {
         if ((EGV_OrderList0[i].sl != EGV_OrderList[i].sl) && (EGV_OrderList0[i].tp != EGV_OrderList[i].tp)) {
            Print("Order "+(string)EGV_OrderList[i].ticket+" has changed Stop Loss from "+ (string)EGV_OrderList0[i].sl +" to "+ (string)EGV_OrderList[i].sl);
            Print("Order "+(string)EGV_OrderList[i].ticket+" has changed Take Profit from "+ (string)EGV_OrderList0[i].tp +" to "+ (string)EGV_OrderList[i].tp);
            UpdateEventValues(EGV_OrderList[i],"modify","sltp");
            event=true;
         } else {
            if (EGV_OrderList0[i].sl != EGV_OrderList[i].sl)
            {
               Print("Order "+(string)EGV_OrderList[i].ticket+" has changed Stop Loss from "+ (string)EGV_OrderList0[i].sl +" to "+ (string)EGV_OrderList[i].sl);
               UpdateEventValues(EGV_OrderList[i],"modify","sl");
               event=true;
            }
            if (EGV_OrderList0[i].tp != EGV_OrderList[i].tp)
            {
               Print("Order "+(string)EGV_OrderList[i].ticket+" has changed Take Profit from "+ (string)EGV_OrderList0[i].tp +" to "+ (string)EGV_OrderList[i].tp);
               UpdateEventValues(EGV_OrderList[i],"modify","tp");
               event=true;
            }
         }
         if (EGV_OrderList0[i].price_open != EGV_OrderList[i].price_open)
         {
            Print("Order "+(string)EGV_OrderList[i].ticket+" has changed Open Price from "+ (string)EGV_OrderList0[i].price_open +" to "+ (string)EGV_OrderList[i].price_open);
            UpdateEventValues(EGV_OrderList[i],"modify","price");
            event=true;
         }
         if (EGV_OrderList0[i].time_expiration != EGV_OrderList[i].time_expiration)
         {
            Print("Order "+(string)EGV_OrderList[i].time_expiration+" has changed Expiration from "+ (string)EGV_OrderList0[i].time_expiration +" to "+ (string)EGV_OrderList[i].time_expiration);
            UpdateEventValues(EGV_OrderList[i],"modify","expiration");
            event=true;
         }
      }
   }
   
   
   
   BuildPositionsList(EGV_PositionsList0);
   BuildOrdersList(EGV_OrderList0);
   lastOrdersTotal     =OrdersTotal();
   lastPositionsTotal  =PositionsTotal();
   
   if (event==true) {return(true);} else {return(false);}
}
int OnTradeQueue(int queue=0)
{
	static int mem=0;
   mem=mem+queue;
   return(mem);
}
double OrderClosePrice() {
   if (LoadedType()==1){
      if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) {return(SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_ASK));}
      if (PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) {return(SymbolInfoDouble(PositionGetString(POSITION_SYMBOL),SYMBOL_BID));}
   }
   if (LoadedType()==3){return(HistoryDealGetDouble(attrTicket(),DEAL_PRICE));}
   if (LoadedType()==4){return(HistoryDealGetDouble(attrTicket(),DEAL_PRICE));}
   return(OrderGetDouble(ORDER_PRICE_CURRENT));
}
bool OrderCreate(
   string symbol="",
   int    type=ORDER_TYPE_BUY,
   double lots=0,
   double op=0,
   double sll=0,
   double tpl=0,
   double slp=0,
   double tpp=0,
   double slippage=0,
   ulong  magic=0,
   string comment=NULL,
   ENUM_ORDER_TYPE_TIME type_time=ORDER_TIME_GTC,
   datetime expiration=0
   )
{
   OnTrade(); // When position is closed by sl or tp, this event is not fired (by MetaTrader) until the end of the tick, and if a new position is opened, it will be missed. 

   uint time0=GetTickCount();
   
   bool closing = false;
   double lots0 = 0;
   int type0 = type;
   if (type == POSITION_TYPE_BUY || type == POSITION_TYPE_SELL)
   {
      if (PositionSelect(symbol))
      {
         if ((int)PositionGetInteger(POSITION_TYPE) != type) {
            closing = true;
         }
         lots0 = NormalizeDouble(OrderLots(), 5);
         type0 = OrderType();
      }
   }
   
   int ticket=-1;
   int bs=1;
   if (
         type==ORDER_TYPE_SELL
      || type==ORDER_TYPE_SELL_STOP
      || type==ORDER_TYPE_SELL_LIMIT
   )
   {bs=-1;} // Positive when Buy, negative when Sell
   
   if (symbol=="") {symbol=Symbol();}
   
   lots=AlignLots(lots);

   //-- attempts to send position/order ---------------------------------
   while(true)
   {   
      int digits     =(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
      double ask     =SymbolInfoDouble(symbol,SYMBOL_ASK);
      double bid     =SymbolInfoDouble(symbol,SYMBOL_BID);
      double point   =SymbolInfoDouble(symbol,SYMBOL_POINT);
      
      //- not enough money check: fix maximum possible lot by margin required, or quit
      if ((type==POSITION_TYPE_BUY || type==POSITION_TYPE_SELL) && closing==false)
      {
         double LotStep          =SymbolLotStep(symbol);
         double MinLots          =SymbolMinLot(symbol);
         double margin_required  =0; bool ocm = OrderCalcMargin((ENUM_ORDER_TYPE)type,symbol,1,ask(symbol),margin_required);
         static bool not_enough_message = false;
         
         if (margin_required != 0)
         {
            double max_size_by_margin = AccountFreeMargin()/margin_required;
         
            if (lots > max_size_by_margin) {
               double lots_old = lots;
               lots = max_size_by_margin;
               if (lots<MinLots)
               {
                  if (not_enough_message==false) {
                     Print("Not enough money to trade :( The robot is still working, waiting for some funds to appear...");
                  }
                  not_enough_message = true;
                  return(false);
               }
               else
               {
                  lots = MathFloor(lots/LotStep)*LotStep;
                  Print("Not enough money to trade "+DoubleToString(lots_old, 2)+", the volume to trade will be the maximum possible of "+DoubleToString(lots, 2));
               }
            }
         }
         not_enough_message = false;
      }
      
      if (type==ORDER_TYPE_BUY || type==ORDER_TYPE_SELL)
      {
         op=ask;
         if (bs<0) {
           op=bid;
         }
      }
      op=NormalizeDouble(op, digits);
      if (op<0 || op>=EMPTY_VALUE)  {break;}
      if (sll<0) {break;}
      if (slp<0) {break;}
      if (tpl<0) {break;}
      if (tpp<0) {break;}
      
      //-- SL and TP ----------------------------------------------------
      double sl=0, tp=0;
      
      sl=AlignStopLoss(symbol, type, op, NormalizeDouble(sll,digits), slp);
      if (sl<0) {break;}
      tp=AlignTakeProfit(symbol, type, op, NormalizeDouble(tpl,digits), tpp);
      if (tp<0) {break;}
      
      sl = NormalizeDouble(sl,digits);
      tp = NormalizeDouble(tp,digits);
      
      //-- send ---------------------------------------------------------
      MqlTradeRequest request;
      MqlTradeResult result;
      MqlTradeCheckResult check_result;
      ZeroMemory(request);
      ZeroMemory(result);
      ZeroMemory(check_result);
      
      ENUM_SYMBOL_TRADE_EXECUTION exec =(ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfoInteger(symbol,SYMBOL_TRADE_EXEMODE);

      //if (expiration==0) {type_time=ORDER_TIME_GTC;}

      request.symbol       = symbol;
      request.type         = (ENUM_ORDER_TYPE)type;
      request.volume       = lots;
      request.price        = op;
      request.deviation    = (ulong)(slippage*PipValue(symbol));
      request.sl           = sl;
      request.tp           = tp;
      request.comment      = comment;
      request.magic        = magic;
      request.type_time    = type_time;
      request.expiration   = expiration;
      
      //-- request action
      if (type>ORDER_TYPE_SELL)
      {
         request.action       = TRADE_ACTION_PENDING;
      }
      else
      {
         request.action       = TRADE_ACTION_DEAL;
      }
      //-- filling type
      
      // check ORDER_FILLING_RETURN for pending orders only 
      if (type>ORDER_TYPE_SELL && IsFillingTypeAllowed(symbol, ORDER_FILLING_RETURN))
      {
         request.type_filling = ORDER_FILLING_RETURN;
      }
      else if (IsFillingTypeAllowed(symbol, ORDER_FILLING_FOK))
      {
         request.type_filling = ORDER_FILLING_FOK;
      }
      else if (IsFillingTypeAllowed(symbol, ORDER_FILLING_IOC))
      {
         request.type_filling = ORDER_FILLING_IOC;
      }
      // check ORDER_FILLING_RETURN again, if for some strange reason the other two are not supported for positions
      else if (IsFillingTypeAllowed(symbol, ORDER_FILLING_RETURN))
      {
         request.type_filling = ORDER_FILLING_RETURN;
      }
      
      
      if (!OrderCheck(request,check_result))  {
         Print("OrderCheck() failed: "+(string)check_result.comment+" ("+(string)check_result.retcode+")");
         return false;
      }

      int success=OrderSend(request,result);
      
      //-- error check --------------------------------------------------
      if (!success || result.retcode!=TRADE_RETCODE_DONE)
      {
         string errmsgpfx="New position error";
         if (type>ORDER_TYPE_SELL) {
            errmsgpfx="New pending order error";
         }
         int erraction=CheckForTradingError(result.retcode, errmsgpfx);
         switch(erraction)
         {
            case 0: break;    // no error
            case 1: continue; // overcomable error
            case 2: break;    // fatal error
         }
         return(false);
      }
      
      //-- finish work --------------------------------------------------
      if (result.retcode==TRADE_RETCODE_DONE)
      {
         //== Whatever was created, we need to wait until MT5 updates it's cache

         //-- Synchronize: Position
         if (type<=ORDER_TYPE_SELL)
         {
            if (closing == false)
            {
               //- new position: 2 situations here - new position or add to position
               //- ... because of that we will check the lot size instead of PositionSelect
               while (true)
               {
                  if (LoadOrder(symbol) && (lots0 != NormalizeDouble(OrderLots(), 5))) {break;}
                  Sleep(10);
               }
            }
            else
            {
               //- closing position: full
               if (lots0 == NormalizeDouble(result.volume, 5))
               {
                  while (true)
                  {
                     if (!LoadOrder(symbol)) {break;}
                     Sleep(10);
                  }
               }
               //- closing position: partial
               else if (lots0 > NormalizeDouble(result.volume, 5))
               {
                  while (true)
                  {
                     if (LoadOrder(symbol) && (lots0 != NormalizeDouble(OrderLots(), 5))) {break;}
                     Sleep(10);
                  }
               }
               else if (lots0 < NormalizeDouble(result.volume, 5))
               {
               //-- position reverse
                  while (true)
                  {
                     if (LoadOrder(symbol) && (type0 != OrderType())) {break;}
                     Sleep(10);
                  }
               }
            }
         }
         //-- Synchronize: Order
         else
         {
            while (true)
            {
               if (LoadOrder(result.order)) {break;}
               Sleep(10);
            }
         }
      }
      break;
   }
   OnTrade();
   return(true);
}
double OrderLots() {return(OrderVolume());}
int OrderMagicNumber()
{
   if (LoadedType()==1){return((int)PositionGetInteger(POSITION_MAGIC));}
   if (LoadedType()==3){return((int)HistoryOrderGetInteger(HistoryDealGetInteger(OrderTicket(),DEAL_POSITION_ID),ORDER_MAGIC));}
   if (LoadedType()==4){return((int)HistoryOrderGetInteger(OrderTicket(),ORDER_MAGIC));}
   return((int)OrderGetInteger(ORDER_MAGIC));
}
double OrderOpenPrice() {
   if (LoadedType()==1){return(PositionGetDouble(POSITION_PRICE_OPEN));}
   if (LoadedType()==3){return(HistoryOrderGetDouble(HistoryDealGetInteger(OrderTicket(),DEAL_POSITION_ID),ORDER_PRICE_OPEN));}
   if (LoadedType()==4){return(HistoryOrderGetDouble(OrderTicket(),ORDER_PRICE_OPEN));}
   return(OrderGetDouble(ORDER_PRICE_OPEN));
}
datetime OrderOpenTime() {
   if (LoadedType()==1){return((datetime)PositionGetInteger(POSITION_TIME));}
   if (LoadedType()==3){return((datetime)HistoryOrderGetInteger(HistoryDealGetInteger(OrderTicket(),DEAL_POSITION_ID),ORDER_TIME_SETUP));}
   if (LoadedType()==4){return((datetime)HistoryOrderGetInteger(OrderTicket(),ORDER_TIME_SETUP));}
   return((datetime)OrderGetInteger(ORDER_TIME_SETUP));
}
string OrderSymbol()
{
   if (LoadedType()==1){return(PositionGetString(POSITION_SYMBOL));}
   if (LoadedType()==3){return(HistoryDealGetString(OrderTicket(),DEAL_SYMBOL));}
   if (LoadedType()==4){return(HistoryOrderGetString(OrderTicket(),ORDER_SYMBOL));}
   return(OrderGetString(ORDER_SYMBOL));
}
ulong OrderTicket(ulong Ticket=0)
{
   static ulong memory;             // Ticket memory
   if (Ticket>0) {memory=Ticket;}   // Set Ticket
   return(memory);                  // Get Ticket
}
int OrderType() {
   if (LoadedType()==1){return((int)PositionGetInteger(POSITION_TYPE));}
   if (LoadedType()==3){
      int OT=(int)HistoryDealGetInteger(OrderTicket(),DEAL_TYPE);
      if(OT==1){return(0);}
      if(OT==0){return(1);}
      return(OT);
   }
   if (LoadedType()==4){return((int)HistoryOrderGetInteger(OrderTicket(),ORDER_TYPE));}
   return((int)OrderGetInteger(ORDER_TYPE));
}
double OrderVolume() {
   if (LoadedType()==1){return(NormalizeDouble(PositionGetDouble(POSITION_VOLUME), 5));}
   if (LoadedType()==3){return(NormalizeDouble(HistoryDealGetDouble(attrTicket(),DEAL_VOLUME), 5));}
   if (LoadedType()==4){return(NormalizeDouble(HistoryOrderGetDouble(attrTicket(),ORDER_VOLUME_INITIAL), 5));}
   return(NormalizeDouble(OrderGetDouble(ORDER_VOLUME_CURRENT), 5));
}
double PipValue(string symbol="")
{
   if (symbol=="") {symbol=GetSymbol();}
   return(CustomPoint(symbol)/SymbolInfoDouble(symbol,SYMBOL_POINT));
   /*
   if (symbol=="") {symbol=GetSymbol();}
   int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
   if ((digits==2 || digits==4)) {return((int)(POINT_FORMAT/0.0001));}
   if ((digits==3 || digits==5)) {return((int)(POINT_FORMAT/0.00001));}
   if ((digits==6))              {return((int)(POINT_FORMAT/0.000001));}
   return(1);
   */
}
int SellNow(
   string symbol,
   double lots,
   double sll,
   double tpl,
   double slp,
   double tpp,
   double slippage=0,
   int magic=0,
   string comment=""
   )
{
   bool success=OrderCreate(
      symbol,
      POSITION_TYPE_SELL,
      lots,
      0,
      sll,
      tpl,
      slp,
      tpp,
      slippage,
      magic,
      comment,
      0
      );
   return(success);
}
void SetLastIndicatorData(double value=0, string symbol="", int timeframe=0, int shift=0)
{
   LastIndicatorValue(true,value);
   LastIndicatorSymbol(true,symbol);
   LastIndicatorTimeframe(true,timeframe);
   LastIndicatorShift(true,shift);
   IndicatorMoreShift(true,0); // reset
   return;
}
string SetSymbol(string symbol="")
{
   if (symbol=="") {symbol=Symbol();}
   GetSymbol(symbol); return(symbol);
}
bool SkipThePass(bool set=false)
{
   static int mem_fid=0;
   static bool mem=false;
   if (set==true) {
      mem=true;
      mem_fid=FXD_CURRENT_FUNCTION_ID;
   }
   else {
      if (mem_fid!=FXD_CURRENT_FUNCTION_ID) {
         mem=false; // reset
         return(false);
      }
      if (mem==true) {
         mem=false; // reset
         return(true);
      }
   }
   return(mem);
}
datetime StrToTime(string value)
{
	return(StringToTime(value));
}
void StringExplode(string sDelimiter, string sExplode, string &sReturn[]){
   int ilBegin = -1,ilEnd = 0;
   int ilElement=0;
   while (ilEnd != -1){
      ilEnd = StringFind(sExplode, sDelimiter, ilBegin+1);
      ArrayResize(sReturn,ilElement+1);
      sReturn[ilElement] = "";     
      if (ilEnd == -1){
         if (ilBegin+1 != StringLen(sExplode)){
            sReturn[ilElement] = StringSubstr(sExplode, ilBegin+1, StringLen(sExplode));
         }
      } else { 
         if (ilBegin+1 != ilEnd){
            sReturn[ilElement] = StringSubstr(sExplode, ilBegin+1, ilEnd-ilBegin-1);
         }
      }      
      ilBegin = StringFind(sExplode, sDelimiter,ilEnd);  
      ilElement++;    
   }
}
string StringImplode(string sDelimiter, string &sImplode[]){
   string slImplode = "";
   for (int i = 0; i < ArraySize(sImplode); i++) {
      StringConcatenate(slImplode, slImplode,sImplode[i],sDelimiter);
   }
   return(StringSubstr(slImplode, 0, (StringLen(slImplode) - StringLen(sDelimiter))));
}
string StringImplode(string sDelimiter, int &sImplode[]){
   string slImplode = "";
   for (int i = 0; i < ArraySize(sImplode); i++) {
      StringConcatenate(slImplode, slImplode,sImplode[i],sDelimiter);
   }
   return(StringSubstr(slImplode, 0, (StringLen(slImplode) - StringLen(sDelimiter))));
}
string StringImplode(string sDelimiter, double &sImplode[]){
   string slImplode = "";
   for (int i = 0; i < ArraySize(sImplode); i++) {
      StringConcatenate(slImplode, slImplode,sImplode[i],sDelimiter);
   }
   return(StringSubstr(slImplode, 0, (StringLen(slImplode) - StringLen(sDelimiter))));
}
string StringTrim(string text)
{
   StringTrimRight(text);
   StringTrimLeft(text);
   return(text);
}
double SymbolAsk(string symbol="")
{
   if (symbol=="") {symbol=GetSymbol();}
   return(SymbolInfoDouble(symbol,SYMBOL_ASK));
}
double SymbolBid(string symbol="")
{
   if (symbol=="") {symbol=GetSymbol();}
   return(SymbolInfoDouble(symbol,SYMBOL_BID));
}
int SymbolDigits(string symbol="")
{
   if (symbol=="") {symbol=GetSymbol();}
   return((int)SymbolInfoInteger(symbol,SYMBOL_DIGITS));
}
double SymbolLotSize(string symbol="")
{
	if (symbol=="") {symbol=Symbol();}
   return SymbolInfoDouble(symbol,SYMBOL_TRADE_CONTRACT_SIZE);
}
double SymbolLotStep(string symbol="")
{
   if (symbol=="") {symbol=Symbol();}
   return SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
}
double SymbolMaxLot(string symbol="")
{
   if (symbol=="") {symbol=Symbol();}
   return (SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX));
}
double SymbolMinLot(string symbol="")
{
   if (symbol=="") {symbol=Symbol();}
   return (SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN));
}
ENUM_TIMEFRAMES TFMigrate(int tf)
{
 switch(tf)
   {
    case 0: return(PERIOD_CURRENT);
    case 1: return(PERIOD_M1);
    case 5: return(PERIOD_M5);
    case 15: return(PERIOD_M15);
    case 30: return(PERIOD_M30);
    case 60: return(PERIOD_H1);
    case 240: return(PERIOD_H4);
    case 1440: return(PERIOD_D1);
    case 10080: return(PERIOD_W1);
    case 43200: return(PERIOD_MN1);
    
    case 2: return(PERIOD_M2);
    case 3: return(PERIOD_M3);
    case 4: return(PERIOD_M4);      
    case 6: return(PERIOD_M6);
    case 10: return(PERIOD_M10);
    case 12: return(PERIOD_M12);
    case 16385: return(PERIOD_H1);
    case 16386: return(PERIOD_H2);
    case 16387: return(PERIOD_H3);
    case 16388: return(PERIOD_H4);
    case 16390: return(PERIOD_H6);
    case 16392: return(PERIOD_H8);
    case 16396: return(PERIOD_H12);
    case 16408: return(PERIOD_D1);
    case 32769: return(PERIOD_W1);
    case 49153: return(PERIOD_MN1);
    default: return(PERIOD_CURRENT);
   }
}
double TicksData(string symbol="", int type=0, int shift=0)
{
   
   //return(MarketInfo(symbol,type));
   static bool collecting_ticks=false;
   //static string feeded_symbols[];
   static string symbols[];
   static int zero_sid[];
   static double memoryASK[][100];
   static double memoryBID[][100];
   int sid=0; int size=0; int i=0; int id=0;
   double ask=0, bid=0, retval=0;
   bool exists=false;
   
   if (ArraySize(symbols)==0)
   {
      ArrayResize(symbols,1);
      ArrayResize(zero_sid,1);
      ArrayResize(memoryASK,1);
      ArrayResize(memoryBID,1);
      
      symbols[0]=Symbol();
   }
   
   if (symbol=="") {symbol=Symbol();}
   
   if (type>0 && shift>0) {collecting_ticks=true;}
   if (collecting_ticks==false) {
      if (type>0 && shift==0) {
         // going to get ticks
      } else {return(0);}
   }
   
	if (type==0)
	{
      //StringExplode(",",symbol,feeded_symbols);
	   //for (s=0; s<ArraySize(feeded_symbols); s++)
	   //{
	      //symbol=feeded_symbols[s];
         //if (symbol=="") {symbol=Symbol();}
	      exists=false;
         size=ArraySize(symbols);
         if (size==0) {ArrayResize(symbols, 1);}
	      for (i=0; i<size; i++) {
	         if (symbols[i]==symbol) {exists=true; sid=i; break;}
	      }
         if (exists==false) {
            int newsize=ArraySize(symbols)+1;
            
            
            ArrayResize(symbols,newsize); symbols[newsize-1]=symbol;
            ArrayResize(zero_sid,newsize);
            ArrayResize(memoryASK,newsize);
            ArrayResize(memoryBID,newsize);
            sid=newsize;
         }
         if (sid>=0) {
            ask=SymbolInfoDouble(symbol,SYMBOL_ASK);
            bid=SymbolInfoDouble(symbol,SYMBOL_BID);
            if (bid==0 && MQLInfoInteger(MQL_TESTER)) {
               Print("Ticks data collector error: "+symbol+" cannot be backtested. Only the current symbol can be backtested. The EA will be terminated.");
               ExpertRemove();
            }
            if (symbol==Symbol() || ask!=memoryASK[sid][0] || bid!=memoryBID[sid][0])
            {
               memoryASK[sid][zero_sid[sid]]=ask;
               memoryBID[sid][zero_sid[sid]]=bid;
               zero_sid[sid]=zero_sid[sid]+1;
               if (zero_sid[sid]==100) {zero_sid[sid]=0;}
	         }
   	   }
      //}
   }
   else {
      if (shift<=0) {
         if (type==SYMBOL_ASK) {
            return(SymbolInfoDouble(symbol,SYMBOL_ASK));
         }
         else if (type==SYMBOL_BID) {
            return(SymbolInfoDouble(symbol,SYMBOL_BID)); 
         }
         else {
            double mid=((SymbolInfoDouble(symbol,SYMBOL_ASK)+SymbolInfoDouble(symbol,SYMBOL_BID))/2);
            return(mid);
         }
      }
      else {
         size=ArraySize(symbols);
         for (i=0; i<size; i++) {
            if (symbols[i]==symbol) {sid=i;}
         }
         if (shift<100) {
            id=zero_sid[sid]-shift-1; if(id<0) {id=id+100;}
            
            if (type==SYMBOL_ASK) {
               retval=(memoryASK[sid][id]);
               if (retval==0) {retval=SymbolInfoDouble(symbol,SYMBOL_ASK);}
            }
            else if (type==SYMBOL_BID) {
               retval=(memoryBID[sid][id]);
               if (retval==0) {retval=SymbolInfoDouble(symbol,SYMBOL_BID);}
            }
            //Print(shift+" "+id+" "+retval);
         }
      }
   }
   return(retval);
}
int TicksFromStart(bool upd=false)
{
   static int ticks=1;
   if (upd==true) {ticks++; if (ticks<0) ticks=0;}
   return(ticks);
}
datetime TimeAtStart(string cmd="server")
{
   static datetime local=0;
   static datetime server=0;
   
   if (cmd=="local") {return(local);}
   else if (cmd=="server") {return(server);}
   else if (cmd=="set") {
      local=TimeLocal();
      server=TimeCurrent();
   }
   return(0);
}
int TimeDay(datetime time)
{
	MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.day);
}
int TimeDayOfWeek(datetime time)
{
   MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.day_of_week);
}
datetime TimeFromComponents(bool local_time=false, int y=0, int m=0, int d=0, int h=0, int i=0, int s=0)
{
   MqlDateTime tm;
   if (local_time) {TimeLocal(tm);} else {TimeCurrent(tm);}

   if (y>0) {
      if (y<100) {y=2000+y;}
      tm.year = y;
   }
   if (m>0) {tm.mon = m;}
   if (d>0) {tm.day = d;}

   tm.hour  = h;
   tm.min   = i;
   tm.sec   = s;
   
   return StructToTime(tm);
}
int TimeHour(datetime time)
{
	MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.hour);
}
int TimeMinute(datetime time)
{
	MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.min);
}
int TimeMonth(datetime time)
{
	MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.mon);
}
int TimeSeconds(datetime time)
{
	MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.sec);
}
int TimeYear(datetime time)
{
   MqlDateTime tm;
   TimeToStruct(time,tm);
   return(tm.year);
}
void UpdateEventValues(ulong deal_ticket, string e_reason="", string e_detail="")
{
   e_Reason(true, e_reason);
   e_ReasonDetail(true, e_detail);
   e_attrClosePrice (true,HistoryDealGetDouble(deal_ticket,DEAL_PRICE));
   e_attrCloseTime  (true,0);
   e_attrComment    (true,HistoryDealGetString(deal_ticket,DEAL_COMMENT));
   e_attrCommission (true,HistoryDealGetDouble(deal_ticket,DEAL_COMMISSION));
   e_attrExpiration (true,0);
   e_attrLots       (true,HistoryDealGetDouble(deal_ticket,DEAL_VOLUME));
   e_attrMagicNumber(true,HistoryOrderGetInteger(HistoryDealGetInteger(deal_ticket,DEAL_POSITION_ID),ORDER_MAGIC));
   e_attrOpenPrice  (true,HistoryDealGetDouble(deal_ticket,DEAL_PRICE));
   e_attrOpenTime   (true,HistoryDealGetInteger(deal_ticket,DEAL_TIME));
   e_attrProfit     (true,HistoryDealGetDouble(deal_ticket,DEAL_PROFIT));
   e_attrStopLoss   (true,HistoryOrderGetDouble(HistoryDealGetInteger(deal_ticket,DEAL_ORDER),ORDER_SL));
   e_attrSymbol     (true,HistoryDealGetString(deal_ticket,DEAL_SYMBOL));
   e_attrSwap       (true,HistoryDealGetDouble(deal_ticket,DEAL_SWAP));
   e_attrTakeProfit (true,HistoryOrderGetDouble(HistoryDealGetInteger(deal_ticket,DEAL_ORDER),ORDER_TP));
   e_attrTicket     (true,deal_ticket);
   int type=(int)HistoryDealGetInteger(deal_ticket,DEAL_TYPE);
   if (e_reason=="close") {
      if (type==0) {type=1;}
      else if (type==1) {type=0;}
   }
   e_attrType(true,type);
}
void UpdateEventValues(position &data, string e_reason="", string e_detail="")
{
   e_Reason         (true,e_reason);
   e_ReasonDetail   (true,e_detail);
   e_attrClosePrice (true,data.price_current);
   e_attrCloseTime  (true,0);
   e_attrComment    (true,data.comment);
   e_attrCommission (true,data.comission);
   e_attrExpiration (true,0);
   e_attrLots       (true,data.volume);
   e_attrMagicNumber(true,data.magic);
   e_attrOpenPrice  (true,data.price_open);
   e_attrOpenTime   (true,data.time);
   e_attrProfit     (true,data.profit);
   e_attrStopLoss   (true,data.sl);
   e_attrSymbol     (true,data.symbol);
   e_attrSwap       (true,data.swap);
   e_attrTakeProfit (true,data.tp);
   e_attrTicket     (true,data.position_id);

   if (e_reason=="close") {
      if (data.type==0) {data.type=1;}
      else if (data.type==1) {data.type=0;}
   }
   
   e_attrType       (true,(int)data.type);
}
void UpdateEventValues(order &data, string e_reason="", string e_detail="")
{
   e_Reason(true, e_reason);
   e_ReasonDetail(true, e_detail);
   e_attrClosePrice (true,data.price_current);
   e_attrCloseTime  (true,data.time_done);
   e_attrComment    (true,data.comment);
   e_attrCommission (true,0);
   e_attrExpiration (true,data.time_expiration);
   e_attrLots       (true,data.volume_current);
   e_attrMagicNumber(true,data.magic);
   e_attrOpenPrice  (true,data.price_open);
   e_attrOpenTime   (true,data.time_setup);
   e_attrProfit     (true,0);
   e_attrStopLoss   (true,data.sl);
   e_attrSymbol     (true,data.symbol);
   e_attrSwap       (true,0);
   e_attrTakeProfit (true,data.tp);
   e_attrTicket     (true,data.ticket);
   e_attrType       (true,(int)data.type);
}
int WindowFindVisible(long chart_id, string term)
{
   //-- the search term can be chart name, such as Force(13), or subwindow index
   if (term == "" || term == "0") {return 0;}
   
   int subwindow = (int)StringToInteger(term);
   
   if (subwindow == 0 && StringLen(term) > 1)
   {
      subwindow = ChartWindowFind(chart_id, term);
   }
   
   if (subwindow > 0 && !ChartGetInteger(chart_id, CHART_WINDOW_IS_VISIBLE, subwindow))
   {
      return -1;  
   }
   
   return subwindow;
}
double ask(string symbol="")
{
   if (symbol=="") {symbol=GetSymbol();}
   return(SymbolInfoDouble(symbol,SYMBOL_ASK));
}
double attrLots() {return(attrVolume());}
ulong attrTicket(ulong Ticket=0)
{
   return(OrderTicket(Ticket));
}
double attrVolume() {
   if (LoadedType()==1){return(PositionGetDouble(POSITION_VOLUME));}
   if (LoadedType()==3){return(HistoryDealGetDouble(attrTicket(),DEAL_VOLUME));}
   if (LoadedType()==4){return(HistoryOrderGetDouble(attrTicket(),ORDER_VOLUME_INITIAL));}
   return(OrderGetDouble(ORDER_VOLUME_CURRENT));
}
string e_Reason(bool set=false, string inp="") {
   static string mem[250];
   int queue=OnTradeQueue()-1;
   if(set==true){
      mem[queue]=inp;
   }
   return(mem[queue]);
}
string e_ReasonDetail(bool set=false, string inp="") {static string mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrClosePrice(bool set=false, double inp=-1) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
datetime e_attrCloseTime(bool set=false, datetime inp=-1) {static datetime mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
string e_attrComment(bool set=false, string inp="") {static string mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrCommission(bool set=false, double inp=0) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
datetime e_attrExpiration(bool set=false, datetime inp=0) {static datetime mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrLots(bool set=false, double inp=-1) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
ulong e_attrMagicNumber(bool set=false, ulong inp=-1) {static ulong mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrOpenPrice(bool set=false, double inp=-1) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
datetime e_attrOpenTime(bool set=false,datetime inp=-1) {static datetime mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrProfit(bool set=false, double inp=0) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrStopLoss(bool set=false, double inp=-1) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrSwap(bool set=false, double inp=0) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
string e_attrSymbol(bool set=false, string inp="") {static string mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
double e_attrTakeProfit(bool set=false, double inp=-1) {static double mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
ulong e_attrTicket(bool set=false, ulong inp=-1) {static ulong mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
int e_attrType(bool set=false, int inp=-1) {static int mem[250];int queue=OnTradeQueue()-1;if(set==true){mem[queue]=inp;}return(mem[queue]);}
int iBarShift(string symbol,int timeframe,datetime time,bool exact=false)
{
   if(time<0) return(-1);
   ENUM_TIMEFRAMES tf=TFMigrate(timeframe);
   datetime Arr[],time1;
   CopyTime(symbol,tf,0,1,Arr);
   time1=Arr[0];
   if(CopyTime(symbol,tf,time,time1,Arr)>0)
     {
      if(ArraySize(Arr)>2) return(ArraySize(Arr)-1);
      if(time<time1) return(1);
      else return(0);
     }
   else return(-1);
}
int iCandleID(string SYMBOL, int TIMEFRAME, datetime time_stamp)
{
   bool TimeStampPrevDayShift = true;
   int CandleID = 0;
   //== calculate candle ID
   //-- get the time resolution of the desired period, in minutes
   int mins_tf = TIMEFRAME;
   int mins_tf0 = 0;
   if (TIMEFRAME == PERIOD_CURRENT)
   {
      //-- calculate the current period minutes
      //-- we need to calculate the difference in time between 2 candles
      // but because we have holidays, we will compare 2 neighbour candles until we get the same time difference
      int i=0;   
      while(true)
      {
         mins_tf = (int)(iTime(SYMBOL, TIMEFRAME, i) - iTime(SYMBOL, TIMEFRAME, i+1));
   
         if (mins_tf0 == mins_tf) {break;}
         mins_tf0 = mins_tf;
         i++;
      }
      mins_tf = mins_tf / 60;
   }
   
   //-- get the difference between now and the time we want, in minutes
   //int time_stamp = StrToTime(TimeStamp);
   int days_adjust = 0;
   if (TimeStampPrevDayShift)
   {
      //-- automatically shift to the previous day
      if (time_stamp > TimeCurrent())
      {
         time_stamp = time_stamp - 86400;
      }
      //-- also shift weekdays
      while (true)
      {
         int dow = TimeDayOfWeek(time_stamp);
         
         if (dow > 0 && dow < 6) {break;}
         time_stamp = time_stamp - 86400;
         days_adjust++;
      }
   }
   
   int mins_diff = (int)(TimeCurrent() - time_stamp);
   mins_diff = mins_diff - days_adjust*86400;
   mins_diff = mins_diff / 60;
   
   //-- the difference is negative => quit here
   if (mins_diff < 0) {return (int)EMPTY_VALUE;}
   
   //-- now calculate the candle ID, it is relative to the current time
   CandleID = (int)MathCeil((double)mins_diff/(double)mins_tf);
   
   //Print(TimeToStr(TimeCurrent())+" "+TimeToStr(time_stamp) +" ::: " + mins_tf + " " + days_adjust + " " + (days_adjust*1440/mins_tf) + " " + CandleID);
   
   
   //-- now, after all the shifting and in case of missing candles, the calculated candle id can be few candles early
   // so we will search for the right candle
   while(true)
   {
      if (iTime(SYMBOL, TIMEFRAME, CandleID) >= time_stamp) {break;}
      
      CandleID--;
   }
   
   return CandleID;
}
datetime iTime(string symbol,int timeframe,int shift)
{
   if(shift < 0) return(-1);
   ENUM_TIMEFRAMES tf=TFMigrate(timeframe);
   datetime Arr[];
   if(CopyTime(symbol, tf, shift, 1, Arr)>0)
        return(Arr[0]);
   else return(-1);
}
double toDigits(double pips,string symbol="")
{
   if (symbol=="") {symbol=GetSymbol();}
   return(
      NormalizeDouble(
         pips*PipValue(symbol)*SymbolInfoDouble(symbol,SYMBOL_POINT),
         (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS)
      )
   );
}
double toPips(double digits,string symbol="")
{
   if (symbol=="") {symbol=GetSymbol();}
   return(digits/(PipValue(symbol)*SymbolInfoDouble(symbol,SYMBOL_POINT)));
}
int CustomDigits(string symbol="") {
	if (symbol=="") {symbol=GetSymbol();}
	double point=CustomPoint(symbol);
	if (point==0) {return(0);}
	int digits=0;
	while(true) {
		if (point>=1) {break;}
		point=point*10;
		digits++;
	}
	return(digits);
}
double CustomPoint(string symbol="") {
	static string symbols[];
	static double points[];
	static string last_symbol="-";
	static double last_point=0;
	static int last_i=0;
	static int size=0;

	if (symbol=="") {symbol=GetSymbol();}
	if (symbol==last_symbol) {return(last_point);}

	int i=last_i;
	int start_i=i;
	bool found=false;
	if (size>0) {
		while(true) {
			if (symbols[i]==symbol) {
				last_symbol=symbol;
				last_point=points[i];
				last_i=i;
				return(last_point);
				break;
			}
			i++;
			if (i>=size) {i=0;}
			if (i==start_i) {break;}
		}
	}

	if (SymbolInfoInteger(symbol, SYMBOL_TIME)<=0) {Print("Market "+symbol+" does not exists!"); return(0);}

	i=size;
	size=size+1;
	ArrayResize(symbols, size);
	ArrayResize(points, size);
	symbols[i]=symbol;
	points[i]=0;
	last_symbol=symbol;
	last_i=i;

	if (points[i]==0) {points[i]=SymbolInfoDouble(symbol, SYMBOL_POINT);}
	last_point=points[i];
	return(last_point);
}


//+------------------------------------------------------------------+
//| END                                                              |
//| Created with fxDreema EA Builder           https://fxdreema.com/ |
//+------------------------------------------------------------------+
/*<fxdreema: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
:fxdreema>*/