diff --git a/Experts/Articles/481.zip b/Experts/Articles/481.zip new file mode 100644 index 0000000..42df5e1 Binary files /dev/null and b/Experts/Articles/481.zip differ diff --git a/Experts/Articles/481/ctrade_sample_ea.mq5 b/Experts/Articles/481/ctrade_sample_ea.mq5 new file mode 100644 index 0000000..bfeefbf --- /dev/null +++ b/Experts/Articles/481/ctrade_sample_ea.mq5 @@ -0,0 +1,393 @@ +//+------------------------------------------------------------------+ +//| CTrade_Sample_EA.mq5 | +//| Copyright 2012, MetaQuotes Software Corp. | +//| http://www.mql5.com | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2012, MetaQuotes Software Corp." +#property link "http://www.mql5.com" +#property version "1.00" +#include +#property description "This Expert Advisor shows some examples of working " +#property description "with CTrade class. Its functions are not called." + +//--- object for performing trade operations +CTrade trade; +//+------------------------------------------------------------------+ +//| Expert initialization function | +//+------------------------------------------------------------------+ +int OnInit() + { +//--- set MagicNumber for your orders identification + int MagicNumber=123456; + trade.SetExpertMagicNumber(MagicNumber); +//--- set available slippage in points when buying/selling + int deviation=10; + trade.SetDeviationInPoints(deviation); +//--- order execution mode + trade.SetTypeFilling(ORDER_FILLING_RETURN); +//--- logging mode: it would be better not to declare this method at all, the class will set the best mode on its own + trade.LogLevel(1); +//--- what function is to be used for trading: true - OrderSendAsync(), false - OrderSend() + trade.SetAsyncMode(true); +//--- + return(0); + } +//+------------------------------------------------------------------+ +//| Expert deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { +//--- + + } +//+------------------------------------------------------------------+ +//| Expert tick function | +//+------------------------------------------------------------------+ +void OnTick() + { +//--- + + } +//--- Buy sample +//+------------------------------------------------------------------+ +//| Buying a specified volume at the current symbol | +//+------------------------------------------------------------------+ +void BuySample1() + { +//--- 1. example of buying at the current symbol + if(!trade.Buy(0.1)) + { + //--- failure message + Print("Buy() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//+------------------------------------------------------------------+ +//| Buying with specified volume and symbol | +//+------------------------------------------------------------------+ +void BuySample2() + { +//--- 2. example of buying at the specified symbol + if(!trade.Buy(0.1,"GBPUSD")) + { + //--- failure message + Print("Buy() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//+------------------------------------------------------------------+ +//| Buying with specifying all order parameters | +//+------------------------------------------------------------------+ +void BuySample3() + { +//--- 3. example of buying at the specified symbol with specified SL and TP + double volume=0.1; // specify a trade operation volume + string symbol="GBPUSD"; //specify the symbol, for which the operation is performed + int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places + double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point + double bid=SymbolInfoDouble(symbol,SYMBOL_BID); // current price for closing LONG + double SL=bid-1000*point; // unnormalized SL value + SL=NormalizeDouble(SL,digits); // normalizing Stop Loss + double TP=bid+1000*point; // unnormalized TP value + TP=NormalizeDouble(TP,digits); // normalizing Take Profit +//--- receive the current open price for LONG positions + double open_price=SymbolInfoDouble(symbol,SYMBOL_ASK); + string comment=StringFormat("Buy %s %G lots at %s, SL=%s TP=%s", + symbol,volume, + DoubleToString(open_price,digits), + DoubleToString(SL,digits), + DoubleToString(TP,digits)); + if(!trade.Buy(volume,symbol,open_price,SL,TP,comment)) + { + //--- failure message + Print("Buy() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//--- Examples for placing a limit order +//+------------------------------------------------------------------+ +//| Placing a limit order at the current symbol | +//+------------------------------------------------------------------+ +void BuyLimit_Sample1() + { +//--- 1. example of placing a Buy Limit pending order + string symbol="GBPUSD"; // specify the symbol, at which the order is placed + int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places + double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point + double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price + double price=1000*point; // unnormalized open price + price=NormalizeDouble(price,digits); // normalizing open price +//--- everything is ready, sending a Buy Limit pending order to the server + if(!trade.BuyLimit(0.1,price)) + { + //--- failure message + Print("BuyLimit() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("BuyLimit() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//+------------------------------------------------------------------+ +//| Placing a limit order specifying all the parameters | +//+------------------------------------------------------------------+ +void BuyLimit_Sample2() + { +//--- 2. example of placing a Buy Limit pending order with all parameters + double volume=0.1; + string symbol="GBPUSD"; // specify the symbol, at which the order is placed + int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places + double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point + double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price + double price=1000*point; // unnormalized open price + price=NormalizeDouble(price,digits); // normalizing open price + int SL_pips=300; // Stop Loss in points + int TP_pips=500; // Take Profit in points + double SL=price-SL_pips*point; // unnormalized SL value + SL=NormalizeDouble(SL,digits); // normalizing Stop Loss + double TP=price+TP_pips*point; // unnormalized TP value + TP=NormalizeDouble(TP,digits); // normalizing Take Profit + datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_D1); + string comment=StringFormat("Buy Limit %s %G lots at %s, SL=%s TP=%s", + symbol,volume, + DoubleToString(price,digits), + DoubleToString(SL,digits), + DoubleToString(TP,digits)); +//--- everything is ready, sending a Buy Limit pending order to the server + if(!trade.BuyLimit(volume,price,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment)) + { + //--- failure message + Print("BuyLimit() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("BuyLimit() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//--- Examples for placing a stop order +//+------------------------------------------------------------------+ +//| Placing a stop order at the current symbol | +//+------------------------------------------------------------------+ +void BuyStop_Sample1() + { +//--- 1. example of placing a Buy Stop pending order + string symbol="USDJPY"; // specify the symbol, at which the order is placed + int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places + double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point + double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price + double price=1000*point; // unnormalized open price + price=NormalizeDouble(price,digits); // normalizing open price +//--- everything is ready, sending a Buy Stop pending order to the server + if(!trade.BuyStop(0.1,price)) + { + //--- failure message + Print("BuyStop() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("BuyStop() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//+------------------------------------------------------------------+ +//| Placing a stop order specifying all the parameters | +//+------------------------------------------------------------------+ +void BuyStop_Sample2() + { +//--- 2. example of placing a Buy Stop pending order with all parameters + double volume=0.1; + string symbol="USDJPY"; // specify the symbol, at which the order is placed + int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); // number of decimal places + double point=SymbolInfoDouble(symbol,SYMBOL_POINT); // point + double ask=SymbolInfoDouble(symbol,SYMBOL_ASK); // current buy price + double price=1000*point; // unnormalized open price + price=NormalizeDouble(price,digits); // normalizing open price + int SL_pips=300; // Stop Loss in points + int TP_pips=500; // Take Profit in points + double SL=price-SL_pips*point; // unnormalized SL value + SL=NormalizeDouble(SL,digits); // normalizing Stop Loss + double TP=price+TP_pips*point; // unnormalized TP value + TP=NormalizeDouble(TP,digits); // normalizing Take Profit + datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_D1); + string comment=StringFormat("Buy Stop %s %G lots at %s, SL=%s TP=%s", + symbol,volume, + DoubleToString(price,digits), + DoubleToString(SL,digits), + DoubleToString(TP,digits)); +//--- everything is ready, sending a Buy Stop pending order to the server + if(!trade.BuyStop(volume,price,symbol,SL,TP,ORDER_TIME_GTC,expiration,comment)) + { + //--- failure message + Print("BuyStop() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("BuyStop() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//--- Examples for working with positions +//+------------------------------------------------------------------+ +//| Position opening | +//+------------------------------------------------------------------+ +void Open() + { +//--- number of decimal places + int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS); +//--- point value + double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT); +//--- receiving a buy price + double price=SymbolInfoDouble(_Symbol,SYMBOL_ASK); +//--- calculate and normalize SL and TP levels + double SL=NormalizeDouble(price-1000*point,digits); + double TP=NormalizeDouble(price+1000*point,digits); +//--- filling comments + string comment="Buy "+_Symbol+" 0.1 at "+DoubleToString(price,digits); +//--- everything is ready, trying to open a buy position + if(!trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,0.1,price,SL,TP,comment)) + { + //--- failure message + Print("PositionOpen() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("PositionOpen() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//+------------------------------------------------------------------+ +//| Closing a position specifying only a symbol | +//+------------------------------------------------------------------+ +void Close() + { +//--- closing a position at the current symbol + if(!trade.PositionClose(_Symbol)) + { + //--- failure message + Print("PositionClose() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("PositionClose() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//+------------------------------------------------------------------+ +//| Modification for Long position of StopLoss and TakeProfit levels| +//+------------------------------------------------------------------+ +void ModifyPosition() + { +//--- number of decimal places + int digits=(int)SymbolInfoInteger(_Symbol,SYMBOL_DIGITS); +//--- point value + double point=SymbolInfoDouble(_Symbol,SYMBOL_POINT); +//--- receiving the current Bid price + double price=SymbolInfoDouble(_Symbol,SYMBOL_BID); +//--- calculate and normalize SL and TP levels + double SL=NormalizeDouble(price-1000*point,digits); + double TP=NormalizeDouble(price+1000*point,digits); +//--- everything is ready, trying to modify the buy position + if(!trade.PositionModify(_Symbol,SL,TP)) + { + //--- failure message + Print("Ìåòîä PositionModify() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("PositionModify() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//--- Examples for working with orders +//+------------------------------------------------------------------+ +//| Deleting an order by its ticket | +//+------------------------------------------------------------------+ +void DeleteOrder() + { +//--- this is a sample order ticket, it should be received + ulong ticket=1234556; +//--- everything is ready, trying to modify the buy position + if(!trade.OrderDelete(ticket)) + { + //--- failure message + Print("OrderDelete() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("OrderDelete() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } +//+------------------------------------------------------------------+ +//| Modifying a pending order | +//+------------------------------------------------------------------+ +void ModifyOrder() + { +//--- this is a sample order ticket, it should be received + ulong ticket=1234556; +//--- this is a sample symbol, it should be received + string symbol="EURUSD"; +//--- number of decimal places + int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); +//--- point value + double point=SymbolInfoDouble(symbol,SYMBOL_POINT); +//--- receiving a buy price + double price=SymbolInfoDouble(symbol,SYMBOL_ASK); +//--- calculate and normalize SL and TP levels +//--- they should be calculated based on the order type + double SL=NormalizeDouble(price-1000*point,digits); + double TP=NormalizeDouble(price+1000*point,digits); + //--- setting one day as a lifetime + datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_D1); +//--- everything is ready, trying to modify the order + if(!trade.OrderModify(ticket,price,SL,TP,ORDER_TIME_GTC,expiration)) + { + //--- failure message + Print("OrderModify() method failed. Return code=",trade.ResultRetcode(), + ". Code description: ",trade.ResultRetcodeDescription()); + } + else + { + Print("OrderModify() method executed successfully. Return code=",trade.ResultRetcode(), + " (",trade.ResultRetcodeDescription(),")"); + } +//--- + } + +//+------------------------------------------------------------------+ diff --git a/Experts/Articles/481/demo_caccountinfo.mq5 b/Experts/Articles/481/demo_caccountinfo.mq5 new file mode 100644 index 0000000..bef12ab --- /dev/null +++ b/Experts/Articles/481/demo_caccountinfo.mq5 @@ -0,0 +1,69 @@ +//+------------------------------------------------------------------+ +//| Demo_CAccountInfo.mq5 | +//| Copyright 2012, MetaQuotes Software Corp. | +//| http://www.mql5.com | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2012, MetaQuotes Software Corp." +#property link "http://www.mql5.com" +#property version "1.00" + +#include +//+------------------------------------------------------------------+ +//| Expert initialization function | +//+------------------------------------------------------------------+ +int OnInit() + { +//--- object for working with the account + CAccountInfo account; +//--- receiving the account number, the Expert Advisor is launched at + long login=account.Login(); + Print("Login=",login); +//--- clarifying account type + ENUM_ACCOUNT_TRADE_MODE account_type=account.TradeMode(); +//--- if the account is real, the Expert Advisor is stopped immediately! + if(account_type==ACCOUNT_TRADE_MODE_REAL) + { + MessageBox("Trading on a real account is forbidden, disabling","The Expert Advisor has been launched on a real account!"); + return(-1); + } +//--- displaying the account type + Print("Account type: ",EnumToString(account_type)); +//--- clarifying if we can trade on this account + if(account.TradeAllowed()) + Print("Trading on this account is allowed"); + else + Print("Trading on this account is forbidden: you may have entered using the Investor password"); +//--- clarifying if we can use an Expert Advisor on this account + if(account.TradeExpert()) + Print("Automated trading on this account is allowed"); + else + Print("Automated trading using Expert Advisors and scripts on this account is forbidden"); +//--- if the permissible number of orders has been set + int orders_limit=account.LimitOrders(); + if(orders_limit!=0)Print("Maximum permissible amount of active pending orders: ",orders_limit); +//--- displaying company and server names + Print(account.Company(),": server ",account.Server()); +//--- displaying balance and current profit on the account in the end + Print("Balance=",account.Balance()," Profit=",account.Profit()," Equity=",account.Equity()); +//--- final display + Print(__FUNCTION__," completed"); +//--- + return(0); + } +//+------------------------------------------------------------------+ +//| Expert deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { +//--- + + } +//+------------------------------------------------------------------+ +//| Expert tick function | +//+------------------------------------------------------------------+ +void OnTick() + { +//--- + + } +//+------------------------------------------------------------------+ diff --git a/Experts/Articles/481/demo_csymbolinfo.mq5 b/Experts/Articles/481/demo_csymbolinfo.mq5 new file mode 100644 index 0000000..ecf612e --- /dev/null +++ b/Experts/Articles/481/demo_csymbolinfo.mq5 @@ -0,0 +1,69 @@ +//+------------------------------------------------------------------+ +//| Demo_CSymbolInfo.mq5 | +//| Copyright 2012, MetaQuotes Software Corp. | +//| http://www.mql5.com | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2012, MetaQuotes Software Corp." +#property link "http://www.mql5.com" +#property version "1.00" + +#include +//+------------------------------------------------------------------+ +//| Expert initialization function | +//+------------------------------------------------------------------+ +int OnInit() + { +//--- object for receiving symbol settings + CSymbolInfo symbol_info; +//--- set the name for the appropriate symbol + symbol_info.Name(_Symbol); +//--- receive current rates and display + symbol_info.RefreshRates(); + Print(symbol_info.Name()," (",symbol_info.Description(),")", + " Bid=",symbol_info.Bid()," Ask=",symbol_info.Ask()); +//--- receive minimum freeze levels for trade operations + Print("StopsLevel=",symbol_info.StopsLevel()," pips, FreezeLevel=", + symbol_info.FreezeLevel()," pips"); +//--- receive the number of decimal places and point size + Print("Digits=",symbol_info.Digits(), + ", Point=",DoubleToString(symbol_info.Point(),symbol_info.Digits())); +//--- spread data + Print("SpreadFloat=",symbol_info.SpreadFloat(),", Spread(current)=", + symbol_info.Spread()," pips"); +//--- request order execution type for limitations + Print("Limitations for trade operations: ",EnumToString(symbol_info.TradeMode()), + " (",symbol_info.TradeModeDescription(),")"); +//--- clarifying trades execution mode + Print("Trades execution mode: ",EnumToString(symbol_info.TradeExecution()), + " (",symbol_info.TradeExecutionDescription(),")"); +//--- clarifying contracts price calculation method + Print("Contract price calculation: ",EnumToString(symbol_info.TradeCalcMode()), + " (",symbol_info.TradeCalcModeDescription(),")"); +//--- contracts' size + Print("Standard contract size: ",symbol_info.ContractSize(), + " (",symbol_info.CurrencyBase(),")"); +//--- minimum and maximum volumes in trade operations + Print("Volume info: LotsMin=",symbol_info.LotsMin()," LotsMax=",symbol_info.LotsMax(), + " LotsStep=",symbol_info.LotsStep()); +//--- final display + Print(__FUNCTION__," completed"); +//--- + return(0); + } +//+------------------------------------------------------------------+ +//| Expert deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { +//--- + + } +//+------------------------------------------------------------------+ +//| Expert tick function | +//+------------------------------------------------------------------+ +void OnTick() + { +//--- + + } +//+------------------------------------------------------------------+ diff --git a/Experts/Articles/481/demo_ctrade.mq5 b/Experts/Articles/481/demo_ctrade.mq5 new file mode 100644 index 0000000..4f0b507 --- /dev/null +++ b/Experts/Articles/481/demo_ctrade.mq5 @@ -0,0 +1,49 @@ +//+------------------------------------------------------------------+ +//| Demo_CTrade.mq5 | +//| Copyright 2012, MetaQuotes Software Corp. | +//| http://www.mql5.com | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2012, MetaQuotes Software Corp." +#property link "http://www.mql5.com" +#property version "1.00" + +#include +//--- object for performing trade operations +CTrade trade; +//+------------------------------------------------------------------+ +//| Expert initialization function | +//+------------------------------------------------------------------+ +int OnInit() + { +//--- set MagicNumber for your orders identification + int MagicNumber=123456; + trade.SetExpertMagicNumber(MagicNumber); +//--- set available slippage in points when buying/selling + int deviation=10; + trade.SetDeviationInPoints(deviation); +//--- order execution mode + trade.SetTypeFilling(ORDER_FILLING_RETURN); +//--- logging mode + trade.LogLevel(1); // it would be better not to declare this method at all, the class will set the best mode on its own +//--- what function is to be used for trading: true - OrderSendAsync(), false - OrderSend() +trade.SetAsyncMode(true); +//--- + return(0); + } +//+------------------------------------------------------------------+ +//| Expert deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) + { +//--- + + } +//+------------------------------------------------------------------+ +//| Expert tick function | +//+------------------------------------------------------------------+ +void OnTick() + { +//--- + + } +//+------------------------------------------------------------------+ diff --git a/Experts/Downloads/Exp_GStopLoss.mq5 b/Experts/Downloads/Exp_GStopLoss.mq5 new file mode 100644 index 0000000..4d9dd05 Binary files /dev/null and b/Experts/Downloads/Exp_GStopLoss.mq5 differ diff --git a/Experts/Downloads/Opening_and_ilosing_on_time.mq5 b/Experts/Downloads/Opening_and_ilosing_on_time.mq5 new file mode 100644 index 0000000..feb254e Binary files /dev/null and b/Experts/Downloads/Opening_and_ilosing_on_time.mq5 differ diff --git a/Experts/Downloads/RobotPowerM5 meta4V12.mq5 b/Experts/Downloads/RobotPowerM5 meta4V12.mq5 new file mode 100644 index 0000000..73966bc Binary files /dev/null and b/Experts/Downloads/RobotPowerM5 meta4V12.mq5 differ diff --git a/Experts/TradePad/classchart.mqh b/Experts/TradePad/classchart.mqh new file mode 100644 index 0000000..779f3ab --- /dev/null +++ b/Experts/TradePad/classchart.mqh @@ -0,0 +1,297 @@ +//+------------------------------------------------------------------+ +//| CChart.mqh | +//| Copyright © 2009, MetaQuotes Software Corp. | +//| http://www.metaquotes.net | +//+------------------------------------------------------------------+ +#property copyright "Copyright © 2009, MetaQuotes Software Corp." +#property link "http://www.metaquotes.net" + +#include "ClassControlButton.mqh" +#define UP "\x0431" +#define DOWN "\x0432" + +ENUM_TIMEFRAMES periods[21]; +//+------------------------------------------------------------------+ +//| class for implemeting a chart with controls | +//+------------------------------------------------------------------+ +class CChart + { +private: + int m_top; // Y coordinate of the upper-left corner + int m_left; // X coordinate of the upper-left corner + int m_width; // width + int m_height; // height + ENUM_TIMEFRAMES m_time_frame; // timeframe + int m_scaling; // current scale + string m_symbol; // Chart symbol + string m_chart_name; // Chart object name + int m_control_width; // button width + int m_control_height; // button height + CControlButton m_controls[6]; // array of chart managing controls + bool m_first_launch; // first launch attribute + int m_period_counter; +public: + void CChart(); + void CreateChart(int l,int t,int w,int h,string s,string name); + void MoveChart(int x,int y); + void SetSymbolForChart(string symbol); + void UpScaleChart(); + void DownScaleChart(); + void DeleteChart(); + bool IsChartControlEvent(string control_name); + void DoChartOperations(string name); + ENUM_TIMEFRAMES GetChartTimeframe(){return(periods[m_period_counter]);}; + }; +//+------------------------------------------------------------------+ +//| default constructor | +//+------------------------------------------------------------------+ +void CChart::CChart() + { + m_top=0; + m_left=0; + m_time_frame=ChartPeriod(0); + m_symbol=ChartSymbol(0); + m_scaling=2; + m_control_width=30; + m_control_height=42; + m_first_launch=true; + periods[0]=PERIOD_M1; + periods[1]=PERIOD_M2; + periods[2]=PERIOD_M3; + periods[3]=PERIOD_M4; + periods[4]=PERIOD_M5; + periods[5]=PERIOD_M6; + periods[6]=PERIOD_M10; + periods[7]=PERIOD_M12; + periods[8]=PERIOD_M15; + periods[9]=PERIOD_M20; + periods[10]=PERIOD_M30; + periods[11]=PERIOD_H1; + periods[12]=PERIOD_H2; + periods[13]=PERIOD_H3; + periods[14]=PERIOD_H4; + periods[15]=PERIOD_H6; + periods[16]=PERIOD_H8; + periods[17]=PERIOD_H12; + periods[18]=PERIOD_D1; + periods[19]=PERIOD_W1; + periods[20]=PERIOD_MN1; + } +//+------------------------------------------------------------------+ +//| returns true if the managing control is pressed | +//+------------------------------------------------------------------+ +bool CChart::IsChartControlEvent(string control_name) + { + bool res=false; + for(int i=0;i<6;i++) + { + if(m_controls[i].GetControlName()==control_name)return(true); + } + return(res); + } +//+------------------------------------------------------------------+ +//| delete class graphical objects | +//+------------------------------------------------------------------+ +void CChart::DeleteChart() + { + if(ObjectFind(0,m_chart_name)>=0) ObjectDelete(0,m_chart_name); + for(int i=0;i<6;i++) + { + m_controls[i].DeleteControl(); + } + } +//+------------------------------------------------------------------+ +//| create an object with specified parameters | +//+------------------------------------------------------------------+ +void CChart::CreateChart(int l,int t,int w,int h,string s,string name) + { + for(int p=0;p<21;p++) + { + int tempPer=(int)ChartPeriod(0); + if((int)periods[p]==(int)ChartPeriod(0)) + { + m_period_counter=p; + break; + } + } +//Print("m_period_counter=",m_period_counter, " periods=",periods[m_period_counter]); +//Print("PERIOD_H4=",PERIOD_H4); +//Print("ChartPeriod(0)=",ChartPeriod(0)); + m_width=w; + m_height=h; + m_chart_name=name; + Print("Trying to create Chart object named ",m_chart_name); + if(ObjectFind(0,m_chart_name)<0)ObjectCreate(0,m_chart_name,OBJ_CHART,0,0,0,0,0); + SetSymbolForChart(s); + MoveChart(l,t); + m_first_launch=false; +//Print("Get chart width=",w," set chart width=",m_width-m_control_width); +//Print("Get chart height=",h," set chart height=",m_height); + ObjectSetInteger(0,m_chart_name,OBJPROP_XSIZE,m_width-m_control_width); +//Print("Width is set"); + ObjectSetInteger(0,m_chart_name,OBJPROP_YSIZE,m_height); +//Print("Height is set"); + ObjectSetInteger(0,m_chart_name,OBJPROP_SELECTABLE,0); +//Print("OBJPROP_SELECTABL is set"); + int left_controls=l+w-m_control_width; + int top_contols=t; +//Print("Starting placing buttons with X:Y=>",left_controls,":",top_contols); + m_controls[0].CreateButton(left_controls,top_contols, + m_control_width,m_control_height,"Scale +",UP); + m_controls[0].SetTextDetails(8,"Wingdings",White); + m_controls[0].SetTextForControl(UP); + + m_controls[1].CreateButton(left_controls,top_contols+m_control_height, + m_control_width,m_control_height,"Show Price","P"); + m_controls[1].SetTextForControl("P"); + m_controls[1].SetTextDetails(10,"Arial",White); + + m_controls[2].CreateButton(left_controls,top_contols+2*m_control_height, + m_control_width,m_control_height,"Scale -",DOWN); + m_controls[2].SetTextDetails(8,"Wingdings",White); + m_controls[2].SetTextForControl(DOWN); + + m_controls[3].CreateButton(left_controls,top_contols+3*m_control_height, + m_control_width,m_control_height,"Time Frame Up",UP); + m_controls[3].SetTextDetails(8,"Wingdings",White); + m_controls[3].SetTextForControl(UP); + + m_controls[4].CreateButton(left_controls,top_contols+4*m_control_height, + m_control_width,m_control_height,"Show Time","T"); + m_controls[4].SetTextForControl("T"); + m_controls[4].SetTextDetails(10,"Arial",White); + + m_controls[5].CreateButton(left_controls,top_contols+5*m_control_height, + m_control_width,m_control_height,"Time Frame Down",DOWN); + m_controls[5].SetTextDetails(8,"Wingdings",White); + m_controls[5].SetTextForControl(DOWN); + + for(int i=0;i<6;i++) + { + if(i<3) m_controls[i].SetBGColor(CadetBlue); + else m_controls[i].SetBGColor(SeaGreen); + } + ObjectSetInteger(0,"Show Price",OBJPROP_STATE,ObjectGetInteger(0,m_chart_name,OBJPROP_PRICE_SCALE)); + ObjectSetInteger(0,"Show Time",OBJPROP_STATE,ObjectGetInteger(0,m_chart_name,OBJPROP_DATE_SCALE)); + } +//+------------------------------------------------------------------+ +//| chart buttons pressing event | +//+------------------------------------------------------------------+ +void CChart::DoChartOperations(string name) + { +//Print("Test DoChartOperations(), name=",name); + if(name=="Show Time") + { + bool showdates=ObjectGetInteger(0,name,OBJPROP_STATE); + ObjectSetInteger(0,m_chart_name,OBJPROP_DATE_SCALE,showdates); + } + + if(name=="Show Price") + { + bool showdates=ObjectGetInteger(0,name,OBJPROP_STATE); + ObjectSetInteger(0,m_chart_name,OBJPROP_PRICE_SCALE,showdates); + } + + if(name=="Scale +") + { + UpScaleChart(); + Sleep(100); + ObjectSetInteger(0,name,OBJPROP_STATE,false); + } + + if(name=="Scale -") + { + DownScaleChart(); + Sleep(100); + ObjectSetInteger(0,name,OBJPROP_STATE,false); + } + + if(name=="Time Frame Up") + { + if(m_period_counter<20) + { + m_period_counter++; + ObjectSetInteger(0,m_chart_name,OBJPROP_PERIOD,periods[m_period_counter]); + } + Sleep(100); + ObjectSetInteger(0,name,OBJPROP_STATE,false); + } + + if(name=="Time Frame Down") + { + if(m_period_counter>0) + { + m_period_counter--; + ObjectSetInteger(0,m_chart_name,OBJPROP_PERIOD,periods[m_period_counter]); + } + Sleep(100); + ObjectSetInteger(0,name,OBJPROP_STATE,false); + } + + } +//+------------------------------------------------------------------+ +//| set the symbol | +//+------------------------------------------------------------------+ +void CChart::SetSymbolForChart(string symbol) + { + m_symbol=symbol; + ObjectSetString(0,m_chart_name,OBJPROP_SYMBOL,symbol); + } +//+------------------------------------------------------------------+ +//| move to the specified coordinates | +//+------------------------------------------------------------------+ +void CChart::MoveChart(int x,int y) + { + m_left+=x; + m_top+=y; + ObjectSetInteger(0,m_chart_name,OBJPROP_XDISTANCE,m_left); + ObjectSetInteger(0,m_chart_name,OBJPROP_YDISTANCE,m_top); + if(m_first_launch) return; + for(int i=0;i<6;i++) + { + m_controls[i].MoveControlButton(x,y); + } + } +//+------------------------------------------------------------------+ +//| zoom in the chart | +//+------------------------------------------------------------------+ +void CChart::UpScaleChart() + { +//Print(__FUNCTION__,"m_scaling =",m_scaling); + if(m_scaling<5) + { + m_scaling++; + Print(__FUNCTION__,"Set the chart scale =",m_scaling); + bool changed=ObjectSetInteger(0,m_chart_name,OBJPROP_CHART_SCALE,m_scaling); + if(!changed) + { + Print(__FUNCTION__,"Failed to zoom in the chart. Error="+string(GetLastError())); + } + else + { + Print("Chart scale =",ObjectGetInteger(0,m_chart_name,OBJPROP_CHART_SCALE)); + } + } + } +//+------------------------------------------------------------------+ +//| zoom out the chart | +//+------------------------------------------------------------------+ +void CChart::DownScaleChart() + { +//Print(__FUNCTION__,"m_scaling =",m_scaling); + if(m_scaling>0) + { + m_scaling--; + Print(__FUNCTION__,"Set the chart scale =",m_scaling); + bool changed=ObjectSetInteger(0,m_chart_name,OBJPROP_CHART_SCALE,m_scaling); + if(!changed) + { + Print(__FUNCTION__,"Failed to zoom out the chart. Error="+string(GetLastError())); + } + else + { + Print("Chart scale =",ObjectGetInteger(0,m_chart_name,OBJPROP_CHART_SCALE)); + } + } + } +//+------------------------------------------------------------------+ diff --git a/Experts/TradePad/classcontrolbutton.mqh b/Experts/TradePad/classcontrolbutton.mqh new file mode 100644 index 0000000..373f8cf --- /dev/null +++ b/Experts/TradePad/classcontrolbutton.mqh @@ -0,0 +1,118 @@ +//+------------------------------------------------------------------+ +//| CControlButton.mqh | +//| Copyright © 2009, MetaQuotes Software Corp. | +//| http://www.metaquotes.net | +//+------------------------------------------------------------------+ +#property copyright "Copyright © 2009, MetaQuotes Software Corp." +#property link "http://www.metaquotes.net" +//+------------------------------------------------------------------+ +//| control object | +//+------------------------------------------------------------------+ +class CControlButton + { +private: + string m_control_name; // control's unique name + int m_top; // Y coordinate of the upper-left corner + int m_left; // X coordinate of the upper-left corner + int m_width; // control width + int m_heigt; // control height + string m_text; // control text + string m_font; // text font + int m_text_size; // control text size + color m_text_color; // text color + color m_bg_color; // background color +public: + void CControlButton(){m_top=0; m_left=0;m_text_size=10;m_font="Arial";m_bg_color=Blue;}; + void CreateButton(int l,int t,int w,int h,string button_name,string button_text); + void MoveControlButton(int shiftX,int shiftY); + void SetTextDetails(int text_size,string font_name,color text_color); + void SetTextForControl(string text); + void SetWidthAndHeight(int w,int h); + void SetBGColor(color bg_color); + void DeleteControl(); + string GetControlName(){return(m_control_name);}; + }; +//+------------------------------------------------------------------+ +//| create the control | +//+------------------------------------------------------------------+ +void CControlButton::CreateButton(int l,int t,int w,int h, + string button_name,string button_text) + { + m_top=0; + m_left=0; + m_control_name=button_name; + //Print("CreateButton function is creating control named ",button_name); + if(ObjectFind(0,m_control_name)<0) ObjectCreate(0,m_control_name,OBJ_BUTTON,0,0,0,0,0); + SetWidthAndHeight(w,h); + MoveControlButton(l,t); + ObjectSetInteger(0,m_control_name,OBJPROP_SELECTABLE,false); + + } +//+------------------------------------------------------------------+ +//| delete the control | +//+------------------------------------------------------------------+ +void CControlButton::DeleteControl() + { + if(ObjectFind(0,m_control_name)>=0) + { + if(!ObjectDelete(0,m_control_name)) + { + Print("Failed to delete the object named ",m_control_name,"! Error #",GetLastError()); + } + } + } +//+------------------------------------------------------------------+ +//| move control along the axes by the specified values | +//+------------------------------------------------------------------+ +void CControlButton::MoveControlButton(int shiftX,int shiftY) + { + m_top+=shiftY; + m_left+=shiftX; + ObjectSetInteger(0,m_control_name,OBJPROP_XDISTANCE,m_left); + ObjectSetInteger(0,m_control_name,OBJPROP_YDISTANCE,m_top); + } +//+------------------------------------------------------------------+ +//| set control's height and width | +//+------------------------------------------------------------------+ +void CControlButton::SetWidthAndHeight(int w,int h) + { + m_width=w; + m_heigt=h; + ObjectSetInteger(0,m_control_name,OBJPROP_XSIZE,m_width); + ObjectSetInteger(0,m_control_name,OBJPROP_YSIZE,m_heigt); + } +//+------------------------------------------------------------------+ +//| set control text attributes | +//+------------------------------------------------------------------+ +void CControlButton::SetTextDetails(int text_size, + string font_name,color text_color) + { + m_text_size=text_size; + m_font=font_name; + m_text_color=text_color; + //Print("Start setting attributes for the button named ",m_control_name); + ObjectSetInteger(0,m_control_name,OBJPROP_COLOR,text_color); + //Print("Button text color is set ",m_control_name); + ObjectSetString(0,m_control_name,OBJPROP_FONT,font_name); + //Print("Button text font is set ",m_control_name); + ObjectSetInteger(0,m_control_name,OBJPROP_FONTSIZE,m_text_size); + //Print("Button text font size is set ",m_control_name); + } +//+------------------------------------------------------------------+ +//| set control text | +//+------------------------------------------------------------------+ +void CControlButton::SetTextForControl(string text) + { + m_text=text; + //Print("Set control text:",text); + ObjectSetString(0,m_control_name,OBJPROP_TEXT,m_text); + } +//+------------------------------------------------------------------+ +//| set control background color | +//+------------------------------------------------------------------+ +void CControlButton::SetBGColor(color bg_color) + { + m_bg_color=bg_color; + ObjectSetInteger(0,m_control_name,OBJPROP_BGCOLOR,m_bg_color); + } +//+------------------------------------------------------------------+ diff --git a/Experts/TradePad/classsymbolbutton.mqh b/Experts/TradePad/classsymbolbutton.mqh new file mode 100644 index 0000000..b3d8302 --- /dev/null +++ b/Experts/TradePad/classsymbolbutton.mqh @@ -0,0 +1,105 @@ +//+------------------------------------------------------------------+ +//| CSymbolButton.mqh | +//| Copyright © 2009, MetaQuotes Software Corp. | +//| http://www.metaquotes.net | +//+------------------------------------------------------------------+ +#property copyright "Copyright © 2009, MetaQuotes Software Corp." +#property link "http://www.metaquotes.net" + +//+------------------------------------------------------------------+ +//| Class for creating a symbol button | +//+------------------------------------------------------------------+ +class CSymbolButton + { +private: + double m_top; // Y coordinate of the upper-left corner + double m_left; // X coordinate of the upper-left corner + double m_height; // button height + double m_width; // button width + color m_txt_col; // text color + color m_bg_col; // background color + int m_ind_handle; // pointer to the indicator for the button + string m_symbol_name; // name of the Symbol, for which the button is created + +public: + string m_button_name; // button's unique name + bool CreateSymbolButton(double top,double left,double height,double width, + string buttonID,color TextColor,color BGColor);// constructor + bool DeleteSymbolButton(); + void MoveButton(int x_shift,int y_shift); + color GetBGColor(){return(m_bg_col);}; + void SetBGColor(color bg_color); + string GetSymbolName(){return(m_symbol_name);}; + void SetSymbolName(string s){m_symbol_name=s;}; + }; +//+------------------------------------------------------------------+ +//| delete Symbol button | +//+------------------------------------------------------------------+ +bool CSymbolButton::DeleteSymbolButton() + { + if(ObjectFind(0,m_button_name)>=0) + { + //Print("Delete the cell with the name ",m_button_name); + if(!ObjectDelete(0,m_button_name)) + { + Print("Failed to delete the object named ",m_button_name,"! Error #",GetLastError()); + } + else + { + //ChartRedraw(0); + } + return(true); + } + return(false); + } +//+------------------------------------------------------------------+ +//| setup object of Class CSymbolButton | +//+------------------------------------------------------------------+ +bool CSymbolButton::CreateSymbolButton(double top,double left,double height,double width, + string buttonID,color TextColor,color BGColor) + { + bool res=false; +//--- + if(ObjectFind(0,buttonID)<0) + { + m_top=top; + m_left=left; + ObjectCreate(ChartID(),buttonID,OBJ_BUTTON,0,0,0,0,0); + ObjectSetInteger(0,buttonID,OBJPROP_COLOR,TextColor); + ObjectSetInteger(0,buttonID,OBJPROP_BGCOLOR,BGColor); + ObjectSetInteger(0,buttonID,OBJPROP_XDISTANCE,int(m_left)); + ObjectSetInteger(0,buttonID,OBJPROP_YDISTANCE,int(m_top)); + ObjectSetInteger(0,buttonID,OBJPROP_XSIZE,int(width)); + ObjectSetInteger(0,buttonID,OBJPROP_YSIZE,int(height)); + ObjectSetString(0,buttonID,OBJPROP_FONT,"Arial"); + ObjectSetString(0,buttonID,OBJPROP_TEXT,buttonID); + ObjectSetInteger(0,buttonID,OBJPROP_FONTSIZE,10); + ObjectSetInteger(0,buttonID,OBJPROP_SELECTABLE,0); + m_button_name=buttonID; + SetSymbolName(buttonID); + //ChartRedraw(ChartID()); + } +// else +// { +// } +//--- + return(res); + } +//+------------------------------------------------------------------+ +//| set Symbol button background color | +//+------------------------------------------------------------------+ +void CSymbolButton::SetBGColor(color bg_color) + { + ObjectSetInteger(0,m_button_name,OBJPROP_BGCOLOR,bg_color); + } +//+------------------------------------------------------------------+ +//| shift the symbol button by the specified value | +//+------------------------------------------------------------------+ +void CSymbolButton::MoveButton(int x_shift,int y_shift) + { + m_top+=y_shift; + m_left+=x_shift; + ObjectSetInteger(0,m_button_name,OBJPROP_XDISTANCE,int(m_left)); + ObjectSetInteger(0,m_button_name,OBJPROP_YDISTANCE,int(m_top)); +//ChartRedraw(0); + } diff --git a/Experts/TradePad/classtradepad.mqh b/Experts/TradePad/classtradepad.mqh new file mode 100644 index 0000000..a73c37e --- /dev/null +++ b/Experts/TradePad/classtradepad.mqh @@ -0,0 +1,414 @@ +//+------------------------------------------------------------------+ +//| CChart.mqh | +//| Copyright © 2009, MetaQuotes Software Corp. | +//| http://www.metaquotes.net | +//+------------------------------------------------------------------+ +#property copyright "Copyright © 2009, MetaQuotes Software Corp." +#property link "http://www.metaquotes.net" + +#include "ClassSymbolButton.mqh" +#include "ClassChart.mqh" +//+------------------------------------------------------------------+ +//| class for implementation of Symbols table | +//+------------------------------------------------------------------+ +class CTradePad + { +private: + int m_rows; // number of strings in the Symbols table + int m_columns; // number of columns in the Symbols table + int m_button_width; // width of the cell containing a symbol + int m_button_height; // height of the cell containing a symbol + int m_top; // X coordinate of the upper left corner + int m_left; // Y coordinate of the upper left corner + int m_left_previous_header; // previous X value for the upper left corner of the header + int m_top_previos_header; // previous Y value for the upper left corner of the header + color m_button_text_color; // unified text color for the buttons + color m_button_bg_color; // unified background color for the buttons + string m_prefix; // unified prefix for the created CSymbolButton type objects + string m_chart_name; // Chart Object name + int m_top_chart; // Y coordinate of the table's upper left corner + int m_left_chart; // X coordinate of the table's upper left corner + int m_footer_width; // footer width + CSymbolButton m_symbol_set[]; // array with the objects for managing Symbol buttons + string m_header; // name of the line for dragging the object + int m_top_buy_button; // Y coordinate of the upper left corner of BUY button + int m_left_buy_button; // X coordinate of the upper left corner of BUY + int m_top_sell_button; // Y coordinate of the upper left corner of SELL button + int m_left_sell_button; // X coordinate of the upper left corner of SELL button + int m_top_lots_edit; // Y coordinate of the upper left corner of the field for specifying the volume + int m_left_lots_edit; // X coordinate of the upper left corner of the field for specifying the volume + int m_width_lots_edit; // volume field width + string m_buy_button; // BUY button name + string m_sell_button; // SELL button name + string m_lots_edit; // volume field name + string m_chart_symbol_name; // name of the Symbol displaying Chart object + ENUM_TIMEFRAMES m_current_tf; // period of the Symbol displaying Chart object + color m_up_color; + color m_down_color; + color m_flat_color; + color m_blank_color; + CChart tradeChart; // chart object +public: + void CTradePad(); // constructor + bool CreateTradePad(int cols,int rows,int Xleft,int Ytop,int width,int height,color u,color d,color f,color b); + int DeleteTradePad(); + string GetChartName(){return(m_chart_name);}; + int GetSymbolButtons(){return(ArraySize(m_symbol_set));}; + void SetButtons(string symbolName); + void MoveTradePad(int x_shift,int y_shift); + void GetShiftTradePad(int &x_shift,int &y_shift); + string GetHeaderName(){return(m_header);}; + void SetButtonColors(); + void SetTrendColors(color u,color d,color f,color b){m_up_color=u;m_down_color=d;m_flat_color=f; m_blank_color=b;}; + void EmptyFunction(); + }; +//+------------------------------------------------------------------+ +//| default constructor (always without parameters) | +//+------------------------------------------------------------------+ +void CTradePad::CTradePad() + { + m_button_bg_color=Green; + m_button_text_color=White; + m_prefix="cell_"; + m_header="TablePad"; + m_chart_name="test"; + m_buy_button="BuyButton"; + m_sell_button="SellButton"; + m_lots_edit="InputVolume"; + } +//+------------------------------------------------------------------+ +//| creating Symbols Table (actually, it is a constructor) | +//+------------------------------------------------------------------+ +bool CTradePad::CreateTradePad(int cols,int rows,int Xleft,int Ytop,int width,int height, + color u,color d,color f,color b) + { + bool res=false; +//--- + SetTrendColors(u,d,f,b); + m_left=Xleft; + m_top=Ytop; + int Yord,Xord; +//--- how many buttons will we have? + ArrayResize(m_symbol_set,cols*rows); + int j=0,tradeSymbols=SymbolsTotal(false); + string symb[]; + ArrayResize(symb,cols*rows); + +//--- draw the header + m_top_previos_header=m_top-20; + m_left_previous_header=m_left; + if(ObjectFind(0,m_header)<0) ObjectCreate(0,m_header,OBJ_BUTTON,0,0,0,0,0); + ObjectSetInteger(0,m_header,OBJPROP_COLOR,White); + ObjectSetInteger(0,m_header,OBJPROP_BGCOLOR,Blue); + ObjectSetInteger(0,m_header,OBJPROP_XDISTANCE,m_left_previous_header); + ObjectSetInteger(0,m_header,OBJPROP_YDISTANCE,m_top_previos_header); + ObjectSetInteger(0,m_header,OBJPROP_XSIZE,cols*width); + ObjectSetInteger(0,m_header,OBJPROP_YSIZE,20); + ObjectSetString(0,m_header,OBJPROP_TEXT,"Trade Pad "); + ObjectSetString(0,m_header,OBJPROP_FONT,"Tahoma"); + ObjectSetInteger(0,m_header,OBJPROP_SELECTABLE,true); + +//--- draw the buttons + for(int c=0;c=tradeSymbols) j=0; + name=SymbolName(j,false); + j++; + symb[c*rows+r]=name; + SymbolSelect(name,true); + double v; + color col; + col=GetColorOfSymbol(name,PERIOD_CURRENT, + m_up_color,m_down_color, + m_flat_color,m_blank_color,v); + m_symbol_set[c*rows+r].CreateSymbolButton(Yord, + Xord, + height, + width, + name, + m_button_text_color, + col); + //Sleep(10);// pause in order to see the buttons' generation + } + } +//--- click the first button + ObjectSetInteger(0,symb[0],OBJPROP_STATE,true); + +//--- create Chart object + double chartheight=252; + m_current_tf=ChartPeriod(0); +// if(ObjectFind(0,m_chart_name)<0)ObjectCreate(0,m_chart_name,OBJ_CHART,0,0,0,0,0); + + m_top_chart=m_top+rows*height; + m_left_chart=m_left; +/* + ObjectSetInteger(0,m_chart_name,OBJPROP_XDISTANCE,m_left_chart); + ObjectSetInteger(0,m_chart_name,OBJPROP_YDISTANCE,m_top_chart); +*/ + m_footer_width=cols*width; +/* + ObjectSetInteger(0,m_chart_name,OBJPROP_XSIZE,m_footer_width); + chartheight=cols*width/4.0*3.0; + ObjectSetInteger(0,m_chart_name,OBJPROP_YSIZE,(int)chartheight); + ObjectSetInteger(0,m_chart_name,OBJPROP_SELECTABLE,0); + ObjectSetString(0,m_chart_name,OBJPROP_SYMBOL,symb[0]); + +*/ + chartheight=252; + tradeChart.CreateChart(m_left_chart,m_top_chart,m_footer_width,int(chartheight),symb[0],"testChart"); + +//--- create the footer +//--- SELL button + if(ObjectFind(0,m_sell_button)<0) ObjectCreate(0,m_sell_button,OBJ_BUTTON,0,0,0,0,0); + ObjectSetInteger(0,m_sell_button,OBJPROP_COLOR,White); + ObjectSetInteger(0,m_sell_button,OBJPROP_BGCOLOR,OrangeRed); + m_top_sell_button=int(m_top_chart+chartheight); + m_left_sell_button=m_left_chart; + ObjectSetInteger(0,m_sell_button,OBJPROP_XDISTANCE,m_left_sell_button); + ObjectSetInteger(0,m_sell_button,OBJPROP_YDISTANCE,m_top_sell_button); + ObjectSetInteger(0,m_sell_button,OBJPROP_XSIZE,100); + ObjectSetInteger(0,m_sell_button,OBJPROP_YSIZE,40); + ObjectSetString(0,m_sell_button,OBJPROP_FONT,"Tahoma"); + ObjectSetInteger(0,m_sell_button,OBJPROP_FONTSIZE,15); + ObjectSetString(0,m_sell_button,OBJPROP_TEXT,"SELL"); + ObjectSetInteger(0,m_sell_button,OBJPROP_SELECTABLE,false); + +//--- BUY button + if(ObjectFind(0,m_buy_button)<0) ObjectCreate(0,m_buy_button,OBJ_BUTTON,0,0,0,0,0); + ObjectSetInteger(0,m_buy_button,OBJPROP_COLOR,White); + ObjectSetInteger(0,m_buy_button,OBJPROP_BGCOLOR,Blue); + m_top_buy_button=m_top_sell_button; + m_left_buy_button=m_left_chart+m_footer_width-100; + ObjectSetInteger(0,m_buy_button,OBJPROP_XDISTANCE,m_left_buy_button); + ObjectSetInteger(0,m_buy_button,OBJPROP_YDISTANCE,m_top_buy_button); + ObjectSetInteger(0,m_buy_button,OBJPROP_XSIZE,100); + ObjectSetInteger(0,m_buy_button,OBJPROP_YSIZE,40); + ObjectSetString(0,m_buy_button,OBJPROP_FONT,"Tahoma"); + ObjectSetInteger(0,m_buy_button,OBJPROP_FONTSIZE,15); + ObjectSetString(0,m_buy_button,OBJPROP_TEXT,"BUY"); + ObjectSetInteger(0,m_buy_button,OBJPROP_SELECTABLE,false); + +//--- Volume field + if(ObjectFind(0,m_lots_edit)<0) ObjectCreate(0,m_lots_edit,OBJ_EDIT,0,0,0,0,0); + ObjectSetInteger(0,m_lots_edit,OBJPROP_COLOR,White); + ObjectSetInteger(0,m_lots_edit,OBJPROP_BGCOLOR,DarkOliveGreen); + m_top_lots_edit=m_top_sell_button; + m_left_lots_edit=m_left_chart+100; + m_width_lots_edit=m_footer_width-200; + ObjectSetInteger(0,m_lots_edit,OBJPROP_XDISTANCE,m_left_lots_edit); + ObjectSetInteger(0,m_lots_edit,OBJPROP_YDISTANCE,m_top_lots_edit); + ObjectSetInteger(0,m_lots_edit,OBJPROP_XSIZE,m_width_lots_edit); + ObjectSetInteger(0,m_lots_edit,OBJPROP_YSIZE,40); + ObjectSetString(0,m_lots_edit,OBJPROP_FONT,"Tahoma"); + ObjectSetInteger(0,m_lots_edit,OBJPROP_FONTSIZE,10); + ObjectSetString(0,m_lots_edit,OBJPROP_TEXT," 0.1"); + ObjectSetInteger(0,m_lots_edit,OBJPROP_SELECTABLE,false); + +//--- command for drawing all the changes + ChartRedraw(0); + +//--- wait a bit and try to draw the buttons' background once again + Sleep(300); + SetButtonColors(); + ChartRedraw(0); + +//--- + return(res); + } +//+------------------------------------------------------------------+ +//| set background color | +//+------------------------------------------------------------------+ +void CTradePad::SetButtonColors() + { + int i,buttons=GetSymbolButtons(); + double v;// indicator values are received here + + struct IndicatorValue + { + string symbol; + ENUM_TIMEFRAMES timeframe; + double value; + }; + + IndicatorValue state[]; + ArrayResize(state,buttons); +//Print("SetButtonColors"); +//--- + string out=""; + for(i=0;i=0) + { + int size=GetSymbolButtons(); + for(int i=0;i=0)ObjectDelete(0,SymbolTable.GetChartName()); + ChartRedraw(0); +//Print(del," Symbols deleted"); +//--- + return(res); + } +//+------------------------------------------------------------------+ +//| initialization during the launch or re-initialization | +//+------------------------------------------------------------------+ +void OnInit() + { + EventSetTimer(TimerPeriodSeconds); + Print("Init"); + if(!launched) + { + CreatePad(TableCols,TableRows); + launched=true; + } + } +//+-----------------------------------------------------------------------------------+ +//| when the Expert Advisor's operation is complete or input parameters are changed | +//+-----------------------------------------------------------------------------------+ +void OnDeinit(const int reason) + { +//--- + Print("Deinit"); + launched=false; +//--- disable the timer + EventKillTimer(); +//--- delete the object + DeletePad(); + } +//+------------------------------------------------------------------+ +//| Process chart events | +//+------------------------------------------------------------------+ + +void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) + { + //Print("OnChartEvent event: lparam =",lparam," dparam=",dparam); + + if(id==CHARTEVENT_OBJECT_CLICK) + { + string clickedButton=sparam; + SymbolTable.SetButtons(clickedButton); + ChartRedraw(); + } + if(id==CHARTEVENT_OBJECT_DRAG) + { + string dragged=sparam; + //Print("Shifted the object ",dragged," lparam =",lparam," dparam=",dparam); + if(dragged==SymbolTable.GetHeaderName()) + { + int x=ObjectGetInteger(0,dragged,OBJPROP_XDISTANCE); + int y=ObjectGetInteger(0,dragged,OBJPROP_YDISTANCE); + SymbolTable.GetShiftTradePad(x,y); + //Print("X shift = ",x," Y shift = ",y); + SymbolTable.MoveTradePad(x,y); + ChartRedraw(); + } + } + + } +//+------------------------------------------------------------------+ +//| processing timer events | +//+------------------------------------------------------------------+ +void OnTimer() + { + //Print("Timer event"); + if(launched)SymbolTable.SetButtonColors(); + } + +//+------------------------------------------------------------------+ diff --git a/Indicators/Downloads/Macd FRAMA.mq5 b/Indicators/Downloads/Macd FRAMA.mq5 new file mode 100644 index 0000000..42b0658 Binary files /dev/null and b/Indicators/Downloads/Macd FRAMA.mq5 differ diff --git a/Profiles/Charts/Default/chart01.chr b/Profiles/Charts/Default/chart01.chr deleted file mode 100644 index 5ad851c..0000000 Binary files a/Profiles/Charts/Default/chart01.chr and /dev/null differ diff --git a/Profiles/Charts/Default/chart02.chr b/Profiles/Charts/Default/chart02.chr deleted file mode 100644 index a50e8e6..0000000 Binary files a/Profiles/Charts/Default/chart02.chr and /dev/null differ diff --git a/Profiles/Charts/Default/chart03.chr b/Profiles/Charts/Default/chart03.chr deleted file mode 100644 index 2171f3b..0000000 Binary files a/Profiles/Charts/Default/chart03.chr and /dev/null differ diff --git a/Profiles/Charts/Default/chart04.chr b/Profiles/Charts/Default/chart04.chr deleted file mode 100644 index f1138db..0000000 Binary files a/Profiles/Charts/Default/chart04.chr and /dev/null differ