├── AM_Fractal_OrderBlock.mq5 ├── AM_Session_Opens.mq5 ├── AutoStopLoss.mq5 ├── Average Day Range v1.0.mq4 ├── Bollinger_Bands.mq5 ├── CHT_AutoFibo_v0.6.mq5 ├── Custom_Boomerang1.3.mq4 ├── DSS_Bressert.mq4 ├── DailyPercentageChange.mq5 ├── Day_Hight_Low.mq5 ├── DrawLine.mq5 ├── FGV_mod_MACD.mq4 ├── ForexTesterSetupEng29.exe ├── Gann T3 High-Low activator composite 2_1.mq4 ├── HalfTrend.mq5 ├── IdleLib.dll ├── JeromeClock.mq5 ├── MAX_LOT.mq5 ├── Murrey_Math_Line_X.mq4 ├── Murrey_Math_Line_X.mq5 ├── MyShortcuts-Emilio-Reale.mq4 ├── PLdot.mq4 ├── PPO.mq4 ├── PZ_PivotPoints.mq4 ├── PriceAlert.mq5 ├── Print200EMA.mq5 ├── RoundLevels.mq5 ├── Salvador ├── ElliottWaveMaker 3.0 │ ├── Experts │ │ ├── EWM.ex5 │ │ └── EWM.mq5 │ ├── Files │ │ └── EWM.txt │ └── Include │ │ └── EWM │ │ ├── defines.mqh │ │ ├── ewa │ │ ├── analysis.mqh │ │ ├── counted.mqh │ │ ├── ewa.mqh │ │ ├── node.mqh │ │ ├── patterns.mqh │ │ ├── rules.mqh │ │ ├── wave.mqh │ │ └── zigzags.mqh │ │ ├── ewm │ │ ├── descrs.mqh │ │ ├── ewm.mqh │ │ ├── horizontal.mqh │ │ ├── label.mqh │ │ ├── labels.mqh │ │ ├── panel.mqh │ │ ├── price_label.mqh │ │ ├── vertical.mqh │ │ ├── wave_label.mqh │ │ └── wave_labels.mqh │ │ ├── functions.mqh │ │ ├── p │ │ ├── p.mqh │ │ ├── pitchfork.mqh │ │ ├── pitchforks.mqh │ │ ├── reaction.mqh │ │ ├── schiff.mqh │ │ └── warning.mqh │ │ └── parser.mqh ├── Simple EA │ └── simple-ea.mq5 └── VolatilityPivot │ ├── MQL5 │ ├── Indicators │ │ └── volatilitypivot.mq5 │ └── include │ │ └── tradealgorithms.mqh │ └── exp_volatilitypivot.mq5 ├── Show Pips.mq5 ├── SweetSpots.mq4 ├── TD Sequential Ultimate.mq4 ├── TD Sequential Ultimate.mq5 ├── TradeManager1.0.mq5 ├── TradersDynamicIndex.mq5 ├── TrendLineAlert.mq5 ├── TzPivots.mq5 ├── VWAP.mq5 ├── calliara.tpl ├── data_to_csv.mq4 ├── dobrin20i200.tpl ├── dobrin20i50i200-light.tpl ├── dobrin20i50i200.tpl ├── donchian_channels.mq5 ├── ema-levels.mq5 ├── i-Sessions.mq4 ├── i-Sessions.mq5 ├── ma_colored.mq5 ├── maximum-trade-volume.mq5 ├── openWithRisk.mq5 ├── opentrade.mq5 ├── set-sl-tp.mq4 ├── shistoryexport ├── shistoryexport-mql5 ├── CheckHistory.mqh ├── String.mqh ├── fxtester2.9.6-feb-2021.tem └── sHistoryExport.mq5 ├── socket.mq5 ├── socket_mql5.cpp ├── supertrend.mq5 ├── template_bollinger.tpl ├── template_dec_2020.tpl └── tradingview-screener-mean-reversion /AutoStopLoss.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Script program start function | 3 | //+------------------------------------------------------------------+ 4 | void OnStart() 5 | { 6 | double stopLoss = 100 * _Point; // Stop loss in points 7 | double takeProfit = 200 * _Point; // Take profit in points 8 | int totalOrders = OrdersTotal(); 9 | 10 | for (int i = totalOrders - 1; i >= 0; i--) 11 | { 12 | if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 13 | { 14 | if (OrderMagicNumber() == 0) // Check if the order was placed manually 15 | { 16 | double newSL, newTP; 17 | 18 | if (OrderType() == ORDER_BUY) 19 | { 20 | newSL = OrderOpenPrice() - stopLoss; 21 | newTP = OrderOpenPrice() + takeProfit; 22 | } 23 | else if (OrderType() == ORDER_SELL) 24 | { 25 | newSL = OrderOpenPrice() + stopLoss; 26 | newTP = OrderOpenPrice() - takeProfit; 27 | } 28 | else 29 | { 30 | continue; 31 | } 32 | 33 | bool result = OrderModify(OrderTicket(), OrderOpenPrice(), newSL, newTP, 0); 34 | if (result) 35 | { 36 | Print("Stop Loss and Take Profit set successfully."); 37 | } 38 | else 39 | { 40 | Print("Failed to set Stop Loss and Take Profit. Error: ", GetLastError()); 41 | } 42 | break; // Stop after modifying the latest order 43 | } 44 | } 45 | } 46 | } 47 | //+------------------------------------------------------------------+ 48 | -------------------------------------------------------------------------------- /Average Day Range v1.0.mq4: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Average Day Range v1.0.mq4 | 3 | //| Copyright � 2006, Ogeima | 4 | //| ph_bresson@yahoo.com | 5 | //+------------------------------------------------------------------+ 6 | //Please find some notes at the end of the script 7 | #property copyright "Copyright � 2006, Ogeima" 8 | #property link "ph_bresson@yahoo.com" 9 | 10 | #property indicator_separate_window 11 | #property indicator_buffers 1 12 | #property indicator_color1 Brown 13 | #property indicator_minimum 0 14 | 15 | double ADR[]; 16 | int cur_day; 17 | 18 | //+------------------------------------------------------------------+ 19 | //| Custom indicator initialization function | 20 | //+------------------------------------------------------------------+ 21 | int init() 22 | { 23 | IndicatorShortName("Average Day Range " + Symbol() + " "); 24 | IndicatorBuffers(1); 25 | SetIndexBuffer(0,ADR); 26 | SetIndexStyle(0,DRAW_LINE,EMPTY,3,Brown); 27 | SetIndexEmptyValue(0,EMPTY_VALUE); 28 | SetIndexLabel(0,"ADR " + Symbol() + " " + Period()); 29 | /* 30 | cur_day = TimeDayOfWeek(Time[0]); 31 | ADR[0] = AvgDayRange(1); 32 | */ 33 | cur_day = 6; 34 | } 35 | //+------------------------------------------------------------------+ 36 | //| Custom indicator deinitialization function | 37 | //+------------------------------------------------------------------+ 38 | int deinit() 39 | { 40 | return(0); 41 | } 42 | //+------------------------------------------------------------------+ 43 | //| Custom indicator iteration function | 44 | //+------------------------------------------------------------------+ 45 | int start() 46 | { 47 | int nth_day,shift; 48 | int counted_bars = IndicatorCounted(); 49 | if(counted_bars<0) counted_bars=0; 50 | if(counted_bars>0) counted_bars--; 51 | int limit = Bars-counted_bars - 21; 52 | 53 | for( shift=0 ; shift < limit; shift++ ) 54 | { 55 | if(cur_day != TimeDayOfWeek(Time[shift])) //New Day: compute the ADR 56 | { 57 | cur_day = TimeDayOfWeek(Time[shift]); 58 | nth_day ++; 59 | ADR[shift] = AvgDayRange(nth_day); 60 | } //if(cur_day != TimeDayOfWeek(Time[shift])) 61 | else ADR[shift] = ADR[shift-1]; //Not a new day 62 | } //for(shift=limit ; shift >= 0 ; shift--) 63 | return(0); 64 | } 65 | //+---------------------------------------------------------------------------+ 66 | double AvgDayRange(int nth_day) 67 | { 68 | double R1,R5,R10,R20; 69 | int i; 70 | 71 | R1 = (iHigh(NULL,PERIOD_D1,nth_day)-iLow(NULL,PERIOD_D1,nth_day)); 72 | for(i=0;i<5;i++) R5 = R5 + (iHigh(NULL,PERIOD_D1,nth_day+i)-iLow(NULL,PERIOD_D1,nth_day+i)); 73 | for(i=0;i<10;i++) R10 = R10 + (iHigh(NULL,PERIOD_D1,nth_day+i)-iLow(NULL,PERIOD_D1,nth_day+i)); 74 | for(i=0;i<20;i++) R20 = R20 + (iHigh(NULL,PERIOD_D1,nth_day+i)-iLow(NULL,PERIOD_D1,nth_day+i)); 75 | 76 | R5 = R5/5; 77 | R10 = R10/10; 78 | R20 = R20/20; 79 | 80 | return((R1+R5+R10+R20)/4); 81 | } 82 | //+---------------------------------------------------------------------------+ 83 | 84 | /* 85 | It computes yesterday's range (range= high - low), the previous 5, 10 and 20 days ranges. And it calculates the "Average Day Range" of these four ranges (yesterday's+ Prev 5 Day Range + Prev 10 Day Range + Prev 20 Day Range)/4. 86 | So, if yesterday's Day Range was 80, the Previous 5 Day Range was 110, the Previous 10 Day Range was 90 and the Previous 20 Day Range was 120, then the Average Day Range would be 100. 87 | ADR is therefore a kind of weighted Day Range. 88 | 89 | 90 | For FXIGOR's DBO system, Divide_Factor is 2. 91 | For more information regarding the DBO system, read the "FXiGoR-(T_S_R) very effective Trend Slope Retracement system" thread opened by iGoR at StrategyBuilderfx or Forex-tsd. 92 | For FXIGOR's TSR method, use Divide_Factor = 1. 93 | For more information regarding the T_S_R method, read the "FXiGoR-(T_S_R) very effective Trend Slope Retracement system" thread opened by iGoR at StrategyBuilderfx or Forex-tsd. 94 | 95 | Ogeima. 96 | */ 97 | 98 | -------------------------------------------------------------------------------- /Bollinger_Bands.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| BB.mq5 | 3 | //| Copyright 2009, MetaQuotes Software Corp. | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "2009, MetaQuotes Software Corp." 7 | #property link "http://www.mql5.com" 8 | #property description "Bollinger Bands" 9 | #include 10 | //--- 11 | #property indicator_chart_window 12 | #property indicator_buffers 4 13 | #property indicator_plots 3 14 | #property indicator_type1 DRAW_LINE 15 | #property indicator_color1 LightSeaGreen 16 | #property indicator_type2 DRAW_LINE 17 | #property indicator_color2 LightSeaGreen 18 | #property indicator_type3 DRAW_LINE 19 | #property indicator_color3 LightSeaGreen 20 | #property indicator_label1 "Bands middle" 21 | #property indicator_label2 "Bands upper" 22 | #property indicator_label3 "Bands lower" 23 | //--- input parametrs 24 | input int InpBandsPeriod=20; // Period 25 | input int InpBandsShift=0; // Shift 26 | input double InpBandsDeviations=2.0; // Deviation 27 | //--- global variables 28 | int ExtBandsPeriod,ExtBandsShift; 29 | double ExtBandsDeviations; 30 | int ExtPlotBegin=0; 31 | //---- indicator buffer 32 | double ExtMLBuffer[]; 33 | double ExtTLBuffer[]; 34 | double ExtBLBuffer[]; 35 | double ExtStdDevBuffer[]; 36 | //+------------------------------------------------------------------+ 37 | //| Custom indicator initialization function | 38 | //+------------------------------------------------------------------+ 39 | void OnInit() 40 | { 41 | //--- check for input values 42 | if(InpBandsPeriod<2) 43 | { 44 | ExtBandsPeriod=20; 45 | printf("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod); 46 | } 47 | else ExtBandsPeriod=InpBandsPeriod; 48 | if(InpBandsShift<0) 49 | { 50 | ExtBandsShift=0; 51 | printf("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift); 52 | } 53 | else 54 | ExtBandsShift=InpBandsShift; 55 | if(InpBandsDeviations==0.0) 56 | { 57 | ExtBandsDeviations=2.0; 58 | printf("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations); 59 | } 60 | else ExtBandsDeviations=InpBandsDeviations; 61 | //--- define buffers 62 | SetIndexBuffer(0,ExtMLBuffer); 63 | SetIndexBuffer(1,ExtTLBuffer); 64 | SetIndexBuffer(2,ExtBLBuffer); 65 | SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS); 66 | //--- set index labels 67 | PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle"); 68 | PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper"); 69 | PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower"); 70 | //--- indicator name 71 | IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); 72 | //--- indexes draw begin settings 73 | ExtPlotBegin=ExtBandsPeriod-1; 74 | PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); 75 | PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); 76 | PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); 77 | //--- indexes shift settings 78 | PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); 79 | PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); 80 | PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); 81 | //--- number of digits of indicator value 82 | IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); 83 | //---- OnInit done 84 | } 85 | //+------------------------------------------------------------------+ 86 | //| Custom indicator iteration function | 87 | //+------------------------------------------------------------------+ 88 | int OnCalculate(const int rates_total, 89 | const int prev_calculated, 90 | const int begin, 91 | const double &price[]) 92 | { 93 | //--- variables 94 | int pos; 95 | //--- indexes draw begin settings, when we've recieved previous begin 96 | if(ExtPlotBegin!=ExtBandsPeriod+begin) 97 | { 98 | ExtPlotBegin=ExtBandsPeriod+begin; 99 | PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin); 100 | PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin); 101 | PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin); 102 | } 103 | //--- check for bars count 104 | if(rates_total1) pos=prev_calculated-1; 108 | else pos=0; 109 | //--- main cycle 110 | for(int i=pos;i 0) limit = Bars - counted_bars; 68 | 69 | double HighRange, LowRange; 70 | double delta, MIT; 71 | for (i = limit; i >= 0; i--) 72 | { 73 | HighRange = High[iHighest(NULL,0,MODE_HIGH,Stochastic_period,i)]; 74 | LowRange = Low[iLowest(NULL,0,MODE_LOW,Stochastic_period,i)]; 75 | delta = Close[i] - LowRange; 76 | MIT = delta/(HighRange - LowRange)*100.0; 77 | MitBuffer[i] = smooth_coefficient * (MIT - MitBuffer[i+1]) + MitBuffer[i+1]; 78 | } 79 | 80 | double DSS; 81 | for (i = limit; i >= 0; i--) 82 | { 83 | HighRange = MitBuffer[ArrayMaximum(MitBuffer, Stochastic_period, i)]; 84 | LowRange = MitBuffer[ArrayMinimum(MitBuffer, Stochastic_period, i)]; 85 | delta = MitBuffer[i] - LowRange; 86 | DSS = delta/(HighRange - LowRange)*100.0; 87 | DssBuffer[i] = smooth_coefficient * (DSS - DssBuffer[i+1]) + DssBuffer[i+1]; 88 | } 89 | 90 | //---- 91 | return(0); 92 | } 93 | //+------------------------------------------------------------------+ -------------------------------------------------------------------------------- /Day_Hight_Low.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Day_Hight_Low.mq5 | 3 | //| Copyright 2015, MetaQuotes Software Corp. | 4 | //| https://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #property script_show_inputs 7 | //--- input parameters 8 | input datetime Day; 9 | input color Day_level=clrDarkViolet; 10 | input color Night_Level=clrRoyalBlue; 11 | input bool Night_Session=true; 12 | //+------------------------------------------------------------------+ 13 | //| Script program start function | 14 | //+------------------------------------------------------------------+ 15 | void OnStart() 16 | { 17 | datetime TStart,TDay,TNight; 18 | MqlDateTime STRTime; 19 | int IStart,IDay,INight; 20 | int IDayHight,IDayLow,INightHight,INightLow; 21 | double MHightD[1],MLowD[1],MHightN[1],MLowN[1]; 22 | 23 | //--- 24 | TimeToStruct(Day,STRTime); 25 | STRTime.hour= 10; 26 | STRTime.min = 0; 27 | TStart=StructToTime(STRTime); 28 | STRTime.hour= 18; 29 | STRTime.min = 40; 30 | TDay=StructToTime(STRTime); 31 | STRTime.hour= 23; 32 | STRTime.min = 45; 33 | TNight=StructToTime(STRTime); 34 | //Print (TStart, TDay, TNight); 35 | IStart=iBarShift(NULL,PERIOD_CURRENT,TStart,true); 36 | IDay=iBarShift(NULL,PERIOD_CURRENT,TDay,true); 37 | INight=iBarShift(NULL,PERIOD_CURRENT,TNight,true); 38 | //Print ("IStart = ", IStart , " IDay = ", IDay, " INight = ",INight); 39 | IDayHight=iHighest(NULL,0,MODE_HIGH,IStart-IDay+1,IDay); 40 | IDayLow=iLowest(NULL,0,MODE_LOW,IStart-IDay+1,IDay); 41 | INightHight=iHighest(NULL,0,MODE_HIGH,IStart-INight+2,INight); 42 | INightLow=iLowest(NULL,0,MODE_LOW,IStart-INight+2,INight); 43 | CopyHigh(NULL,0,IDayHight,1,MHightD); 44 | CopyHigh(NULL,0,INightHight,1,MHightN); 45 | CopyLow(NULL,0,IDayLow,1,MLowD); 46 | CopyLow(NULL,0,INightLow,1,MLowN); 47 | //Print ("Hight дня = ",MHightD[0]," - ",IDayHight," Low дня = ", MLowD[0], " - ",IDayLow," Hight с вечером = ", MHightN[0], " - ",INightHight, " Low с вечером = ",MLowN[0], " - ",INightLow); 48 | ObjectCreate(0,"NOFX_DH",OBJ_HLINE,0,IStart,MHightD[0]); 49 | ObjectSetInteger(0,"NOFX_DH",OBJPROP_COLOR,Day_level); 50 | ObjectSetInteger(0,"NOFX_DH",OBJPROP_HIDDEN,false); 51 | ObjectCreate(0,"NOFX_DL",OBJ_HLINE,0,IStart,MLowD[0]); 52 | ObjectSetInteger(0,"NOFX_DL",OBJPROP_COLOR,Day_level); 53 | ObjectSetInteger(0,"NOFX_DL",OBJPROP_HIDDEN,false); 54 | 55 | if(Night_Session)//если включен учёт ночной сессии, то дорисовываем ночные экстремумы если они выходят за рамки дня 56 | { 57 | if(MHightD[0]MLowN[0])//если дневной минимум больше ночного то дорисовываем ночной минимум 64 | { 65 | ObjectCreate(0,"NOFX_DL",OBJ_HLINE,0,IStart,MLowN[0]); 66 | ObjectSetInteger(0,"NOFX_DL",OBJPROP_COLOR,Night_Level); 67 | ObjectSetInteger(0,"NOFX_DL",OBJPROP_HIDDEN,false); 68 | } 69 | } 70 | 71 | } 72 | //+------------------------------------------------------------------+ 73 | -------------------------------------------------------------------------------- /DrawLine.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| DrawLine.mq5 | 3 | //| Copyright 2021, MetaQuotes Software Corp. | 4 | //| http://www.metaquotes.net/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2021, Your Name" 7 | #property link "http://www.yourwebsite.com" 8 | #property version "1.00" 9 | #property indicator_chart_window 10 | 11 | //+------------------------------------------------------------------+ 12 | //| Custom indicator initialization function | 13 | //+------------------------------------------------------------------+ 14 | int OnInit() 15 | { 16 | datetime prevDayStart, prevDayEnd, currDayEnd; 17 | double highPrice; 18 | int err; 19 | 20 | // Find the start and end of the previous day based on the server time 21 | prevDayStart = iTime(_Symbol, PERIOD_D1, 1); 22 | prevDayEnd = iTime(_Symbol, PERIOD_D1, 0) - 1; 23 | currDayEnd = TimeCurrent(); 24 | 25 | // Get the high of the previous day 26 | highPrice = iHigh(_Symbol, PERIOD_D1, 1); 27 | 28 | // Create a line from previous day high to the end of the current day 29 | string lineName = "PrevDayHighLine"; 30 | if(!ObjectCreate(0, lineName, OBJ_TREND, 0, prevDayStart, highPrice, currDayEnd, highPrice)) 31 | { 32 | err = GetLastError(); 33 | Print("Error creating line object: ", err); 34 | return(INIT_FAILED); 35 | } 36 | 37 | // Set the properties of the line 38 | ObjectSetInteger(0, lineName, OBJPROP_COLOR, clrRed); 39 | ObjectSetInteger(0, lineName, OBJPROP_STYLE, STYLE_SOLID); 40 | ObjectSetInteger(0, lineName, OBJPROP_WIDTH, 2); 41 | 42 | // Success 43 | return(INIT_SUCCEEDED); 44 | } 45 | int OnCalculate(const int rates_total, 46 | const int prev_calculated, 47 | const datetime& time[], 48 | const double& open[], 49 | const double& high[], 50 | const double& low[], 51 | const double& close[], 52 | const long& tick_volume[], 53 | const long& volume[], 54 | const int& spread[]) 55 | { 56 | // Indicator calculation logic here 57 | for(int i = 0; i < rates_total; i++) 58 | { 59 | // Example: Simply copy close prices to a buffer 60 | // Make sure you have defined and mapped a buffer at the top 61 | } 62 | 63 | return(rates_total); 64 | } 65 | 66 | //+------------------------------------------------------------------+ 67 | //| Custom indicator deinitialization function | 68 | //+------------------------------------------------------------------+ 69 | void OnDeinit(const int reason) 70 | { 71 | // Remove the graphical object when the indicator is removed 72 | ObjectDelete(0, "PrevDayHighLine"); 73 | } 74 | 75 | //+------------------------------------------------------------------+ 76 | -------------------------------------------------------------------------------- /FGV_mod_MACD.mq4: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Custom FGV_mod_MACD.mq4 | 3 | //| Copyright 2005-2014, MetaQuotes Software Corp. | 4 | //| http://www.mql4.com | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "2005-2014, MetaQuotes Software Corp." 7 | #property link "http://www.mql4.com" 8 | #property description "Exponential Moving Averages Convergence/Divergence" 9 | #property strict 10 | //+------------------------------------------------------------------+ 11 | //| | 12 | //| Modified by FGV http://sapienssapiens.com | 13 | //| | 14 | //+------------------------------------------------------------------+ 15 | 16 | #include 17 | 18 | //--- indicator settings 19 | #property indicator_separate_window 20 | #property indicator_buffers 2 21 | #property indicator_color1 Aqua 22 | #property indicator_color2 Red 23 | #property indicator_width1 2 24 | //--- indicator parameters 25 | input int InpFastEMA=12; // Fast EMA Period 26 | input int InpSlowEMA=26; // Slow EMA Period 27 | input int InpSignalEMA=9; // Signal EMA Period 28 | //--- indicator buffers 29 | double ExtMacdBuffer[]; 30 | double ExtSignalBuffer[]; 31 | //--- right input parameters flag 32 | bool ExtParameters=false; 33 | 34 | //+------------------------------------------------------------------+ 35 | //| Custom indicator initialization function | 36 | //+------------------------------------------------------------------+ 37 | int OnInit(void) 38 | { 39 | IndicatorDigits(Digits+1); 40 | //--- drawing settings 41 | SetIndexStyle(0,DRAW_LINE); 42 | SetIndexStyle(1,DRAW_LINE); 43 | SetIndexDrawBegin(1,InpSignalEMA); 44 | //--- indicator buffers mapping 45 | SetIndexBuffer(0,ExtMacdBuffer); 46 | SetIndexBuffer(1,ExtSignalBuffer); 47 | //--- name for DataWindow and indicator subwindow label 48 | IndicatorShortName("FGV_mod_MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalEMA)+")"); 49 | SetIndexLabel(0,"FGV_mod_MACD"); 50 | SetIndexLabel(1,"Signal"); 51 | //--- check for input parameters 52 | if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalEMA<=1 || InpFastEMA>=InpSlowEMA) 53 | { 54 | Print("Wrong input parameters"); 55 | ExtParameters=false; 56 | return(INIT_FAILED); 57 | } 58 | else 59 | ExtParameters=true; 60 | //--- initialization done 61 | return(INIT_SUCCEEDED); 62 | } 63 | //+------------------------------------------------------------------+ 64 | //| Moving Averages Convergence/Divergence | 65 | //+------------------------------------------------------------------+ 66 | int OnCalculate (const int rates_total, 67 | const int prev_calculated, 68 | const datetime& time[], 69 | const double& open[], 70 | const double& high[], 71 | const double& low[], 72 | const double& close[], 73 | const long& tick_volume[], 74 | const long& volume[], 75 | const int& spread[]) 76 | { 77 | int i,limit; 78 | //--- 79 | if(rates_total<=InpSignalEMA || !ExtParameters) 80 | return(0); 81 | //--- last counted bar will be recounted 82 | limit=rates_total-prev_calculated; 83 | if(prev_calculated>0) 84 | limit++; 85 | //--- macd counted in the 1-st buffer 86 | for(i=0; i0) ExtCountedBars--; 62 | //---- 63 | switch(MA_Method) 64 | { 65 | case 0 : sma(); break; 66 | case 1 : ema(); break; 67 | case 2 : smma(); break; 68 | case 3 : lwma(); 69 | } 70 | //---- done 71 | return(0); 72 | } 73 | //+------------------------------------------------------------------+ 74 | //| Simple Moving Average | 75 | //+------------------------------------------------------------------+ 76 | void sma() 77 | { 78 | double sum=0; 79 | int i,pos=Bars-ExtCountedBars-1; 80 | //---- initial accumulation 81 | if(pos=0) 86 | { 87 | sum+=Close[pos]; 88 | ExtMapBuffer[pos]=sum/MA_Period; 89 | sum-=Close[pos+MA_Period-1]; 90 | pos--; 91 | } 92 | //---- zero initial bars 93 | if(ExtCountedBars<1) 94 | for(i=1;i2) pos=Bars-ExtCountedBars-1; 104 | //---- main calculation loop 105 | while(pos>=0) 106 | { 107 | if(pos==Bars-2) ExtMapBuffer[pos+1]=Close[pos+1]; 108 | ExtMapBuffer[pos]=Close[pos]*pr+ExtMapBuffer[pos+1]*(1-pr); 109 | pos--; 110 | } 111 | } 112 | //+------------------------------------------------------------------+ 113 | //| Smoothed Moving Average | 114 | //+------------------------------------------------------------------+ 115 | void smma() 116 | { 117 | double sum=0; 118 | int i,k,pos=Bars-ExtCountedBars+1; 119 | //---- main calculation loop 120 | pos=Bars-MA_Period; 121 | if(pos>Bars-ExtCountedBars) pos=Bars-ExtCountedBars; 122 | while(pos>=0) 123 | { 124 | if(pos==Bars-MA_Period) 125 | { 126 | //---- initial accumulation 127 | for(i=0,k=pos;i=0) 160 | { 161 | ExtMapBuffer[pos]=sum/weight; 162 | if(pos==0) break; 163 | pos--; 164 | i--; 165 | price=Close[pos]; 166 | sum=sum-lsum+price*MA_Period; 167 | lsum-=Close[i]; 168 | lsum+=price; 169 | } 170 | //---- zero initial bars 171 | if(ExtCountedBars<1) 172 | for(i=1;i0) counted_bars--; 56 | limit=Bars-counted_bars; 57 | //---- (FastEMA-SlowEMA)/SlowEMA 58 | //---- PPO counted in the 1st buffer 59 | for(int i=0; i= 0; i--) 116 | { 117 | string label = ObjectName(i); 118 | if(StringFind(label, OLabel) == -1) continue; 119 | ObjectDelete(label); 120 | } 121 | return(0); 122 | } 123 | int deinit() 124 | { 125 | Comment("Copyright © http://www.pointzero-trading.com"); 126 | DeleteObjects(); 127 | } 128 | //+------------------------------------------------------------------+ 129 | //| Custom indicator iteration function | 130 | //+------------------------------------------------------------------+ 131 | int start() 132 | { 133 | // Start, limit, etc.. 134 | int start = 1; 135 | int limit; 136 | int counted_bars = IndicatorCounted(); 137 | 138 | // nothing else to do? 139 | if(counted_bars < 0) 140 | return(-1); 141 | 142 | // do not check repeated bars 143 | limit = Bars - 1 - counted_bars; 144 | 145 | // Only for inferior timeframes! 146 | if(Period() >= FTimeFrame) return(0); 147 | 148 | // Iteration 149 | for(int pos = limit; pos >= start; pos--) 150 | { 151 | // Daily shift to use 152 | int dshift = iBarShift(Symbol(), FTimeFrame, Time[pos], false); 153 | 154 | // High, low, close and open 155 | double HIGH = iHigh(Symbol(), FTimeFrame, dshift+1); 156 | double LOW = iLow(Symbol(), FTimeFrame, dshift+1); 157 | double CLOSE = iClose(Symbol(), FTimeFrame, dshift+1); 158 | double OPEN = iOpen(Symbol(), FTimeFrame, dshift+1); 159 | 160 | // Pivot Point 161 | double pv = (HIGH + LOW + CLOSE) / 3; 162 | 163 | // Calcuations 164 | FextMapBuffer1[pos] = (2 * pv) - LOW; // R1 165 | FextMapBuffer4[pos] = (2 * pv) - HIGH; // S1 166 | FextMapBuffer2[pos] = (pv - FextMapBuffer4[pos]) + FextMapBuffer1[pos]; // R2 167 | FextMapBuffer5[pos] = pv - (FextMapBuffer1[pos] - FextMapBuffer4[pos]); // S2 168 | FextMapBuffer3[pos] = (pv - FextMapBuffer5[pos]) + FextMapBuffer2[pos]; // R3 169 | FextMapBuffer6[pos] = pv - (FextMapBuffer2[pos] - FextMapBuffer5[pos]); // S3 170 | } 171 | 172 | // Draw labels 173 | DrawLabel("R1", Shift, FextMapBuffer1[Shift], ResistanceLabel, 0); 174 | DrawLabel("R2", Shift, FextMapBuffer2[Shift], ResistanceLabel, 0); 175 | DrawLabel("R3", Shift, FextMapBuffer3[Shift], ResistanceLabel, 0); 176 | DrawLabel("S1", Shift, FextMapBuffer4[Shift], SupportLabel, 0); 177 | DrawLabel("S2", Shift, FextMapBuffer5[Shift], SupportLabel, 0); 178 | DrawLabel("S3", Shift, FextMapBuffer6[Shift], SupportLabel, 0); 179 | 180 | // Bye 181 | return(0); 182 | } 183 | 184 | void DrawLabel(string text, int shift, double vPrice, color vcolor, int voffset) 185 | { 186 | // Time 187 | datetime x1 = Time[shift]; 188 | 189 | // Bye if I don't need you 190 | if(!DisplayLabels) return(0); 191 | 192 | // Label 193 | string label = OLabel +"-"+ text; 194 | 195 | // If object exists, detroy it -we might be repainting- 196 | if(ObjectFind(label) != -1) ObjectDelete(label); 197 | 198 | ObjectCreate(label, OBJ_TEXT, 0, x1, vPrice); 199 | ObjectSetText(label, text, LabelFontSize, "Tahoma", vcolor); 200 | ObjectSet(label, OBJPROP_BACK, true); 201 | } 202 | -------------------------------------------------------------------------------- /PriceAlert.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| PriceAlert.mq5 | 3 | //| Copyright © 2009-2011, www.earnforex.com | 4 | //| Issues sound alerts when price reaches certain levels. | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "EarnForex.com" 7 | #property link "http://www.earnforex.com" 8 | #property version "1.01" 9 | 10 | #property description "Update 1.01: Dragging lines on chart will now change the alert levels." 11 | 12 | #property indicator_chart_window 13 | 14 | input double SoundWhenPriceGoesAbove = 0; 15 | input double SoundWhenPriceGoesBelow = 0; 16 | input double SoundWhenPriceIsExactly = 0; 17 | input bool SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT5. E-mail SMTP Server settings should also be configured in your MT5. 18 | 19 | //Vars to substitute input parameters to be able to modify them 20 | double SWPGB; 21 | double SWPGA; 22 | double SWPIE; 23 | 24 | //+------------------------------------------------------------------+ 25 | //| Custom indicator initialization function | 26 | //+------------------------------------------------------------------+ 27 | void OnInit() 28 | { 29 | if (SoundWhenPriceIsExactly > 0) 30 | { 31 | SWPIE = SoundWhenPriceIsExactly; 32 | ObjectCreate(0, "SoundWhenPriceIsExactly", OBJ_HLINE, 0, TimeCurrent(), SoundWhenPriceIsExactly); 33 | ObjectSetInteger(0, "SoundWhenPriceIsExactly", OBJPROP_STYLE, STYLE_SOLID); 34 | ObjectSetInteger(0, "SoundWhenPriceIsExactly", OBJPROP_COLOR, Yellow); 35 | ObjectSetInteger(0, "SoundWhenPriceIsExactly", OBJPROP_WIDTH, 1); 36 | ObjectSetInteger(0, "SoundWhenPriceIsExactly", OBJPROP_SELECTABLE, true); 37 | } 38 | if (SoundWhenPriceGoesAbove > 0) 39 | { 40 | SWPGA = SoundWhenPriceGoesAbove; 41 | ObjectCreate(0, "SoundWhenPriceGoesAbove", OBJ_HLINE, 0, TimeCurrent(), SoundWhenPriceGoesAbove); 42 | ObjectSetInteger(0, "SoundWhenPriceGoesAbove", OBJPROP_STYLE, STYLE_SOLID); 43 | ObjectSetInteger(0, "SoundWhenPriceGoesAbove", OBJPROP_COLOR, Green); 44 | ObjectSetInteger(0, "SoundWhenPriceGoesAbove", OBJPROP_WIDTH, 1); 45 | ObjectSetInteger(0, "SoundWhenPriceGoesAbove", OBJPROP_SELECTABLE, true); 46 | } 47 | if (SoundWhenPriceGoesBelow > 0) 48 | { 49 | SWPGB = SoundWhenPriceGoesBelow; 50 | ObjectCreate(0, "SoundWhenPriceGoesBelow", OBJ_HLINE, 0, TimeCurrent(), SoundWhenPriceGoesBelow); 51 | ObjectSetInteger(0, "SoundWhenPriceGoesBelow", OBJPROP_STYLE, STYLE_SOLID); 52 | ObjectSetInteger(0, "SoundWhenPriceGoesBelow", OBJPROP_COLOR, Red); 53 | ObjectSetInteger(0, "SoundWhenPriceGoesBelow", OBJPROP_WIDTH, 1); 54 | ObjectSetInteger(0, "SoundWhenPriceGoesBelow", OBJPROP_SELECTABLE, true); 55 | } 56 | } 57 | 58 | //+------------------------------------------------------------------+ 59 | //| Custor indicator deinitialization function | 60 | //+------------------------------------------------------------------+ 61 | void OnDeinit(const int reason) 62 | { 63 | ObjectDelete(0, "SoundWhenPriceIsExactly"); 64 | ObjectDelete(0, "SoundWhenPriceGoesAbove"); 65 | ObjectDelete(0, "SoundWhenPriceGoesBelow"); 66 | } 67 | //+------------------------------------------------------------------+ 68 | //| Custom indicator iteration function | 69 | //+------------------------------------------------------------------+ 70 | int OnCalculate(const int rates_total, 71 | const int prev_calculated, 72 | const datetime &time[], 73 | const double &open[], 74 | const double &high[], 75 | const double &low[], 76 | const double &close[], 77 | const long &tick_volume[], 78 | const long &volume[], 79 | const int &spread[]) 80 | { 81 | double Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); 82 | double Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); 83 | if ((Ask > SWPGA) && (SWPGA > 0)) 84 | { 85 | Alert("Price above the alert level."); 86 | PlaySound("alert.wav"); 87 | SendMail("Price for " + Symbol() + " above the alert level " + DoubleToString(Ask), "Price for " + Symbol() + " reached " + DoubleToString(Ask) + " level, which is above your alert level of " + DoubleToString(SWPGA)); 88 | ObjectDelete(0, "SoundWhenPriceGoesAbove"); 89 | SWPGA = 0; 90 | } 91 | if ((Bid < SWPGB) && (SWPGB > 0)) 92 | { 93 | Alert("Price below the alert level."); 94 | PlaySound("alert.wav"); 95 | SendMail("Price for " + Symbol() + " below the alert level " + DoubleToString(Bid), "Price for " + Symbol() + " reached " + DoubleToString(Bid) + " level, which is below your alert level of " + DoubleToString(SWPGB)); 96 | ObjectDelete(0, "SoundWhenPriceGoesBelow"); 97 | SWPGB = 0; 98 | } 99 | if ((Bid == SWPIE) || (Ask == SWPIE)) 100 | { 101 | Alert("Price is exactly at the alert level."); 102 | PlaySound("alert.wav"); 103 | SendMail("Price for " + Symbol() + " exactly at the alert level " + DoubleToString(Ask), "Price for " + Symbol() + " reached " + DoubleToString(Ask) + "/" + DoubleToString(Bid) + " level, which is exactly your alert level of " + DoubleToString(SWPIE)); 104 | ObjectDelete(0, "SoundWhenPriceIsExactly"); 105 | SWPIE = 0; 106 | } 107 | return(rates_total); 108 | } 109 | 110 | void OnChartEvent(const int id, 111 | const long& lparam, 112 | const double& dparam, 113 | const string& sparam) 114 | { 115 | if (id != CHARTEVENT_OBJECT_DRAG) return; 116 | 117 | double newprice = ObjectGetDouble(0, sparam, OBJPROP_PRICE); 118 | 119 | if (sparam == "SoundWhenPriceIsExactly") SWPIE = newprice; 120 | else if (sparam == "SoundWhenPriceGoesAbove") SWPGA = newprice; 121 | else if (sparam == "SoundWhenPriceGoesBelow") SWPGB = newprice; 122 | } 123 | //+------------------------------------------------------------------+ 124 | -------------------------------------------------------------------------------- /Print200EMA.mq5: -------------------------------------------------------------------------------- 1 | //+--------------------------------------------------------------------+ 2 | //| Print200EMA.mq5 | 3 | //| Copyright 2024, lanastasov | 4 | //| https://www.mql5.com | 5 | //+--------------------------------------------------------------------+ 6 | #property copyright "Copyright 2024, lanastasov" 7 | #property link "https://www.mql5.com" 8 | #property version "1.00" 9 | #property strict 10 | 11 | input ENUM_APPLIED_PRICE AppliedPrice = PRICE_CLOSE; // Applied price for EMA calculation 12 | 13 | int EmaHandle; 14 | int DailyEmaHandle; 15 | 16 | //+------------------------------------------------------------------+ 17 | //| Expert initialization function | 18 | //+------------------------------------------------------------------+ 19 | int OnInit() 20 | { 21 | // Create the EMA indicator handle 22 | EmaHandle = iMA(_Symbol, PERIOD_CURRENT, 200, 0, MODE_EMA, AppliedPrice); 23 | 24 | if(EmaHandle == INVALID_HANDLE) 25 | { 26 | Print("Failed to create EMA indicator handle"); 27 | return(INIT_FAILED); 28 | } 29 | 30 | DailyEmaHandle = iMA(_Symbol, PERIOD_D1, 200, 0, MODE_EMA, AppliedPrice); 31 | if(DailyEmaHandle == INVALID_HANDLE) 32 | { 33 | Print("Failed to create EMA indicator handle"); 34 | return(INIT_FAILED); 35 | } 36 | 37 | // Array to store the EMA values 38 | double emaValues[]; 39 | double closingPrice; 40 | double emaValue; 41 | double dailyemaValues[]; 42 | double dailyemaValue; 43 | 44 | // Copy the last EMA value 45 | if(CopyBuffer(EmaHandle, 0, 0, 1, emaValues) > 0) 46 | { 47 | emaValue = emaValues[0]; 48 | Print("Current 200 EMA value: ", emaValue); 49 | } 50 | else 51 | { 52 | int error = GetLastError(); 53 | Print("Failed to copy EMA value. Error code: ", error); 54 | } 55 | 56 | if(CopyBuffer(DailyEmaHandle, 0, 0, 1, dailyemaValues) > 0) 57 | { 58 | dailyemaValue = dailyemaValues[0]; 59 | Print("Current Daily 200 EMA value: ", dailyemaValue); 60 | } 61 | else 62 | { 63 | int error = GetLastError(); 64 | Print("Failed to copy EMA value. Error code: ", error); 65 | } 66 | 67 | MqlRates rates[]; 68 | if(CopyRates(_Symbol, PERIOD_CURRENT, 0, 1, rates) > 0) 69 | { 70 | closingPrice = rates[0].close; 71 | Print("Current closing price of ", _Symbol, ": ", closingPrice); 72 | } 73 | else 74 | { 75 | Print("Failed to get rates data. Error code: ", GetLastError()); 76 | } 77 | 78 | 79 | double distancePercent = ((closingPrice - emaValue) / emaValue) * 100; 80 | Print("Distance in Percent: ", distancePercent, "%"); 81 | 82 | double dailydistancePercent = ((closingPrice - dailyemaValue) / dailyemaValue) * 100; 83 | Print("Daily Distance in Percent: ", dailydistancePercent, "%"); 84 | 85 | 86 | // Create a text label on the chart 87 | string labelName = "Daily-200EMA_Distance_Label-To-Current-Close-Price"; 88 | if (ObjectFind(0, labelName) == -1) 89 | { 90 | ObjectCreate(0, labelName, OBJ_LABEL, 0, 0, 0); 91 | } 92 | 93 | // Set the label properties 94 | ObjectSetString(0, labelName, OBJPROP_TEXT, dailydistancePercent); 95 | ObjectSetInteger(0, labelName, OBJPROP_CORNER, CORNER_RIGHT_UPPER); 96 | ObjectSetInteger(0, labelName, OBJPROP_XDISTANCE, 100); 97 | ObjectSetInteger(0, labelName, OBJPROP_YDISTANCE, 20); 98 | ObjectSetInteger(0, labelName, OBJPROP_COLOR, clrBlack); 99 | ObjectSetInteger(0, labelName, OBJPROP_FONTSIZE, 12); 100 | 101 | return(INIT_SUCCEEDED); 102 | } 103 | 104 | //+------------------------------------------------------------------+ 105 | //| Expert deinitialization function | 106 | //+------------------------------------------------------------------+ 107 | void OnDeinit(const int reason) 108 | { 109 | // Release the indicator handle 110 | if(EmaHandle != INVALID_HANDLE) 111 | IndicatorRelease(EmaHandle); 112 | } 113 | 114 | //+------------------------------------------------------------------+ 115 | //| Expert tick function | 116 | //+------------------------------------------------------------------+ 117 | void OnTick() 118 | { 119 | 120 | 121 | 122 | } 123 | -------------------------------------------------------------------------------- /RoundLevels.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| RoundLevels.mq5 | 3 | //| Copyright © 2020, Andriy Moraru | 4 | //| https://www.earnforex.com/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright © 2020 www.EarnForex.com" 7 | #property link "https://www.earnforex.com/metatrader-indicators/Round-Levels/" 8 | #property version "1.00" 9 | #property strict 10 | 11 | #property description "Generates round level zone background shading on chart." 12 | 13 | #property indicator_chart_window 14 | #property indicator_plots 0 15 | 16 | input int Levels = 5; // Levels - number of level zones in each direction. 17 | input int Interval = 50; // Interval between zones in points. 18 | input int ZoneWidth = 10; // Zone width in points. 19 | input color ColorUp = clrFireBrick; 20 | input color ColorDn = clrDarkGreen; 21 | input bool InvertZones = false; // Invert zones to shade the areas between round numbers. 22 | input bool DrawLines = false; // Draw lines on levels. 23 | input color LineColor = clrDarkGray; 24 | input int LineWidth = 1; 25 | input ENUM_LINE_STYLE LineStyle = STYLE_DASHDOT; 26 | input string ObjectPrefix = "RoundLevels"; 27 | 28 | enum direction 29 | { 30 | Up, 31 | Down 32 | }; 33 | 34 | void OnDeinit(const int reason) 35 | { 36 | ObjectsDeleteAll(0, ObjectPrefix); 37 | } 38 | 39 | int OnCalculate(const int rates_total, 40 | const int prev_calculated, 41 | const datetime& time[], 42 | const double& open[], 43 | const double& high[], 44 | const double& low[], 45 | const double& close[], 46 | const long& tick_volume[], 47 | const long& volume[], 48 | const int& spread[]) 49 | { 50 | double starting_price = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); 51 | 52 | for (int i = 0; i < Levels; i++) 53 | { 54 | // Calculate price levels below and above the current price. 55 | double lvl_down = FindNextLevel(NormalizeDouble(starting_price - i * Interval * _Point, _Digits), Down); 56 | double lvl_up = FindNextLevel(NormalizeDouble(starting_price + i * Interval * _Point, _Digits), Up); 57 | 58 | // Calculate and draw rectangle below current price. 59 | string name = ObjectPrefix + "D" + IntegerToString(i); 60 | double price1, price2; 61 | if (InvertZones) 62 | { 63 | price1 = lvl_down - (ZoneWidth / 2 * _Point); 64 | price2 = lvl_down - ((Interval - ZoneWidth / 2) * _Point); 65 | } 66 | else 67 | { 68 | price1 = lvl_down + (ZoneWidth / 2 * _Point); 69 | price2 = lvl_down - (ZoneWidth / 2 * _Point); 70 | } 71 | DrawRectangle(name, price1, price2, ColorDn); 72 | name = ObjectPrefix + "LD" + IntegerToString(i); 73 | if (DrawLines) DrawLine(name, lvl_down); 74 | 75 | // Calculate and draw rectangle above current price. 76 | name = ObjectPrefix + "U" + IntegerToString(i); 77 | if (InvertZones) 78 | { 79 | price1 = lvl_up + ((Interval - ZoneWidth / 2) * _Point); 80 | price2 = lvl_up + (ZoneWidth / 2 * _Point); 81 | } 82 | else 83 | { 84 | price1 = lvl_up + (ZoneWidth / 2 * _Point); 85 | price2 = lvl_up - (ZoneWidth / 2 * _Point); 86 | } 87 | DrawRectangle(name, price1, price2, ColorUp); 88 | name = ObjectPrefix + "LU" + IntegerToString(i); 89 | if (DrawLines) DrawLine(name, lvl_up); 90 | } 91 | 92 | // Center level required for inverted zones. 93 | if (InvertZones) 94 | { 95 | double lvl_down = FindNextLevel(NormalizeDouble(starting_price, _Digits), Down); 96 | double lvl_up = FindNextLevel(NormalizeDouble(starting_price, _Digits), Up); 97 | string name = ObjectPrefix + "C"; 98 | double price1 = lvl_up - (ZoneWidth / 2 * _Point); 99 | double price2 = lvl_down + (ZoneWidth / 2 * _Point); 100 | DrawRectangle(name, price1, price2, (ColorDn + ColorUp) / 2); 101 | name = ObjectPrefix + "LC"; 102 | if (DrawLines) 103 | { 104 | DrawLine(name, lvl_up); 105 | DrawLine(name, lvl_down); 106 | } 107 | } 108 | 109 | return(0); 110 | } 111 | 112 | double FindNextLevel(double sp, direction dir) 113 | { 114 | // Multiplier for getting number of points in the price. 115 | double multiplier = MathPow(10, _Digits); 116 | // Integer price (nubmer of points in the price). 117 | int integer_price = (int)MathRound(sp * MathPow(10, _Digits)); 118 | // Distance from the next round number down. 119 | int distance = integer_price % Interval; 120 | if (dir == Down) 121 | { 122 | return(NormalizeDouble(MathRound(integer_price - distance) / multiplier, _Digits)); 123 | } 124 | else if (dir == Up) 125 | { 126 | return(NormalizeDouble((integer_price + (Interval - distance)) / multiplier, _Digits)); 127 | } 128 | return(EMPTY_VALUE); 129 | } 130 | 131 | void DrawRectangle(string name, double price1, double price2, color colour) 132 | { 133 | if (ObjectFind(0, name) < 0) ObjectCreate(0, name, OBJ_RECTANGLE, 0, 0, 0); 134 | ObjectSetDouble(0, name, OBJPROP_PRICE, 0, price1); 135 | ObjectSetDouble(0, name, OBJPROP_PRICE, 1, price2); 136 | ObjectSetInteger(0, name, OBJPROP_TIME, 0, D'1970.01.01'); 137 | ObjectSetInteger(0, name, OBJPROP_TIME, 1, TimeLocal() + 60 * PeriodSeconds()); 138 | ObjectSetInteger(0, name, OBJPROP_COLOR, colour); 139 | ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false); 140 | ObjectSetInteger(0, name, OBJPROP_BACK, true); 141 | ObjectSetInteger(0, name, OBJPROP_FILL, true); 142 | } 143 | 144 | void DrawLine(string name, double price) 145 | { 146 | if (ObjectFind(0, name) < 0) ObjectCreate(0, name, OBJ_HLINE, 0, 0, 0); 147 | ObjectSetDouble(0, name, OBJPROP_PRICE, 0, price); 148 | ObjectSetInteger(0, name, OBJPROP_COLOR, LineColor); 149 | ObjectSetInteger(0, name, OBJPROP_STYLE, LineStyle); 150 | ObjectSetInteger(0, name, OBJPROP_WIDTH, LineWidth); 151 | ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false); 152 | } 153 | //+------------------------------------------------------------------+ 154 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Experts/EWM.ex5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lanastasov/mt-mql/0a5487edd3971a24a6cd811bb3fe61ed10aa6466/Salvador/ElliottWaveMaker 3.0/Experts/EWM.ex5 -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Experts/EWM.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| EWM.mq5 | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | #property version "3.0" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | Parser parser; 16 | Ewm ewm; 17 | P p(GetPointer(ewm.wave_labels)); 18 | Ewa ewa(GetPointer(ewm.wave_labels)); 19 | 20 | //+------------------------------------------------------------------+ 21 | //| Expert initialization function | 22 | //+------------------------------------------------------------------+ 23 | int OnInit() 24 | { 25 | ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, true); 26 | ewm.on_init(); 27 | p.on_init(); 28 | ewa.on_init(); 29 | ChartRedraw(); 30 | return(0); 31 | } 32 | //+------------------------------------------------------------------+ 33 | //| Expert deinitialization function | 34 | //+------------------------------------------------------------------+ 35 | void OnDeinit(const int reason) 36 | { 37 | ewm.on_deinit(reason); 38 | p.on_deinit(reason); 39 | ewa.on_deinit(reason); 40 | ChartRedraw(); 41 | } 42 | 43 | void OnTick() 44 | { 45 | ewm.set_time_vertical0(); 46 | } 47 | 48 | //+------------------------------------------------------------------+ 49 | //| ChartEvent function | 50 | //+------------------------------------------------------------------+ 51 | void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) 52 | { 53 | if(id == CHARTEVENT_OBJECT_DRAG) 54 | { 55 | if(StringFind(sparam, NAME_LABEL) >= 0) 56 | { 57 | ewm.on_label_drag(sparam); 58 | p.pitchforks.update(); 59 | } 60 | else if(StringFind(sparam, NAME_WAVE) >= 0 || StringFind(sparam, NAME_AUTO_WAVE) >= 0) 61 | { 62 | ewm.on_wave_drag(sparam); 63 | p.pitchforks.update(); 64 | } 65 | } 66 | if(id == CHARTEVENT_CLICK || id == CHARTEVENT_CHART_CHANGE || id == CHARTEVENT_OBJECT_CHANGE) 67 | { 68 | ewm.wave_labels.correct(); 69 | } 70 | if(id == CHARTEVENT_OBJECT_DELETE) 71 | { 72 | if(StringFind(sparam, NAME_WAVE) >= 0 || StringFind(sparam, NAME_AUTO_WAVE) >= 0) 73 | { 74 | p.on_remove_pitchfork(sparam); 75 | ewm.on_remove_wave(sparam); 76 | } 77 | } 78 | if(id == CHARTEVENT_OBJECT_CLICK) 79 | { 80 | if(StringFind(sparam, NAME_LABEL) >= 0) 81 | { 82 | ewm.on_label_click(sparam); 83 | } 84 | else if(StringFind(sparam, NAME_WAVE) >= 0 || StringFind(sparam, NAME_AUTO_WAVE) >= 0) 85 | { 86 | ewm.on_wave_click(sparam); 87 | if(StringFind(sparam, NAME_AUTO_WAVE) >= 0) 88 | { 89 | ewa.get_name_wave("", GetPointer(ewm.wave_labels)); 90 | } 91 | } 92 | } 93 | if(id == CHARTEVENT_CLICK) 94 | { 95 | ewm.on_chart_click((int)lparam, (int)dparam); 96 | p.insert_pitchfork((int)lparam, (int)dparam); 97 | p.pitchforks.update(); 98 | } 99 | if(id == CHARTEVENT_KEYDOWN) 100 | { 101 | switch((int)lparam) 102 | { 103 | case PREV_LEVEL: 104 | ewm.on_prev_level(); 105 | break; 106 | case NEXT_LEVEL: 107 | ewm.on_next_level(); 108 | break; 109 | case UP_LEVEL: 110 | ewm.on_up_level(); 111 | p.pitchforks.update(); 112 | break; 113 | case DOWN_LEVEL: 114 | ewm.on_down_level(); 115 | p.pitchforks.update(); 116 | break; 117 | case HIDE_PANEL: 118 | ewm.on_hide_panel(); 119 | break; 120 | case STOP_MARKING: 121 | ewm.on_stop_marking(); 122 | break; 123 | case START_MARKING: 124 | ewm.on_start_marking(); 125 | break; 126 | case SELECT_GROUP: 127 | ewm.on_select_group(); 128 | break; 129 | case DELETE_OBJECT: 130 | ewm.wave_labels.correct(); 131 | break; 132 | case INCREASE_LEVEL: 133 | ewm.on_increase_level(); 134 | p.pitchforks.update(); 135 | break; 136 | case REDUCE_LEVEL: 137 | ewm.on_reduce_level(); 138 | p.pitchforks.update(); 139 | break; 140 | case SELECT: 141 | ewm.wave_labels.select = ! ewm.wave_labels.select; 142 | break; 143 | case START_ANALYSIS_LEFT: 144 | ewa.analysis_left(GetPointer(ewm.wave_labels)); 145 | break; 146 | case START_ANALYSIS_RIGHT: 147 | ewa.analysis_right(GetPointer(ewm.wave_labels)); 148 | break; 149 | case PREV_VARIANT_LEFT: 150 | ewa.select("PrevLeft", GetPointer(ewm.wave_labels)); 151 | ewa.get_name_wave("PrevLeft", GetPointer(ewm.wave_labels)); 152 | break; 153 | case NEXT_VARIANT_LEFT: 154 | ewa.select("NextLeft", GetPointer(ewm.wave_labels)); 155 | ewa.get_name_wave("NextLeft", GetPointer(ewm.wave_labels)); 156 | break; 157 | case PREV_VARIANT_RIGHT: 158 | ewa.select("PrevRight", GetPointer(ewm.wave_labels)); 159 | ewa.get_name_wave("PrevRight", GetPointer(ewm.wave_labels)); 160 | break; 161 | case NEXT_VARIANT_RIGHT: 162 | ewa.select("NextRight", GetPointer(ewm.wave_labels)); 163 | ewa.get_name_wave("NextRight", GetPointer(ewm.wave_labels)); 164 | break; 165 | case CONVERT: 166 | ewa.convert(); 167 | break; 168 | case CLEAR: 169 | ewm.clear(); 170 | ewa.clear(); 171 | break; 172 | case GET_NAME_WAVE_LEFT: 173 | ewa.get_name_wave("", GetPointer(ewm.wave_labels)); 174 | break; 175 | case GET_NAME_WAVE_RIGHT: 176 | ewa.get_name_wave("NextRight", GetPointer(ewm.wave_labels)); 177 | break; 178 | case COPY_CHART: 179 | { 180 | long chart_id = ChartOpen(_Symbol, _Period); 181 | ewm.panel.remove(); 182 | ChartSaveTemplate(0, "EWM"); 183 | ChartApplyTemplate(chart_id, "EWM.tpl"); 184 | ChartRedraw(chart_id); 185 | ewm.panel.create(); 186 | break; 187 | } 188 | case SHOW_HORIZONTAL: 189 | ewm.on_show_horizontal(); 190 | break; 191 | case HIDE_ALL_HORIZONTAL: 192 | ewm.on_hide_all_horizontal(); 193 | break; 194 | case SHOW_PRICE_LABEL: 195 | ewm.on_show_price_label(); 196 | break; 197 | case HIDE_ALL_PRICE_LABEL: 198 | ewm.on_hide_all_price_label(); 199 | break; 200 | case SHOW_VETICAL: 201 | ewm.on_show_vertical(); 202 | break; 203 | case HIDE_ALL_VERTICAL: 204 | ewm.on_hide_all_vertical(); 205 | break; 206 | case SHOW_VERTICAL0: 207 | ewm.on_show_vertical0(); 208 | break; 209 | case SHOW_SCHIFF: 210 | p.on_show_schiff(); 211 | break; 212 | case SHOW_WARNING_UP: 213 | p.on_show_warning_up(); 214 | break; 215 | case SHOW_WARNING_DOWN: 216 | p.on_show_warning_down(); 217 | break; 218 | case HIDE_PITCHFORK: 219 | p.on_hide_pitchfork(); 220 | break; 221 | } 222 | } 223 | ChartRedraw(); 224 | } -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Files/EWM.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lanastasov/mt-mql/0a5487edd3971a24a6cd811bb3fe61ed10aa6466/Salvador/ElliottWaveMaker 3.0/Files/EWM.txt -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/defines.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| defines.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | 11 | // ewm 12 | #define PREV_LEVEL 'Q' // show the previous wave level on the labels panel 13 | #define NEXT_LEVEL 'W' // show the next wave level on the labels panel 14 | #define DOWN_LEVEL 'A' // decrease the wave labels' level 15 | #define UP_LEVEL 'S' // increase the wave labels' level 16 | #define START_MARKING 'Z' // start marking waves 17 | #define STOP_MARKING 'X' // stop marking waves 18 | #define SELECT_GROUP 0x09 // select/deselect groups of wave labels (press Tab key) 19 | #define HIDE_PANEL 0x1B // hide/show the labels panel (press Esc key) 20 | #define INCREASE_LEVEL 'E' // reduce the number of wave levels displayed in the chart 21 | #define REDUCE_LEVEL 'R' // increase the number of wave levels displayed in the chart 22 | #define DELETE_OBJECT 0x2E // delete selected object (press Del key) 23 | #define SELECT 0x10 // start/stop the labels selection process (press Shift key) 24 | #define SHIFT_X 3 // padding of the chart frame along the X-axis 25 | #define SHIFT_Y 5 // padding of the chart frame along the Y-axis 26 | #define UP true // increases the wave level 27 | #define DOWN false // decreases the wave level 28 | #define LEVEL 0 // the wave label level 29 | #define TEXT 1 //text of the label 30 | #define GROUP 2 // the group of the wave label 31 | #define UNIQUE_NAME 3 // the unique name of the wave label on which it is identified 32 | #define LABELS 15 // the number of one wave level labels 33 | #define DELAY 100 // delay of the cycle in milliseconds 34 | #define TOP true // the wave label located above the bar 35 | #define BOTTOM false // the wave label located below the bar 36 | #define EVERY_BAR 1 // the possibility to set the wave label above/below each bar 37 | #define NOT_EVERY_BAR 0 // the possibility to set the wave label above/below each 3-bar fractal 38 | #define SEPARATOR "_" // separator 39 | #define NAME_LABEL "$L$" // the name of the label in the labels panel 40 | #define NAME_WAVE "$W$" // the name of the wave label 41 | 42 | // ewa 43 | #define START_ANALYSIS_LEFT '1' // analyze the whole chart/analyze from the left of the selected wave 44 | #define START_ANALYSIS_RIGHT '2' // analyze the whole chart/analyze from the right of the selected wave 45 | #define PREV_VARIANT_LEFT '3' // show the previous variants of the selected wave labeling 46 | #define NEXT_VARIANT_LEFT '4' // show the following variants of the selected wave labeling 47 | #define PREV_VARIANT_RIGHT '5' // show the previous variants of the wave labeling located to the right from the selected wave 48 | #define NEXT_VARIANT_RIGHT '6' // show the following variants of the wave labeling located to the right from the selected wave 49 | #define CONVERT 'V' // convert automatic labeling manually 50 | #define CLEAR 'C' // clear the chart 51 | #define GET_NAME_WAVE_LEFT '7' // get the name of the selected wave 52 | #define GET_NAME_WAVE_RIGHT '8' // get the name of the wave l;ocated to the right from the selected wave 53 | #define NAME_AUTO_WAVE "$A$" // the unique name of the wave label created using auto labeling 54 | #define MAX_POINTS 6 // the maximum number of points for identification 55 | #define TREND_UP "Up" // trend up 56 | #define TREND_DOWN "Down" // trend down 57 | #define MORE ">=" // more or equal 58 | #define LESS "<=" // less or equal 59 | #define MIN "min" // the minimum wave value 60 | #define MAX "max" // the maximum wave value 61 | #define VAL "val" // height value 62 | #define LENGTH "length" // length ratio 63 | #define TIME "time" // time ratio 64 | #define EOF 26 // identifier of file end 65 | #define LEFT true // 66 | #define RIGHT false // 67 | #define TYPE1 1 // type of analysis - completed waves analysis 68 | #define TYPE2 2 // the type of analysis - the unbegun waves analysis 69 | #define TYPE3 3 // the type of analysis - the unfinished waves analysis 70 | #define TYPE4 4 // the type of analysis - unbegun and unfinished waves analysis 71 | #define MSG_BEGIN_ANALYSIS "Start an analysis?" 72 | #define MSG_SELECTED_MORE "An analysis is impossible as more than one wave is selected!" 73 | #define MSG_ANALYSIS_COMPLETED "An analysis is complete!" 74 | #define MSG_REMOVE "All labels will be deleted!" 75 | #define MSG_CLEAR "Delete all labels from the chart?" 76 | #define NAME_RULES_FILE "EWM.txt" 77 | #define MSG_FILE_OPEN_ERROR "The EWM.txt file open error!" 78 | 79 | #define COPY_CHART 'J' // create a copy of chart with all objects 80 | 81 | // pitchfork 82 | #define SHOW_SCHIFF 'U' 83 | #define SHOW_WARNING_UP 'D' 84 | #define SHOW_WARNING_DOWN 'F' 85 | #define NAME_PITCHFORK "$P$" 86 | #define NAME_SCHIFF "$S$" 87 | #define NAME_REACTION "$R$" 88 | #define NAME_WARNING_UP "$WU$" 89 | #define NAME_WARNING_DOWN "$WD$" 90 | #define PITCHFORK_LEVEL1 0 91 | #define PITCHFORK_TEXT1 1 92 | #define PITCHFORK_GROUP1 2 93 | #define PITCHFORK_LEVEL2 3 94 | #define PITCHFORK_TEXT2 4 95 | #define PITCHFORK_GROUP2 5 96 | #define PITCHFORK_LEVEL3 6 97 | #define PITCHFORK_TEXT3 7 98 | #define PITCHFORK_GROUP3 8 99 | #define PITCHFORK_NAME 9 100 | #define PITCHFORK_VISIBLE 10 101 | #define HIDE_PITCHFORK 'P' 102 | #define NAME_PRICE_LABEL "$PL$" 103 | #define NAME_HORIZONTAL "$H$" 104 | #define NAME_VERTICAL "$V$" 105 | #define NAME_VERTICAL0 "$V0$" 106 | #define SHOW_HORIZONTAL 'T' 107 | #define HIDE_ALL_HORIZONTAL 'Y' 108 | #define SHOW_PRICE_LABEL 'G' 109 | #define HIDE_ALL_PRICE_LABEL 'H' 110 | #define SHOW_VETICAL 'B' 111 | #define HIDE_ALL_VERTICAL 'N' 112 | #define SHOW_VERTICAL0 'M' 113 | 114 | double schiff_levels1[] = {-0.764, -1.000}; 115 | double schiff_levels2[] = {-0.764, -1.000, 0.000}; 116 | double pitchfork_levels[] = {-0.764}; 117 | 118 | CArrayDouble warning_levels; 119 | CArrayDouble reaction_levels; 120 | 121 | string etalon[] = {"1", "2", "3", "4", "5", "A", "B", "C", "D", "E", "W", "X", "Y", "XX", "Z"}; 122 | 123 | MqlRates rates[]; 124 | 125 | // timeframws on which all objects are displayed 126 | int tfs[] = {OBJ_PERIOD_M1, OBJ_PERIOD_M2, OBJ_PERIOD_M3, OBJ_PERIOD_M4, OBJ_PERIOD_M5, OBJ_PERIOD_M6, OBJ_PERIOD_M10, OBJ_PERIOD_M12, OBJ_PERIOD_M15, OBJ_PERIOD_M20, OBJ_PERIOD_M30, OBJ_PERIOD_H1, OBJ_PERIOD_H2, OBJ_PERIOD_H3, OBJ_PERIOD_H4, OBJ_PERIOD_H6, OBJ_PERIOD_H8, OBJ_PERIOD_H12, OBJ_PERIOD_D1, OBJ_PERIOD_W1, OBJ_PERIOD_MN1}; 127 | 128 | // chart periods 129 | int periods[] = {PERIOD_M1, PERIOD_M2, PERIOD_M3, PERIOD_M4, PERIOD_M5, PERIOD_M6, PERIOD_M10, PERIOD_M12, PERIOD_M15, PERIOD_M20, PERIOD_M30, PERIOD_H1, PERIOD_H2, PERIOD_H3, PERIOD_H4, PERIOD_H6, PERIOD_H8, PERIOD_H12, PERIOD_D1, PERIOD_W1, PERIOD_MN1}; 130 | 131 | input int interval = 25; // The distance between the labels on the labels panel 132 | input int x_distance = 10; // The position of the labels panel along the X-axis 133 | input int y_distance = 10; // The position of the labels panel along the Y-axis 134 | input color red_zone_color = clrSalmon; // "Red zone" boundary color 135 | input color verical0_color = LightGray; // Vertical line on the 0 bar color 136 | 137 | struct Coord 138 | { 139 | double price1; 140 | double price2; 141 | double price3; 142 | double price4; 143 | double pos1; 144 | double pos2; 145 | double pos3; 146 | double pos4; 147 | }; 148 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewa/counted.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lanastasov/mt-mql/0a5487edd3971a24a6cd811bb3fe61ed10aa6466/Salvador/ElliottWaveMaker 3.0/Include/EWM/ewa/counted.mqh -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewa/node.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| node.mqh | 3 | //| Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | #include 9 | #include 10 | #include "Wave.mqh" 11 | 12 | class Node : public CObject 13 | { 14 | public: 15 | CArrayObj childs; 16 | Wave *wave; 17 | string text; 18 | Node *parent; 19 | bool selected; 20 | Node *add(string text, Wave *wave = NULL); 21 | void clear(); 22 | }; 23 | 24 | Node *Node::add(string text, Wave *wave = NULL) 25 | { 26 | Node *node = new Node; 27 | node.parent = GetPointer(this); 28 | node.selected = false; 29 | node.text = text; 30 | node.wave = wave; 31 | childs.Add(node); 32 | return(node); 33 | } 34 | 35 | void Node::clear() 36 | { 37 | for(int i = 0; i < childs.Total(); i++) 38 | { 39 | if(CheckPointer(childs.At(i)) != POINTER_INVALID) 40 | { 41 | Node *node = childs.At(i); 42 | node.clear(); 43 | } 44 | } 45 | childs.FreeMode(true); 46 | childs.Clear(); 47 | if(CheckPointer(wave) != POINTER_INVALID) 48 | { 49 | delete wave; 50 | } 51 | } -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewa/patterns.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| patterns.mqh | 3 | //| Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "wave.mqh" 15 | #include "rules.mqh" 16 | 17 | class Target : public CObject 18 | { 19 | public: 20 | string type; 21 | int num_wave1; 22 | int num_wave2; 23 | int num_wave3; 24 | int num_wave4; 25 | double ratio; 26 | }; 27 | 28 | class Targets : public CArrayObj 29 | { 30 | 31 | }; 32 | 33 | class Time_targets : public Targets 34 | { 35 | 36 | }; 37 | 38 | class Fibo : public CObject 39 | { 40 | public: 41 | int num_wave1; 42 | int num_wave2; 43 | double score; 44 | double low; 45 | double middle; 46 | double high; 47 | }; 48 | 49 | class Value_fibos : public CArrayObj 50 | { 51 | public: 52 | double get_score(int num_wave1, int num_wave2, double ratio); 53 | }; 54 | 55 | double Value_fibos::get_score(int num_wave1, int num_wave2, double ratio) 56 | { 57 | double score = 0; 58 | for(int i = 0; i < Total(); i++) 59 | { 60 | Fibo *fibo = At(i); 61 | if(fibo.num_wave1 == num_wave1 && fibo.num_wave2 == num_wave2) 62 | { 63 | if(ratio > fibo.low && ratio < fibo.high) 64 | { 65 | if(ratio < fibo.middle) 66 | { 67 | score += fibo.score * (1 - (ratio - fibo.low) / (fibo.middle - fibo.low)) * 100; 68 | } 69 | else if(ratio > fibo.middle) 70 | { 71 | score += fibo.score * (1 - (fibo.high - ratio) / (fibo.high - fibo.middle)) * 100; 72 | } 73 | else 74 | { 75 | score += fibo.score*100; 76 | } 77 | } 78 | } 79 | } 80 | return(score); 81 | } 82 | 83 | class Time_fibos : public Value_fibos 84 | { 85 | 86 | }; 87 | 88 | class Proportion_fibos : public Value_fibos 89 | { 90 | 91 | }; 92 | 93 | class Proportion_fibos_required : public Value_fibos 94 | { 95 | 96 | }; 97 | 98 | class Subwaves_descr : public CObject 99 | { 100 | public: 101 | string wave_label; 102 | double ratio1; 103 | double ratio2; 104 | int num_wave1; 105 | int num_wave2; 106 | CArrayDouble probability; 107 | CArrayString name_wave; 108 | }; 109 | 110 | class Subwaves : public CArrayObj 111 | { 112 | 113 | }; 114 | 115 | class Pattern : public CObject 116 | { 117 | public: 118 | string name; 119 | string type; 120 | double probability; 121 | string descr; 122 | int num_wave; 123 | Rules rules; 124 | Guidelines guidelines; 125 | Subwaves subwaves; 126 | Rules entry_signals; 127 | Rules exit_signals; 128 | Rules stop_signals; 129 | Rules wave_signals; 130 | Rules confirm_signals; 131 | Time_fibos time_fibos; 132 | Value_fibos value_fibos; 133 | Proportion_fibos proportion_fibos; 134 | Proportion_fibos_required proportion_fibos_required; 135 | Targets targets; 136 | Time_targets time_targets; 137 | bool check(Wave *wave); 138 | }; 139 | 140 | bool Pattern::check(Wave *wave) 141 | { 142 | bool b = true; 143 | int j = -1; 144 | int k = -1; 145 | for(int i = 0; i <= 5; i++) 146 | { 147 | if(wave.fixed[i] == 1 && b) 148 | { 149 | j = i; 150 | b = false; 151 | } 152 | else if(wave.fixed[i] == 1) 153 | { 154 | k = i; 155 | } 156 | } 157 | int trend1 = 0; 158 | int trend2 = 0; 159 | for(int i = j; i < k; i++) 160 | { 161 | if((i % 2 == 0 && wave.value[i + 1] > wave.value[i]) || (i % 2==1 && wave.value[i] > wave.value[i + 1])) 162 | { 163 | trend1++; 164 | } 165 | else if((i % 2 == 0 && wave.value[i] > wave.value[i + 1]) || (i % 2 == 1 && wave.value[i + 1] > wave.value[i])) 166 | { 167 | trend2++; 168 | } 169 | } 170 | if((trend1 == 0 && trend2 == 0) || (trend1 > 0 && trend2 > 0)) 171 | { 172 | return(false); 173 | } 174 | else if(trend1 == k - j) 175 | { 176 | wave.trend = TREND_UP; 177 | } 178 | else if(trend2 == k - j) 179 | { 180 | wave.trend = TREND_DOWN; 181 | } 182 | for(int i = 1; i <= 5; i++) 183 | { 184 | if((wave.fixed[i - 1]==0 && wave.fixed[i]==1) || (wave.fixed[i - 1]==1 && wave.fixed[i]==1) || (wave.fixed[i - 1] == 1 && wave.fixed[i] == 0)) 185 | { 186 | wave.maximum[i] = rates[wave.index[i]].high; 187 | wave.minimum[i] = rates[wave.index[i]].low; 188 | for(j = wave.index[i - 1]; j <= wave.index[i]; j++) 189 | { 190 | if(rates[j].high > wave.maximum[i]) 191 | { 192 | wave.maximum[i] = rates[j].high; 193 | } 194 | if(rates[j].low < wave.minimum[i]) 195 | { 196 | wave.minimum[i] = rates[j].low; 197 | } 198 | } 199 | if(wave.fixed[i - 1] == 0 && wave.fixed[i] == 1) 200 | { 201 | if((i % 2 == 0 && wave.trend == TREND_UP) || (i % 2 == 1 && wave.trend == TREND_DOWN)) 202 | { 203 | wave.value[i - 1] = wave.maximum[i]; 204 | } 205 | else 206 | { 207 | wave.value[i - 1] = wave.minimum[i]; 208 | } 209 | } 210 | else if(wave.fixed[i - 1] == 1 && wave.fixed[i] == 0) 211 | { 212 | if((i % 2 == 0 && wave.trend == TREND_UP) || (i % 2 == 1 && wave.trend == TREND_DOWN)) 213 | { 214 | wave.value[i] = wave.minimum[i]; 215 | } 216 | else 217 | { 218 | wave.value[i] = wave.maximum[i]; 219 | } 220 | } 221 | wave.length[i] = MathAbs(wave.value[i] - wave.value[i - 1]); 222 | wave.time[i] = wave.index[i] - wave.index[i - 1] + 1/2; 223 | } 224 | } 225 | if( ! rules.get_result(wave)) 226 | { 227 | return(false); 228 | } 229 | for(int i = 1; i <= 5; i++) 230 | { 231 | for(j = 1; j <= 5; j++) 232 | { 233 | wave.length_ratio[i][j] = -1; 234 | wave.time_ratio[i][j] = -1; 235 | if(wave.fixed[i] == 1 && wave.fixed[i - 1] == 1 && wave.fixed[j]==1 && wave.fixed[j - 1] == 1) 236 | { 237 | wave.length_ratio[i][j] = wave.length[i] / wave.length[j]; 238 | wave.time_ratio[i][j] = wave.time[i] / wave.time[j]; 239 | wave.value_fibo_score += value_fibos.get_score(i, j, wave.length_ratio[i][j]); 240 | wave.time_fibo_score += time_fibos.get_score(i, j, wave.time_ratio[i][j]); 241 | wave.proportion_fibo_score += proportion_fibos.get_score(i, j, wave.length_ratio[i][j]); 242 | } 243 | } 244 | } 245 | wave.fibo_score = 0.25 * wave.value_fibo_score + 0.25 * wave.time_fibo_score + 0.5 * wave.proportion_fibo_score; 246 | wave.pattern_score = 0.11 * probability + 0.3 * wave.fibo_score; 247 | return(true); 248 | } 249 | 250 | class Patterns : public CArrayObj 251 | { 252 | public: 253 | Pattern * find(string name); 254 | void clear(); 255 | }; 256 | 257 | Patterns patterns; 258 | 259 | Pattern *Patterns::find(string name) 260 | { 261 | for(int i = 0; i < Total(); i++) 262 | { 263 | Pattern *pattern = At(i); 264 | if(pattern.name == name) 265 | { 266 | return(pattern); 267 | } 268 | } 269 | return(NULL); 270 | } -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewa/wave.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| wave.mqh | 3 | //| Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | 11 | class Wave : public CObject 12 | { 13 | public: 14 | string name; 15 | int level; 16 | int num_zigzag; 17 | string trend; 18 | //Wave *parent_wave; 19 | double value[6]; 20 | int index[6]; 21 | int fixed[6]; 22 | double maximum[6]; 23 | double minimum[6]; 24 | double length_ratio[6][6]; 25 | double time_ratio[6][6]; 26 | double length[6]; 27 | double time[6]; 28 | double value_fibo_score; 29 | double time_fibo_score; 30 | double proportion_fibo_score; 31 | double fibo_score; 32 | double pattern_score; 33 | }; 34 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewa/zigzags.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| zigzags.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | class Zigzag : public CObject 16 | { 17 | CArrayInt index; 18 | CArrayDouble value; 19 | public: 20 | void Zigzag(int param, int index1, int index2, int type); 21 | int get_total(); 22 | CArrayInt *get_index(); 23 | CArrayDouble *get_value(); 24 | int find_index(int key, bool less); 25 | }; 26 | 27 | void Zigzag::Zigzag(int param, int index1, int index2, int type) 28 | { 29 | bool up = true; 30 | double dparam; 31 | if(_Digits == 5 || _Digits == 3) 32 | { 33 | dparam = param * _Point * 10; 34 | } 35 | else 36 | { 37 | dparam = param * _Point; 38 | } 39 | int max_bar = index1; 40 | int min_bar = index1; 41 | double max = rates[max_bar].high; 42 | double min = rates[min_bar].low; 43 | bool is_first; 44 | if(type == TYPE1 || type == TYPE3) 45 | { 46 | is_first = false; 47 | } 48 | else 49 | { 50 | is_first = true; 51 | } 52 | for(int i = index1 + 1; i <= index2; i++) 53 | { 54 | if(up == true || ! is_first) 55 | { 56 | if(rates[i].high > max) 57 | { 58 | max = rates[i].high; 59 | max_bar = i; 60 | } 61 | else if(rates[i].low < max - dparam) 62 | { 63 | value.Add(max); 64 | index.Add(max_bar); 65 | up = false; 66 | min = rates[i].low; 67 | min_bar = i; 68 | is_first = true; 69 | continue; 70 | } 71 | } 72 | if( ! up || ! is_first) 73 | { 74 | if(rates[i].low < min) 75 | { 76 | min = rates[i].low; 77 | min_bar = i; 78 | } 79 | else if(rates[i].high > min + dparam) 80 | { 81 | value.Add(min); 82 | index.Add(min_bar); 83 | up = true; 84 | max = rates[i].high; 85 | max_bar = i; 86 | is_first = true; 87 | } 88 | } 89 | } 90 | if(type == TYPE1 || type == TYPE2) 91 | { 92 | if(up) 93 | { 94 | value.Add(max); 95 | index.Add(max_bar); 96 | } 97 | else 98 | { 99 | value.Add(min); 100 | index.Add(min_bar); 101 | } 102 | } 103 | } 104 | 105 | int Zigzag::get_total() 106 | { 107 | return(index.Total()); 108 | } 109 | 110 | CArrayInt *Zigzag::get_index() 111 | { 112 | return(GetPointer(index)); 113 | } 114 | 115 | CArrayDouble *Zigzag::get_value() 116 | { 117 | return(GetPointer(value)); 118 | } 119 | 120 | int Zigzag::find_index(int key, bool less) 121 | { 122 | int left = 0; 123 | int right = index.Total() - 1; 124 | while(left <= right) 125 | { 126 | int middle = (left + right) / 2; 127 | if(key < index.At(middle)) 128 | { 129 | right = middle - 1; 130 | } 131 | else if(key > index.At(middle)) 132 | { 133 | left = middle + 1; 134 | } 135 | else 136 | { 137 | return(middle); 138 | } 139 | } 140 | if(less) 141 | { 142 | return(right); 143 | } 144 | else 145 | { 146 | return(left); 147 | } 148 | } 149 | 150 | class Points 151 | { 152 | public: 153 | CArrayInt index; 154 | CArrayDouble value; 155 | int num_zigzag; 156 | }; 157 | 158 | class Zigzags : public CArrayObj 159 | { 160 | public: 161 | void create(int index1, int index2, int type); 162 | void remove(); 163 | bool get_points(int num_points, int index1, int index2, double value1, double value2, Points *points, int num_zigzag); 164 | int find(int key, CArrayInt *index, bool b); 165 | }; 166 | 167 | Zigzags zigzags; 168 | 169 | void Zigzags::create(int index1, int index2, int type) 170 | { 171 | int param = 1; 172 | Zigzag *zigzag = new Zigzag(param++, index1, index2, type); 173 | if(zigzag.get_total() >= 2) 174 | { 175 | Add(zigzag); 176 | while(true) 177 | { 178 | zigzag = new Zigzag(param++, index1, index2, type); 179 | if(zigzag.get_total() < 2) 180 | { 181 | delete zigzag; 182 | break; 183 | } 184 | Zigzag *temp_zigzag = At(Total() - 1); 185 | CArrayInt *index = zigzag.get_index(); 186 | if(temp_zigzag.get_total() == zigzag.get_total() && index.CompareArray(temp_zigzag.get_index())) 187 | { 188 | delete zigzag; 189 | } 190 | else 191 | { 192 | Add(zigzag); 193 | } 194 | } 195 | } 196 | else 197 | { 198 | delete zigzag; 199 | } 200 | } 201 | 202 | void Zigzags::remove() 203 | { 204 | FreeMode(true); 205 | Clear(); 206 | } 207 | 208 | bool Zigzags::get_points(int num_points, int index1, int index2, double value1, double value2, Points *points, int num_zigzag) 209 | { 210 | points.num_zigzag = -1; 211 | points.index.Clear(); 212 | points.value.Clear(); 213 | for(int i = num_zigzag; i >= 0; i--) 214 | { 215 | Zigzag *zigzag = At(i); 216 | CArrayInt *index = zigzag.get_index(); 217 | int temp_index1 = zigzag.find_index(index1, false); 218 | int temp_index2 = zigzag.find_index(index2, true); 219 | int n = temp_index2 - temp_index1 + 1; 220 | if(n >= num_points) 221 | { 222 | CArrayDouble *value = zigzag.get_value(); 223 | if((value1 > 0 && value.At(temp_index1) != value1 && index.At(temp_index1) != index1) || (value2 > 0 && value.At(temp_index2) != value2 && index.At(temp_index2) != index2)) 224 | { 225 | continue; 226 | } 227 | points.num_zigzag = i; 228 | for(int j = temp_index1; j <= temp_index2; j++) 229 | { 230 | points.index.Add(index.At(j)); 231 | points.value.Add(value.At(j)); 232 | } 233 | return(true); 234 | } 235 | } 236 | return(false); 237 | } 238 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/descrs.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Descrs.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | 12 | class Descr : public CObject 13 | { 14 | public: 15 | int num_level; 16 | string level; 17 | string labels[15]; 18 | string font; 19 | int font_size; 20 | int size_in_px; 21 | color clr; 22 | }; 23 | 24 | class Descrs : public CArrayObj 25 | { 26 | 27 | }; 28 | 29 | Descrs descrs; -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/ewm.mqh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lanastasov/mt-mql/0a5487edd3971a24a6cd811bb3fe61ed10aa6466/Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/ewm.mqh -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/horizontal.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| horizontal.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | class Horizontal : public CChartObjectTrend 14 | { 15 | public: 16 | void create(string wave_label_name, datetime time, double price, bool pos, int tf); 17 | void update(string wave_label_name, datetime time, double price, bool pos, int tf); 18 | datetime get_time(datetime time1, double price1, bool pos); 19 | bool Time(int point, datetime time) 20 | { 21 | return(ObjectSetInteger(0, Name(), OBJPROP_TIME, point, time)); 22 | } 23 | bool Price(int point, double price) 24 | { 25 | return(ObjectSetDouble(0, Name(), OBJPROP_PRICE, point, price)); 26 | } 27 | }; 28 | 29 | datetime Horizontal::get_time(datetime time1, double price1, bool pos) 30 | { 31 | datetime times[]; 32 | while(CopyTime(_Symbol, _Period, 0, 1, times) != 1) 33 | { 34 | Sleep(DELAY); 35 | } 36 | datetime time2 = times[0]; 37 | MqlRates temp_rates[]; 38 | int bars = Bars(_Symbol, _Period, time1, times[0]); 39 | while(CopyRates(_Symbol, _Period, time1, times[0], temp_rates) != bars) 40 | { 41 | Sleep(DELAY); 42 | } 43 | for(int i = 0; i < bars; i++) 44 | { 45 | if((pos && temp_rates[i].high >= price1) || (! pos && temp_rates[i].low <= price1)) 46 | { 47 | time2 = temp_rates[i].time; 48 | break; 49 | } 50 | } 51 | return(time2); 52 | } 53 | 54 | void Horizontal::create(string wave_label_name, datetime time, double price, bool pos, int tf) 55 | { 56 | Create(0, replace(wave_label_name, UNIQUE_NAME, NAME_HORIZONTAL), 0, time, price, get_time(time, price, pos), price); 57 | Color(pos == false ? clrRed : clrBlue); 58 | Style(STYLE_DOT); 59 | Timeframes(tf); 60 | } 61 | 62 | void Horizontal::update(string wave_label_name, datetime time, double price, bool pos, int tf) 63 | { 64 | Name(replace(wave_label_name, UNIQUE_NAME, NAME_HORIZONTAL)); 65 | Time(0, time); 66 | Price(0, price); 67 | Time(1, get_time(time, price, pos)); 68 | Price(1, price); 69 | Color(pos == false ? clrRed : clrBlue); 70 | Style(STYLE_DOT); 71 | Timeframes(tf); 72 | } 73 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/label.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| label.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // the class of the wave label 15 | class Label : public CChartObjectLabel 16 | { 17 | public: 18 | void create(string name, int x, int y, bool selectable, ENUM_ANCHOR_POINT anchor, int timeframe, bool b = true); 19 | int get_font_size(); // get the font size of the label 20 | color get_color(); // get the label color 21 | string get_font(); // get the label font 22 | }; 23 | 24 | void Label::create(string name, int x, int y, bool selectable, ENUM_ANCHOR_POINT anchor, int timeframe, bool b = true) 25 | { 26 | Create(0, name, 0, x, y); 27 | Selectable(selectable); 28 | Timeframes(timeframe); 29 | Anchor(anchor); 30 | Z_Order(100); 31 | if(b) 32 | { 33 | Description(get_text(Name())); 34 | Font(get_font()); 35 | FontSize(get_font_size()); 36 | Color(get_color()); 37 | } 38 | Descr *descr = descrs.At(get_level(Name())); 39 | Tooltip(Description() + ": " + descr.level); 40 | } 41 | 42 | int Label::get_font_size() 43 | { 44 | Descr *descr = descrs.At(get_level(Name())); 45 | return(descr.font_size); 46 | } 47 | 48 | color Label::get_color() 49 | { 50 | Descr *descr = descrs.At(get_level(Name())); 51 | return(descr.clr); 52 | } 53 | 54 | string Label::get_font() 55 | { 56 | Descr *descr = descrs.At(get_level(Name())); 57 | return(descr.font); 58 | } 59 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/labels.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| labels.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include "label.mqh" 11 | 12 | class Labels : public CArrayObj 13 | { 14 | public: 15 | int current_label; 16 | bool click_label; 17 | void Labels() 18 | { 19 | current_label = 0; 20 | click_label = false; 21 | } 22 | Label *get(string name); 23 | int get_selected(); 24 | void click(string name); 25 | }; 26 | 27 | Label *Labels::get(string name) 28 | { 29 | for(int i = 0; i < Total(); i++) 30 | { 31 | Label *label = At(i); 32 | if(label.Name() == name) 33 | { 34 | return(label); 35 | } 36 | } 37 | return(NULL); 38 | } 39 | 40 | int Labels::get_selected() 41 | { 42 | for(int i = 0; i < Total(); i++) 43 | { 44 | Label *label = At(i); 45 | if(label.Selected()) 46 | { 47 | return(i); 48 | } 49 | } 50 | return(-1); 51 | } 52 | 53 | void Labels::click(string name) 54 | { 55 | for(int i = 0; i < Total(); i++) 56 | { 57 | Label *label = At(i); 58 | // find the label in the list of labels on the labels panel 59 | if(label.Name() == name) 60 | { 61 | label.Selected( ! label.Selected()); 62 | // if the label is selected 63 | if(label.Selected()) 64 | { 65 | current_label = i; 66 | click_label = true; 67 | } 68 | } 69 | else if(label.Selected()) 70 | { 71 | label.Selected(false); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/panel.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| panel.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include "label.mqh" 12 | #include "labels.mqh" 13 | 14 | class Panel 15 | { 16 | public: 17 | int current_level; 18 | int current_label; 19 | Labels labels; 20 | void create(); 21 | void remove(); 22 | void Panel(); 23 | void ~Panel(); 24 | void hide(); 25 | }; 26 | 27 | void Panel::Panel() 28 | { 29 | current_level = 0; 30 | current_label = 0; 31 | labels.FreeMode(true); 32 | create(); 33 | } 34 | 35 | void Panel::create() 36 | { 37 | Label *label; 38 | string group = "0"; 39 | Descr *descr = descrs.At(current_level); 40 | for(int i = 0; i < LABELS; i++) 41 | { 42 | label = new Label; 43 | label.create((string) current_level + SEPARATOR + descr.labels[i] + SEPARATOR + group + SEPARATOR + NAME_LABEL, x_distance + interval * i, y_distance, true, ANCHOR_CENTER, OBJ_ALL_PERIODS); 44 | labels.Add(label); 45 | } 46 | label = new Label; 47 | label.create((string) current_level + SEPARATOR + (string) descr.num_level + "-" + descr.level + SEPARATOR + group + SEPARATOR + NAME_LABEL, x_distance + interval * LABELS, y_distance, false, ANCHOR_LEFT, OBJ_ALL_PERIODS); 48 | labels.Add(label); 49 | } 50 | 51 | void Panel::remove() 52 | { 53 | labels.Clear(); 54 | } 55 | 56 | void Panel::~Panel() 57 | { 58 | labels.Clear(); 59 | } 60 | 61 | void Panel::hide() 62 | { 63 | for(int i = 0; i < labels.Total(); i++) 64 | { 65 | Label *label = labels.At(i); 66 | if(label.Timeframes() == OBJ_ALL_PERIODS) 67 | { 68 | label.Timeframes(OBJ_NO_PERIODS); 69 | } 70 | else if(label.Timeframes() == OBJ_NO_PERIODS) 71 | { 72 | label.Timeframes(OBJ_ALL_PERIODS); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/price_label.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| price_label.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | class Price_label : public CChartObjectArrowLeftPrice 14 | { 15 | public: 16 | void create(string wave_label_name, datetime time, double price, bool pos, int tf); 17 | void update(string wave_label_name, datetime time, double price, bool pos, int tf); 18 | }; 19 | 20 | void Price_label::create(string wave_label_name, datetime time, double price, bool pos, int tf) 21 | { 22 | Create(0, replace(wave_label_name, UNIQUE_NAME, NAME_PRICE_LABEL), 0, time, price); 23 | Timeframes(tf); 24 | Color(pos == false ? clrRed : clrBlue); 25 | } 26 | 27 | void Price_label::update(string wave_label_name, datetime time, double price, bool pos, int tf) 28 | { 29 | Name(replace(wave_label_name, UNIQUE_NAME, NAME_PRICE_LABEL)); 30 | Time(0, time); 31 | Price(0, price); 32 | Color(pos == false ? clrRed : clrBlue); 33 | Style(STYLE_SOLID); 34 | Timeframes(tf); 35 | } 36 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/ewm/vertical.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| vertical.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | class Vertical : public CChartObjectVLine 14 | { 15 | public: 16 | void create(string wave_label_name, datetime time, bool pos, int tf); 17 | void update(string wave_label_name, datetime time, bool pos, int tf); 18 | }; 19 | 20 | void Vertical::create(string wave_label_name, datetime time, bool pos, int tf) 21 | { 22 | Create(0, replace(wave_label_name, UNIQUE_NAME, NAME_VERTICAL), 0, time); 23 | Color(pos == false ? clrRed : clrBlue); 24 | Style(STYLE_DOT); 25 | Timeframes(tf); 26 | } 27 | 28 | void Vertical::update(string wave_label_name, datetime time, bool pos, int tf) 29 | { 30 | Name(replace(wave_label_name, UNIQUE_NAME, NAME_VERTICAL)); 31 | Time(0, time); 32 | Color(pos == false ? clrRed : clrBlue); 33 | Style(STYLE_DOT); 34 | Timeframes(tf); 35 | } 36 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/functions.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| functions.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | 12 | int get_current_tf() 13 | { 14 | int i = 0; 15 | while(i < ArrayRange(periods, 0)) 16 | { 17 | if(_Period == periods[i]) 18 | { 19 | break; 20 | } 21 | i++; 22 | } 23 | return(tfs[i]); 24 | } 25 | 26 | datetime bar_to_time(int shift) 27 | { 28 | int bars = Bars(_Symbol, _Period); 29 | datetime times[]; 30 | while(CopyTime(_Symbol, _Period, 0, bars, times) != bars) 31 | { 32 | Sleep(DELAY); 33 | } 34 | datetime time; 35 | if(shift >= bars) 36 | { 37 | time = times[bars - 1] + (shift - bars + 1) * PeriodSeconds(_Period); 38 | } 39 | else 40 | { 41 | time = times[shift]; 42 | } 43 | return(time); 44 | } 45 | 46 | void get_coordinates(int x, int y, double &price, datetime &time) 47 | { 48 | CChart chart; 49 | chart.Attach(0); 50 | int chart_visible_bars = (int)ChartGetInteger(0, CHART_VISIBLE_BARS); 51 | if(y - SHIFT_Y < 0) 52 | { 53 | y = 0; 54 | } 55 | else if(y - SHIFT_Y >= chart.HeightInPixels(0)) 56 | { 57 | y = chart.HeightInPixels(0) - 1; 58 | } 59 | else 60 | { 61 | y -= SHIFT_Y; 62 | } 63 | if(x - SHIFT_X < 0) 64 | { 65 | x = 0; 66 | } 67 | else if(x - SHIFT_X >= chart.WidthInPixels()) 68 | { 69 | x = chart.WidthInPixels() - 1; 70 | } 71 | else 72 | { 73 | x -= SHIFT_X; 74 | } 75 | price = chart.PriceMax(0) - ((chart.PriceMax(0) - chart.PriceMin(0)) / chart.HeightInPixels(0)) * y; 76 | int pos = Bars(_Symbol, _Period) - 1 - chart.FirstVisibleBar() + (int)MathRound(x * chart.WidthInBars() / (double)chart.WidthInPixels()); 77 | time = bar_to_time(pos); 78 | chart.Detach(); 79 | } 80 | 81 | int get_level(string name) 82 | { 83 | return((int)get(name, LEVEL)); 84 | } 85 | 86 | string get_text(string name) 87 | { 88 | return(get(name, TEXT)); 89 | } 90 | 91 | string get_group(string name) 92 | { 93 | return(get(name, GROUP)); 94 | } 95 | 96 | string get_unique_name(string name) 97 | { 98 | return(get(name, UNIQUE_NAME)); 99 | } 100 | 101 | string get(string name, int type) 102 | { 103 | string results[]; 104 | StringSplit(name, StringGetCharacter(SEPARATOR, 0), results); 105 | return(results[type]); 106 | } 107 | 108 | string replace(string name, int type, string replacement) 109 | { 110 | string results[]; 111 | StringSplit(name, StringGetCharacter(SEPARATOR, 0), results); 112 | results[type] = replacement; 113 | name = results[0]; 114 | for(int i = 1; i < ArrayRange(results, 0); i++) 115 | { 116 | name += SEPARATOR + results[i]; 117 | } 118 | return(name); 119 | } 120 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/p/pitchfork.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| c_pitchfork.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include "schiff.mqh" 10 | #include "reaction.mqh" 11 | #include 12 | #include 13 | #include "warning.mqh" 14 | #include 15 | 16 | class Pitchfork : public CChartObjectPitchfork 17 | { 18 | public: 19 | Wave_label *wave_label[3]; 20 | Schiff schiff; 21 | Reaction reaction; 22 | Warning warning_up; 23 | Warning warning_down; 24 | void attach(string name); 25 | void create(); 26 | void update(); 27 | void set_coordinates(); 28 | void set_levels(double &levels[]); 29 | string get_name(string name); 30 | string get(int param); 31 | bool Time(int point, datetime time) 32 | { 33 | return(ObjectSetInteger(0, Name(), OBJPROP_TIME, point, time)); 34 | } 35 | bool Price(int point, double price) 36 | { 37 | return(ObjectSetDouble(0, Name(), OBJPROP_PRICE, point, price)); 38 | } 39 | void set_visible(); 40 | void set_hidden(); 41 | }; 42 | 43 | void Pitchfork::attach(string name) 44 | { 45 | Attach(0, name, 0, 3); 46 | } 47 | 48 | void Pitchfork::create() 49 | { 50 | Create(0, get_name(wave_label[0].Name()) + SEPARATOR + get_name(wave_label[1].Name()) + SEPARATOR + get_name(wave_label[2].Name()) + SEPARATOR + NAME_PITCHFORK, 0, 0, 0, 0, 0, 0, 0); 51 | schiff.create(wave_label); 52 | reaction.create(wave_label); 53 | warning_up.name = NAME_WARNING_UP; 54 | warning_down.name = NAME_WARNING_DOWN; 55 | update(); 56 | } 57 | 58 | void Pitchfork::set_coordinates() 59 | { 60 | Time(0, wave_label[0].get_time()); 61 | Price(0, wave_label[0].get_price()); 62 | Time(1, wave_label[1].get_time()); 63 | Price(1, wave_label[1].get_price()); 64 | Time(2, wave_label[2].get_time()); 65 | Price(2, wave_label[2].get_price()); 66 | } 67 | 68 | void Pitchfork::update() 69 | { 70 | Name(get_name(wave_label[0].Name()) + SEPARATOR + get_name(wave_label[1].Name()) + SEPARATOR + get_name(wave_label[2].Name()) + SEPARATOR + NAME_PITCHFORK + ((get(PITCHFORK_VISIBLE) == "H") ? SEPARATOR + "H" : "")); 71 | string name = Name(); 72 | set_coordinates(); 73 | Selectable(false); 74 | RayLeft(false); 75 | RayRight(true); 76 | set_levels(pitchfork_levels); 77 | if(get(PITCHFORK_VISIBLE) == "") 78 | { 79 | Timeframes(wave_label[2].Timeframes()); 80 | } 81 | Z_Order(0); 82 | Descr *descr = descrs.At((int) get(PITCHFORK_LEVEL3)); 83 | Color(descr.clr); 84 | schiff.update(wave_label, Timeframes()); 85 | reaction.update(wave_label, Timeframes()); 86 | if(warning_up.Name() != NULL) 87 | { 88 | warning_up.update(wave_label, Timeframes()); 89 | } 90 | if(warning_down.Name() != NULL) 91 | { 92 | warning_down.update(wave_label, Timeframes()); 93 | } 94 | } 95 | 96 | void Pitchfork::set_levels(double &levels[]) 97 | { 98 | LevelsCount(ArrayRange(levels, 0)); 99 | for(int i = 0; i < ArrayRange(levels, 0); i++) 100 | { 101 | LevelValue(i, levels[i]); 102 | LevelDescription(i, i > 0 ? DoubleToString(levels[i] * 100, 1) : ""); 103 | Descr *descr = descrs.At((int) get(PITCHFORK_LEVEL3)); 104 | LevelColor(i, descr.clr); 105 | LevelStyle(i, STYLE_DOT); 106 | LevelWidth(i, 1); 107 | } 108 | } 109 | string Pitchfork::get_name(string name) 110 | { 111 | string results[]; 112 | StringSplit(name, '_', results); 113 | name = results[0]; 114 | for(int i = 1; i < 3; i++) 115 | { 116 | name += SEPARATOR + results[i]; 117 | } 118 | return(name); 119 | } 120 | string Pitchfork::get(int param) 121 | { 122 | string results[]; 123 | StringSplit(Name(), '_', results); 124 | if(param > ArrayRange(results, 0) - 1) 125 | { 126 | return(""); 127 | } 128 | return(results[param]); 129 | } 130 | 131 | void Pitchfork::set_visible() 132 | { 133 | string results[]; 134 | StringSplit(Name(), '_', results); 135 | string name = results[0]; 136 | for(int i = 1; i < 10; i++) 137 | { 138 | name += SEPARATOR + results[i]; 139 | } 140 | Name(name); 141 | } 142 | void Pitchfork::set_hidden() 143 | { 144 | Name(Name() + SEPARATOR + "H"); 145 | } -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/p/pitchforks.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| c_l_pitchforks.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | #include "pitchfork.mqh" 13 | #include 14 | 15 | class Pitchforks : public CArrayObj 16 | { 17 | public: 18 | void update(); 19 | void remove(Wave_label *wave); 20 | Pitchfork *get(Wave_label *wave); 21 | }; 22 | 23 | void Pitchforks::update() 24 | { 25 | datetime times[]; 26 | while(CopyTime(_Symbol, PERIOD_M1, 0, 1, times) != 1) 27 | { 28 | Sleep(DELAY); 29 | } 30 | for(int i = 0; i < Total(); i++) 31 | { 32 | Pitchfork *pitchfork = At(i); 33 | bool exchange = true; 34 | while(exchange) 35 | { 36 | exchange = false; 37 | for(int j = 0; j < 2; j++) 38 | { 39 | if(pitchfork.wave_label[j].Time(0) > pitchfork.wave_label[j + 1].Time(0)) 40 | { 41 | Wave_label *wave = pitchfork.wave_label[j + 1]; 42 | pitchfork.wave_label[j + 1] = pitchfork.wave_label[j]; 43 | pitchfork.wave_label[j] = wave; 44 | exchange = true; 45 | } 46 | } 47 | } 48 | if(pitchfork.wave_label[2].Time(0) > times[0]) 49 | { 50 | Delete(i); 51 | i--; 52 | } 53 | else 54 | { 55 | pitchfork.update(); 56 | } 57 | } 58 | } 59 | 60 | void Pitchforks::remove(Wave_label *wave) 61 | { 62 | for(int i = 0; i < Total(); i++) 63 | { 64 | Pitchfork *pitchfork = At(i); 65 | for(int j = 0; j < 3; j++) 66 | { 67 | if(pitchfork.wave_label[j] == wave) 68 | { 69 | Delete(i); 70 | i--; 71 | break; 72 | } 73 | } 74 | } 75 | } 76 | 77 | Pitchfork* Pitchforks::get(Wave_label *wave) 78 | { 79 | for(int i = 0; i < Total(); i++) 80 | { 81 | Pitchfork *pitchfork = At(i); 82 | if(pitchfork.wave_label[2] == wave) 83 | { 84 | return(pitchfork); 85 | } 86 | } 87 | return(NULL); 88 | } 89 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/p/reaction.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| c_reaction_lines.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class Reaction : public CChartObjectFiboChannel 15 | { 16 | public: 17 | bool inverse; 18 | double h; 19 | double dx; 20 | void attach(string name); 21 | bool Time(int point, datetime time) 22 | { 23 | return(ObjectSetInteger(0, Name(), OBJPROP_TIME, point, time)); 24 | } 25 | bool Price(int point, double price) 26 | { 27 | return(ObjectSetDouble(0, Name(), OBJPROP_PRICE, point, price)); 28 | } 29 | void create(Wave_label *&waves[]); 30 | void update(Wave_label *&waves[], int tf); 31 | void set_coordinates(Wave_label *&waves[]); 32 | void set_levels(); 33 | string get(int param); 34 | int get_pos(int point); 35 | string get_name(string name); 36 | void copy(long id); 37 | double get_tn_line1(Coord &coord); 38 | double get_tn_line4(Coord &coord); 39 | double get_coord_on_line1(int pos, Coord &coord); 40 | double get_coord_on_line2(int pos, Coord &coord); 41 | double get_coord_on_line3(int pos, Coord &coord); 42 | double get_coord_on_line4(int pos, Coord &coord); 43 | void get_coord4(Coord &coord); 44 | void get_h(Coord &coord); 45 | }; 46 | 47 | void Reaction::attach(string name) 48 | { 49 | Attach(0, name, 0, 3); 50 | } 51 | 52 | string Reaction::get(int param) 53 | { 54 | string results[]; 55 | StringSplit(Name(), '_', results); 56 | return(results[param]); 57 | } 58 | 59 | void Reaction::create(Wave_label *&waves[]) 60 | { 61 | Create(0, get_name(waves[0].Name()) + SEPARATOR + get_name(waves[1].Name()) + SEPARATOR + get_name(waves[2].Name()) + SEPARATOR + NAME_REACTION, 0, 0, 0, 0, 0, 0, 0); 62 | update(waves, waves[2].Timeframes()); 63 | } 64 | 65 | double Reaction::get_tn_line1(Coord &coord) 66 | { 67 | return((coord.price4 - coord.price1) / (coord.pos4 - coord.pos1)); 68 | } 69 | 70 | double Reaction::get_tn_line4(Coord &coord) 71 | { 72 | return((coord.price3 - coord.price2) / (coord.pos3 - coord.pos2)); 73 | } 74 | 75 | double Reaction::get_coord_on_line1(int pos, Coord &coord) 76 | { 77 | double tn = get_tn_line1(coord); 78 | double price = coord.price1 + tn * (pos - coord.pos1); 79 | return(price); 80 | } 81 | 82 | double Reaction::get_coord_on_line2(int pos, Coord &coord) 83 | { 84 | double tn = get_tn_line1(coord); 85 | double price = coord.price2 + tn * (pos - coord.pos2); 86 | return(price); 87 | } 88 | 89 | double Reaction::get_coord_on_line3(int pos, Coord &coord) 90 | { 91 | double tn = get_tn_line1(coord); 92 | double price = coord.price3 + tn * (pos - coord.pos3); 93 | return(price); 94 | } 95 | 96 | double Reaction::get_coord_on_line4(int pos, Coord &coord) 97 | { 98 | double tn = get_tn_line4(coord); 99 | double price = coord.price3 + tn * (coord.pos3 - pos); 100 | return(price); 101 | } 102 | 103 | void Reaction::get_coord4(Coord &coord) 104 | { 105 | coord.pos4 = (coord.pos2 + coord.pos3) / 2.0; 106 | coord.price4 = (coord.price2 + coord.price3) / 2.0; 107 | } 108 | 109 | void Reaction::get_h(Coord &coord) 110 | { 111 | if(coord.pos3 == coord.pos2 || coord.pos1 == coord.pos4) 112 | { 113 | h = 0; 114 | } 115 | else 116 | { 117 | MqlRates temp_rates[]; 118 | int bars = Bars(_Symbol, _Period); 119 | while(CopyRates(_Symbol, _Period, 0, bars, temp_rates) != bars) 120 | { 121 | Sleep(DELAY); 122 | } 123 | double tn_line4 = get_tn_line4(coord); 124 | double tn_line1 = -get_tn_line1(coord); 125 | double dt; 126 | h = 0; 127 | if(coord.price2 < coord.price3) 128 | { 129 | for(int i = (int) coord.pos2; i < (int) coord.pos3; i++) 130 | { 131 | double delta = (coord.price2 + tn_line4 * (i - coord.pos2)) - temp_rates[i].low; 132 | if(delta > h) 133 | { 134 | h = delta; 135 | dt = delta / (tn_line4 + tn_line1); 136 | } 137 | } 138 | } 139 | else 140 | { 141 | for(int i = (int) coord.pos2; i < (int) coord.pos3; i++) 142 | { 143 | double delta = temp_rates[i].high - (coord.price2 + tn_line4 * (i - coord.pos2)); 144 | if(delta > h) 145 | { 146 | h = delta; 147 | dt = delta / (tn_line4 + tn_line1); 148 | } 149 | } 150 | } 151 | h = MathAbs(dt) / (coord.pos4 - coord.pos1); 152 | } 153 | } 154 | 155 | void Reaction::set_coordinates(Wave_label *&waves[]) 156 | { 157 | Time(0, waves[0].get_time()); 158 | Price(0, waves[0].get_price()); 159 | Time(1, waves[1].get_time()); 160 | Price(1, waves[1].get_price()); 161 | Time(2, waves[2].get_time()); 162 | Price(2, waves[2].get_price()); 163 | Coord coord; 164 | coord.pos1 = get_pos(0); 165 | coord.pos2 = get_pos(1); 166 | coord.pos3 = get_pos(2); 167 | coord.price1 = Price(0); 168 | coord.price2 = Price(1); 169 | coord.price3 = Price(2); 170 | get_coord4(coord); 171 | get_h(coord); 172 | double pos1, pos2, pos3; 173 | double price1, price2, price3; 174 | pos1 = coord.pos2 + (coord.pos1 - coord.pos4); 175 | pos2 = coord.pos3 + (coord.pos1 - coord.pos4); 176 | if(pos1 < 0 || pos2 < 0) 177 | { 178 | pos1 = coord.pos3; 179 | pos2 = coord.pos2; 180 | pos3 = coord.pos3 + (coord.pos1 - coord.pos4); 181 | price1 = coord.price3; 182 | price2 = coord.price2; 183 | price3 = coord.price3 - (coord.price4 - coord.price1); 184 | if(MathCeil(pos3) != MathFloor(pos3)) 185 | { 186 | pos3 = MathFloor(pos3); 187 | price3 = get_coord_on_line3((int) pos3, coord); 188 | dx = -0.5 / (pos3 - pos1); 189 | } 190 | inverse = true; 191 | } 192 | else 193 | { 194 | price1 = coord.price2 - (coord.price4 - coord.price1); 195 | price2 = coord.price3 - (coord.price4 - coord.price1); 196 | price3 = coord.price2; 197 | pos3 = coord.pos2; 198 | dx = 0; 199 | if(MathFloor(pos1) != MathCeil(pos1)) 200 | { 201 | pos1 = MathFloor(pos1); 202 | pos2 = MathFloor(pos2); 203 | price1 = get_coord_on_line2((int) pos1, coord); 204 | price2 = get_coord_on_line3((int) pos2, coord); 205 | dx = -0.5 / (pos3 - pos1); 206 | } 207 | inverse = false; 208 | } 209 | Time(0, bar_to_time((int) pos1)); 210 | Time(1, bar_to_time((int) pos2)); 211 | Time(2, bar_to_time((int) pos3)); 212 | Price(0, price1); 213 | Price(1, price2); 214 | Price(2, price3); 215 | } 216 | 217 | void Reaction::update(Wave_label *&waves[], int tf) 218 | { 219 | Name(get_name(waves[0].Name()) + SEPARATOR + get_name(waves[1].Name()) + SEPARATOR + get_name(waves[2].Name()) + SEPARATOR + NAME_REACTION); 220 | set_coordinates(waves); 221 | RayRight(false); 222 | RayLeft(false); 223 | Timeframes(tf); 224 | Z_Order(0); 225 | Color(clrNONE); 226 | set_levels(); 227 | } 228 | 229 | void Reaction::set_levels() 230 | { 231 | LevelsCount(reaction_levels.Total() + 1); 232 | int i = 0; 233 | while(i < reaction_levels.Total()) 234 | { 235 | if(inverse) 236 | { 237 | LevelValue(i, -1 - (reaction_levels.At(i) + dx * reaction_levels.At(i))); 238 | } 239 | else 240 | { 241 | LevelValue(i, reaction_levels.At(i) + dx * reaction_levels.At(i)); 242 | } 243 | LevelDescription(i, DoubleToString(reaction_levels.At(i) * 100, 1)); 244 | Descr *descr = descrs.At((int) get(PITCHFORK_LEVEL3)); 245 | LevelColor(i, descr.clr); 246 | LevelStyle(i, STYLE_DOT); 247 | LevelWidth(i, 1); 248 | i++; 249 | } 250 | if(inverse) 251 | { 252 | LevelValue(i, -1 - (h + dx * h)); 253 | } 254 | else 255 | { 256 | LevelValue(i, h + dx * h); 257 | } 258 | LevelDescription(i, ""); 259 | LevelColor(i, red_zone_color); 260 | LevelStyle(i, STYLE_SOLID); 261 | LevelWidth(i, 2); 262 | } 263 | 264 | int Reaction::get_pos(int point) 265 | { 266 | datetime times[]; 267 | while(CopyTime(_Symbol, _Period, 0, 1, times) != 1) 268 | { 269 | Sleep(DELAY); 270 | } 271 | int bars1 = Bars(_Symbol, _Period); 272 | int bars2 = Bars(_Symbol, _Period, Time(point), times[0]); 273 | return(bars1 - bars2); 274 | } 275 | 276 | string Reaction::get_name(string name) 277 | { 278 | string results[]; 279 | StringSplit(name, '_', results); 280 | name = results[0]; 281 | for(int i = 1; i < 3; i++) 282 | { 283 | name += SEPARATOR + results[i]; 284 | } 285 | return(name); 286 | } 287 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/p/schiff.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| schiff.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class Schiff : public CChartObjectPitchfork 15 | { 16 | public: 17 | bool schiff; 18 | void Schiff() 19 | { 20 | schiff = false; 21 | } 22 | void attach(string name); 23 | int get_level(); 24 | color get_color(); 25 | string get(int param); 26 | void create(Wave_label *&wave_label[]); 27 | void update(Wave_label *&wave_label[], int tf); 28 | void set_coordinates(Wave_label *&wave_labels[]); 29 | bool Time(int point, datetime time) 30 | { 31 | return(ObjectSetInteger(0, this.Name(), OBJPROP_TIME, point, time)); 32 | } 33 | bool Price(int point, double price) 34 | { 35 | return(ObjectSetDouble(0, this.Name(), OBJPROP_PRICE, point, price)); 36 | } 37 | int get_pos(int point); 38 | void set_levels(double &a_levels[]); 39 | string get_name(string name); 40 | void copy(long id); 41 | double get_tn(Coord &coord); 42 | double get_coord_on_line1(int pos, Coord &coord); 43 | double get_coord_on_line2(int pos, Coord &coord); 44 | double get_coord_on_line3(int pos, Coord &coord); 45 | double get_coord_on_line4(int pos, Coord &coord); 46 | void get_coord4(Coord &coord); 47 | }; 48 | 49 | void Schiff::attach(string name) 50 | { 51 | Attach(0, name, 0, 3); 52 | if(LevelsCount() == 2) 53 | { 54 | schiff = false; 55 | } 56 | else 57 | { 58 | schiff = true; 59 | } 60 | } 61 | 62 | string Schiff::get(int param) 63 | { 64 | string results[]; 65 | StringSplit(Name(), '_', results); 66 | return(results[param]); 67 | } 68 | 69 | void Schiff::create(Wave_label *&wave_label[]) 70 | { 71 | Create(0, get_name(wave_label[0].Name()) + SEPARATOR + get_name(wave_label[1].Name()) + SEPARATOR + get_name(wave_label[2].Name()) + SEPARATOR + NAME_SCHIFF, 0, 0, 0, 0, 0, 0, 0); 72 | update(wave_label, wave_label[2].Timeframes()); 73 | } 74 | 75 | double Schiff::get_tn(Coord &coord) 76 | { 77 | return((coord.price4 - coord.price1) / (coord.pos4 - coord.pos1)); 78 | } 79 | 80 | double Schiff::get_coord_on_line1(int pos, Coord &coord) 81 | { 82 | double tn = get_tn(coord); 83 | double price = coord.price1 + tn * (pos - coord.pos1); 84 | return(price); 85 | } 86 | 87 | double Schiff::get_coord_on_line2(int pos, Coord &coord) 88 | { 89 | double tn = get_tn(coord); 90 | double price = coord.price2 + tn * (pos - coord.pos2); 91 | return(price); 92 | } 93 | 94 | double Schiff::get_coord_on_line3(int pos, Coord &coord) 95 | { 96 | double tn = get_tn(coord); 97 | double price = coord.price3 + tn * (pos - coord.pos3); 98 | return(price); 99 | } 100 | 101 | double Schiff::get_coord_on_line4(int pos, Coord &coord) 102 | { 103 | double tn = (coord.price2 - coord.price3) / (coord.pos3 - coord.pos2); 104 | double price = coord.price3 + tn * (coord.pos3 - pos); 105 | return(price); 106 | } 107 | 108 | void Schiff::get_coord4(Coord &coord) 109 | { 110 | coord.pos4 = (coord.pos2 + coord.pos3) / 2; 111 | coord.price4 = (coord.price2 + coord.price3) / 2; 112 | } 113 | 114 | void Schiff::set_coordinates(Wave_label *&wave_label[]) 115 | { 116 | Time(0, wave_label[0].get_time()); 117 | Price(0, wave_label[0].get_price()); 118 | Time(1, wave_label[1].get_time()); 119 | Price(1, wave_label[1].get_price()); 120 | Time(2, wave_label[2].get_time()); 121 | Price(2, wave_label[2].get_price()); 122 | Coord coord; 123 | coord.pos1 = (get_pos(0) + get_pos(1)) / 2.0; 124 | coord.pos2 = get_pos(1); 125 | coord.pos3 = get_pos(2); 126 | coord.price1 = (Price(0) + Price(1)) / 2; 127 | coord.price2 = Price(1); 128 | coord.price3 = Price(2); 129 | get_coord4(coord); 130 | if(MathFloor(coord.pos1) != MathCeil(coord.pos1)) 131 | { 132 | coord.pos1 = MathFloor(coord.pos1); 133 | coord.price1 = get_coord_on_line1((int) coord.pos1, coord); 134 | } 135 | Price(0, coord.price1); 136 | Price(1, coord.price2); 137 | Price(2, coord.price3); 138 | Time(0, bar_to_time((int) coord.pos1)); 139 | Time(1, bar_to_time((int) coord.pos2)); 140 | Time(2, bar_to_time((int) coord.pos3)); 141 | } 142 | 143 | void Schiff::update(Wave_label *&wave_label[], int tf) 144 | { 145 | Name(get_name(wave_label[0].Name()) + SEPARATOR + get_name(wave_label[1].Name()) + SEPARATOR + get_name(wave_label[2].Name()) + SEPARATOR + NAME_SCHIFF); 146 | set_coordinates(wave_label); 147 | Timeframes(tf); 148 | Color(clrNONE); 149 | RayLeft(false); 150 | RayRight(true); 151 | Width(1); 152 | Style(STYLE_DASH); 153 | if( ! schiff) 154 | { 155 | set_levels(schiff_levels1); 156 | } 157 | else 158 | { 159 | set_levels(schiff_levels2); 160 | } 161 | Z_Order(0); 162 | } 163 | 164 | void Schiff::set_levels(double &levels[]) 165 | { 166 | LevelsCount(ArrayRange(levels, 0)); 167 | for(int i = 0; i < ArrayRange(levels, 0); i++) 168 | { 169 | LevelValue(i, levels[i]); 170 | LevelDescription(i, ""); 171 | Descr *descr = descrs.At((int) get(PITCHFORK_LEVEL3)); 172 | LevelColor(i, descr.clr); 173 | LevelStyle(i, STYLE_DASH); 174 | LevelWidth(i, 1); 175 | } 176 | } 177 | 178 | string Schiff::get_name(string name) 179 | { 180 | string results[]; 181 | StringSplit(name, '_', results); 182 | name = results[0]; 183 | for(int i = 1; i < 3; i++) 184 | { 185 | name += SEPARATOR + results[i]; 186 | } 187 | return(name); 188 | } 189 | 190 | int Schiff::get_pos(int point) 191 | { 192 | datetime times[], temp_times[]; 193 | while(CopyTime(_Symbol, _Period, 0, 1, times) != 1) 194 | { 195 | Sleep(DELAY); 196 | } 197 | int bars1 = Bars(_Symbol, _Period); 198 | int bars2 = Bars(_Symbol, _Period, Time(point), times[0]); 199 | return(bars1 - bars2); 200 | } 201 | -------------------------------------------------------------------------------- /Salvador/ElliottWaveMaker 3.0/Include/EWM/p/warning.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| warning.mqh | 3 | //| Copyright 2012, Roman Martynyuk | 4 | //| http://www.dml-ewa.ru/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012, Roman Martynyuk" 7 | #property link "http://www.dml-ewa.ru/" 8 | 9 | #include 10 | #include 11 | 12 | class Warning : public CChartObjectFiboChannel 13 | { 14 | public: 15 | string name; 16 | bool is_warning; 17 | bool inverse; 18 | double h; 19 | double dx; 20 | void attach(string name); 21 | void Warning() 22 | { 23 | is_warning = false; 24 | } 25 | bool Time(int point, datetime time) 26 | { 27 | return(ObjectSetInteger(0, Name(), OBJPROP_TIME, point, time)); 28 | } 29 | bool Price(int point, double price) 30 | { 31 | return(ObjectSetDouble(0, Name(), OBJPROP_PRICE, point, price)); 32 | } 33 | void create(Wave_label *&waves[]); 34 | void update(Wave_label *&waves[], int tf); 35 | void set_coordinates(Wave_label *&waves[]); 36 | void set_levels(); 37 | string get(int param); 38 | int get_pos(int point); 39 | string get_name(string name); 40 | void copy(long id); 41 | double get_tn_line1(Coord &coord); 42 | double get_tn_line4(Coord &coord); 43 | double get_coord_on_line1(int pos, Coord &coord); 44 | double get_coord_on_line2(int pos, Coord &coord); 45 | double get_coord_on_line3(int pos, Coord &coord); 46 | double get_coord_on_line4(int pos, Coord &coord); 47 | void get_coord4(Coord &coord); 48 | void get_h(Coord &coord); 49 | }; 50 | 51 | void Warning::attach(string name) 52 | { 53 | Attach(0, name, 0, 3); 54 | } 55 | 56 | string Warning::get(int param) 57 | { 58 | string results[]; 59 | StringSplit(Name(), '_', results); 60 | return(results[param]); 61 | } 62 | 63 | void Warning::create(Wave_label *&waves[]) 64 | { 65 | Create(0, get_name(waves[0].Name()) + SEPARATOR + get_name(waves[1].Name()) + SEPARATOR + get_name(waves[2].Name()) + SEPARATOR + name, 0, 0, 0, 0, 0, 0, 0); 66 | update(waves, waves[2].Timeframes()); 67 | } 68 | 69 | double Warning::get_tn_line1(Coord &coord) 70 | { 71 | return((coord.price4 - coord.price1) / (coord.pos4 - coord.pos1)); 72 | } 73 | 74 | double Warning::get_tn_line4(Coord &coord) 75 | { 76 | return((coord.price3 - coord.price2) / (coord.pos3 - coord.pos2)); 77 | } 78 | 79 | double Warning::get_coord_on_line1(int pos, Coord &coord) 80 | { 81 | double tn = get_tn_line1(coord); 82 | double price = coord.price1 + tn * (pos - coord.pos1); 83 | return(price); 84 | } 85 | 86 | double Warning::get_coord_on_line2(int pos, Coord &coord) 87 | { 88 | double tn = get_tn_line1(coord); 89 | double price = coord.price2 + tn * (pos - coord.pos2); 90 | return(price); 91 | } 92 | 93 | double Warning::get_coord_on_line3(int pos, Coord &coord) 94 | { 95 | double tn = get_tn_line1(coord); 96 | double price = coord.price3 + tn * (pos - coord.pos3); 97 | return(price); 98 | } 99 | 100 | double Warning::get_coord_on_line4(int pos, Coord &coord) 101 | { 102 | double tn = get_tn_line4(coord); 103 | double price = coord.price3 + tn * (coord.pos3 - pos); 104 | return(price); 105 | } 106 | 107 | void Warning::get_coord4(Coord &coord) 108 | { 109 | coord.pos4 = (coord.pos2 + coord.pos3) / 2.0; 110 | coord.price4 = (coord.price2 + coord.price3) / 2.0; 111 | } 112 | 113 | void Warning::set_coordinates(Wave_label *&waves[]) 114 | { 115 | Time(0, waves[0].get_time()); 116 | Price(0, waves[0].get_price()); 117 | Time(1, waves[1].get_time()); 118 | Price(1, waves[1].get_price()); 119 | Time(2, waves[2].get_time()); 120 | Price(2, waves[2].get_price()); 121 | Coord coord; 122 | coord.pos1 = get_pos(0); 123 | coord.pos2 = get_pos(1); 124 | coord.pos3 = get_pos(2); 125 | coord.price1 = Price(0); 126 | coord.price2 = Price(1); 127 | coord.price3 = Price(2); 128 | get_coord4(coord); 129 | double pos1 = coord.pos4; 130 | double pos2 = pos1 + (coord.pos4 - coord.pos1); 131 | double pos3; 132 | double price1 = coord.price4; 133 | double price2 = price1 + (coord.price4 - coord.price1); 134 | double price3; 135 | if(name == NAME_WARNING_UP) 136 | { 137 | if(coord.price3 >= coord.price2) 138 | { 139 | pos3 = coord.pos3; 140 | price3 = coord.price3; 141 | } 142 | else 143 | { 144 | pos3 = coord.pos2; 145 | price3 = coord.price2; 146 | } 147 | } 148 | else 149 | { 150 | if(coord.price3 >= coord.price2) 151 | { 152 | pos3 = coord.pos2; 153 | price3 = coord.price2; 154 | } 155 | else 156 | { 157 | pos3 = coord.pos3; 158 | price3 = coord.price3; 159 | } 160 | } 161 | if(MathFloor(pos1) != MathCeil(pos1)) 162 | { 163 | pos1 = MathCeil(pos1); 164 | pos2 = MathCeil(pos2); 165 | price1 = get_coord_on_line1((int) pos1, coord); 166 | price2 = get_coord_on_line1((int) pos2, coord); 167 | } 168 | Time(0, bar_to_time((int) pos1)); 169 | Time(1, bar_to_time((int) pos2)); 170 | Time(2, bar_to_time((int) pos3)); 171 | Price(0, price1); 172 | Price(1, price2); 173 | Price(2, price3); 174 | } 175 | 176 | void Warning::update(Wave_label *&waves[], int tf) 177 | { 178 | Name(get_name(waves[0].Name()) + SEPARATOR + get_name(waves[1].Name()) + SEPARATOR + get_name(waves[2].Name()) + SEPARATOR + name); 179 | set_coordinates(waves); 180 | RayRight(true); 181 | RayLeft(false); 182 | Timeframes(tf); 183 | Z_Order(0); 184 | Color(clrNONE); 185 | set_levels(); 186 | } 187 | 188 | void Warning::set_levels() 189 | { 190 | LevelsCount(warning_levels.Total()); 191 | int i = 0; 192 | while(i < warning_levels.Total()) 193 | { 194 | LevelValue(i, warning_levels.At(i)); 195 | LevelDescription(i, DoubleToString(warning_levels.At(i) * 100, 1)); 196 | Descr *descr = descrs.At((int) get(PITCHFORK_LEVEL3)); 197 | LevelColor(i, descr.clr); 198 | LevelStyle(i, STYLE_DOT); 199 | LevelWidth(i, 1); 200 | i++; 201 | } 202 | } 203 | 204 | int Warning::get_pos(int point) 205 | { 206 | datetime times[]; 207 | while(CopyTime(_Symbol, _Period, 0, 1, times) != 1) 208 | { 209 | Sleep(DELAY); 210 | } 211 | int bars1 = Bars(_Symbol, _Period); 212 | int bars2 = Bars(_Symbol, _Period, Time(point), times[0]); 213 | return(bars1 - bars2); 214 | } 215 | 216 | string Warning::get_name(string name) 217 | { 218 | string results[]; 219 | StringSplit(name, '_', results); 220 | name = results[0]; 221 | for(int i = 1; i < 3; i++) 222 | { 223 | name += SEPARATOR + results[i]; 224 | } 225 | return(name); 226 | } 227 | -------------------------------------------------------------------------------- /Salvador/Simple EA/simple-ea.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| roman.mq5 | 3 | //| Copyright 2013,Viktor Moss | 4 | //| http://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2013,Viktor Moss" 7 | #property link "https://login.mql5.com/users/vicmos" 8 | #property version "1.00" 9 | 10 | #include 11 | //--- input parameters 12 | input double Lot=0.1; // Lots 13 | input int TP=46; // Take Profit 14 | input int SL=31; // Stop Loss 15 | 16 | CTrade trade; 17 | bool bs=true; //true-buy false-sell 18 | //+------------------------------------------------------------------+ 19 | //| Expert initialization function | 20 | //+------------------------------------------------------------------+ 21 | int OnInit() 22 | { 23 | //--- 24 | return(INIT_SUCCEEDED); 25 | } 26 | //+------------------------------------------------------------------+ 27 | //| Expert deinitialization function | 28 | //+------------------------------------------------------------------+ 29 | void OnDeinit(const int reason) 30 | { 31 | //--- 32 | } 33 | //+------------------------------------------------------------------+ 34 | //| Expert tick function | 35 | //+------------------------------------------------------------------+ 36 | void OnTick() 37 | { 38 | //--- 39 | double pr=0; 40 | if(!PositionSelect(_Symbol)) //no position 41 | { 42 | if(bs) trade.Buy(Lot); 43 | else trade.Sell(Lot); 44 | } 45 | else // there is a position 46 | { 47 | if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) 48 | { 49 | pr=(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN))/_Point; 50 | if(pr>=TP) 51 | { 52 | trade.PositionClose(_Symbol); 53 | bs=true;//buy 54 | } 55 | if(pr<=-SL) 56 | { 57 | trade.PositionClose(_Symbol); 58 | bs=false;//sell 59 | } 60 | } 61 | if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) 62 | { 63 | pr=(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK))/_Point; 64 | if(pr>=TP) 65 | { 66 | trade.PositionClose(_Symbol); 67 | bs=false;//sell 68 | } 69 | if(pr<=-SL) 70 | { 71 | trade.PositionClose(_Symbol); 72 | bs=true;//buy 73 | } 74 | } 75 | } 76 | } 77 | //+------------------------------------------------------------------+ 78 | -------------------------------------------------------------------------------- /Salvador/VolatilityPivot/exp_volatilitypivot.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Exp_VolatilityPivot.mq5 | 3 | //| Copyright � 2014, Nikolay Kositsin | 4 | //| Khabarovsk, farria@mail.redcom.ru | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright � 2014, Nikolay Kositsin" 7 | #property link "farria@mail.redcom.ru" 8 | #property version "1.00" 9 | //+----------------------------------------------+ 10 | //| Trading algorithms | 11 | //+----------------------------------------------+ 12 | #include 13 | //+----------------------------------------------+ 14 | //| Enumeration for lot calculation options | 15 | //+----------------------------------------------+ 16 | /*enum MarginMode - enumeration is declared in TradeAlgorithms.mqh 17 | { 18 | FREEMARGIN=0, //MM considering account free funds 19 | BALANCE, //MM considering account balance 20 | LOSSFREEMARGIN, //MM for losses share from an account free funds 21 | LOSSBALANCE, //MM for losses share from an account balance 22 | LOT //Lot should be unchanged 23 | }; */ 24 | //+----------------------------------------------+ 25 | //| Declaration of enumeration | 26 | //+----------------------------------------------+ 27 | enum Mode 28 | { 29 | FalshDirect=0, //against the signal 30 | TrueDirect //with the signal 31 | }; 32 | //+----------------------------------------------+ 33 | //| Declaration of enumeration | 34 | //+----------------------------------------------+ 35 | enum Mode_ 36 | { 37 | Mode_ATR=0, //ATR 38 | Mode_Price //price deviation 39 | }; 40 | //+----------------------------------------------+ 41 | //| Input parameters of the EA indicator | 42 | //+----------------------------------------------+ 43 | input double MM=0.1; // Share of a deposit in a deal 44 | input MarginMode MMMode=LOT; // Lot value detection method 45 | input int StopLoss_=1000; // Stop Loss in points 46 | input int TakeProfit_=2000; // Take Profit in points 47 | input int Deviation_=10; // Max. price deviation in points 48 | input bool BuyPosOpen=true; // Permission to buy 49 | input bool SellPosOpen=true; // Permission to sell 50 | input bool BuyPosClose=true; // Permission to exit long positions 51 | input bool SellPosClose=true; // Permission to exit short positions 52 | input Mode Direct=TrueDirect; // Trade direction 53 | //+----------------------------------------------+ 54 | //| VolatilityPivot indicator input parameters | 55 | //+----------------------------------------------+ 56 | input ENUM_TIMEFRAMES InpInd_Timeframe=PERIOD_H4; // Indicator timeframe 57 | input uint atr_range=100; 58 | input uint ima_range=10; 59 | input double atr_factor=3; 60 | input Mode_ IndMode=Mode_ATR; 61 | input uint DeltaPrice=200; 62 | input uint SignalBar=1; // Bar number for getting an entry signal 63 | //+----------------------------------------------+ 64 | int TimeShiftSec; 65 | //--- declaration of integer variables for the indicators handles 66 | int InpInd_Handle; 67 | //--- declaration of integer variables for the start of data calculation 68 | int min_rates_total; 69 | //+------------------------------------------------------------------+ 70 | //| Expert initialization function | 71 | //+------------------------------------------------------------------+ 72 | int OnInit() 73 | { 74 | //--- getting the handle of the VolatilityPivot indicator 75 | InpInd_Handle=iCustom(Symbol(),InpInd_Timeframe,"VolatilityPivot",atr_range,ima_range,atr_factor,IndMode,DeltaPrice,0); 76 | if(InpInd_Handle==INVALID_HANDLE) 77 | { 78 | Print(" Failed to get the handle of VolatilityPivot"); 79 | return(INIT_FAILED); 80 | } 81 | //--- initialization of a variable for storing the chart period in seconds 82 | TimeShiftSec=PeriodSeconds(InpInd_Timeframe); 83 | //--- initialization of variables of the start of data calculation 84 | if(IndMode==Mode_ATR) min_rates_total=int(atr_range+ima_range)+1; 85 | else min_rates_total=3; 86 | min_rates_total+=int(3+SignalBar); 87 | //--- initialization end 88 | return(INIT_SUCCEEDED); 89 | } 90 | //+------------------------------------------------------------------+ 91 | //| Expert deinitialization function | 92 | //+------------------------------------------------------------------+ 93 | void OnDeinit(const int reason) 94 | { 95 | //--- 96 | GlobalVariableDel_(Symbol()); 97 | //--- 98 | } 99 | //+------------------------------------------------------------------+ 100 | //| Expert tick function | 101 | //+------------------------------------------------------------------+ 102 | void OnTick() 103 | { 104 | //--- checking if the number of bars is enough for the calculation 105 | if(BarsCalculated(InpInd_Handle)=0; i--) { 45 | string name= ObjectName(i); 46 | 47 | if (StringSubstr(name,0,11)=="[SweetSpot]") 48 | ObjectDelete(name); 49 | } 50 | 51 | return(0); 52 | } 53 | 54 | //+------------------------------------------------------------------+ 55 | //| Custom indicator iteration function | 56 | //+------------------------------------------------------------------+ 57 | int start() 58 | { 59 | static datetime timelastupdate= 0; 60 | static datetime lasttimeframe= 0; 61 | 62 | 63 | // no need to update these buggers too often 64 | if (CurTime()-timelastupdate < 600 && Period()==lasttimeframe) 65 | return (0); 66 | 67 | deinit(); // delete all previous lines 68 | 69 | int i, ssp1, style, ssp, thickness; //sublevels= 50; 70 | double ds1; 71 | color linecolor; 72 | 73 | if (!ShowSubLevels) 74 | sublevels*= 2; 75 | 76 | ssp1= Bid / Point; 77 | ssp1= ssp1 - ssp1%sublevels; 78 | 79 | for (i= -NumLinesAboveBelow; iTrendValue) 59 | { 60 | AlertOnce("Price touched DOWN the trendline!",1); 61 | SendMailOnce("DOWN","Price touched DOWN the trendline!",1); 62 | } 63 | } 64 | } 65 | return(rates_total); 66 | } 67 | //+------------------------------------------------------------------+ 68 | double GetTrend(string trend_name) 69 | { 70 | for(int cnt=0; cnt-1) 75 | { 76 | return(ObjectGetValueByTime(0,objName,TimeCurrent())); 77 | } 78 | } 79 | return(0); 80 | } 81 | //+------------------------------------------------------------------+ 82 | bool AlertOnce(string msg, int ref) 83 | { 84 | static int LastAlert[3]; 85 | 86 | if( LastAlert[ref] == 0 || LastAlert[ref] < Bars(_Symbol,_Period)) 87 | { 88 | Alert(msg); 89 | LastAlert[ref] = Bars(_Symbol,_Period); 90 | return (true); 91 | } 92 | return(false); 93 | } 94 | //+------------------------------------------------------------------+ 95 | bool SendMailOnce(string subject, string body, int ref) 96 | { 97 | static int LastAlert[3]; 98 | 99 | if( LastAlert[ref] == 0 || LastAlert[ref] < Bars(_Symbol,_Period)) 100 | { 101 | SendMail(subject,body); 102 | LastAlert[ref] = Bars(_Symbol,_Period); 103 | return (true); 104 | } 105 | return(false); 106 | } 107 | //+------------------------------------------------------------------+ 108 | -------------------------------------------------------------------------------- /data_to_csv.mq4: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Data_to_CSV.mq4 | 3 | //| | 4 | //| | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Inovance" 7 | #property link "https://www.inovancetech.com/" 8 | #property description "Save OHLCV data to a csv file." 9 | #property version "1.00" 10 | #property strict 11 | #property indicator_chart_window 12 | 13 | //Filename 14 | input string FileName = "PriceData.csv"; 15 | 16 | 17 | 18 | //+------------------------------------------------------------------+ 19 | //| Initialization function | 20 | //+------------------------------------------------------------------+ 21 | int OnInit() 22 | { 23 | 24 | return(INIT_SUCCEEDED); 25 | } 26 | //+------------------------------------------------------------------+ 27 | //| Custom indicator iteration function | 28 | //+------------------------------------------------------------------+ 29 | int start() 30 | { 31 | //Define variables 32 | int limit,i; 33 | int counted_bars = IndicatorCounted(); 34 | 35 | //Make sure on most recent bar 36 | if(counted_bars>0) counted_bars--; 37 | 38 | //Set limit 39 | limit = Bars - counted_bars - 1; 40 | 41 | 42 | //Main loop 43 | for(i = limit - 1; i>=0; i--) 44 | { 45 | 46 | //Create and Open file 47 | int handle=FileOpen(FileName,FILE_CSV|FILE_READ|FILE_WRITE,","); 48 | 49 | //Name column headers 50 | FileWrite(handle,"Open Timestamp","Open","High","Low","Close","Volume"); 51 | 52 | //Go to end of file 53 | FileSeek(handle,0,SEEK_END); 54 | 55 | //Record data 56 | FileWrite(handle,Time[i],Open[i],High[i],Low[i],Close[i],Volume[i]); 57 | 58 | //Close file 59 | FileClose(handle); 60 | 61 | } 62 | 63 | return(0); 64 | } -------------------------------------------------------------------------------- /dobrin20i50i200.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lanastasov/mt-mql/0a5487edd3971a24a6cd811bb3fe61ed10aa6466/dobrin20i50i200.tpl -------------------------------------------------------------------------------- /ema-levels.mq5: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------ 2 | #property copyright "© mladen, 2018" 3 | #property link "mladenfx@gmail.com" 4 | #property version "1.00" 5 | //------------------------------------------------------------------ 6 | #property indicator_chart_window 7 | #property indicator_buffers 5 8 | #property indicator_plots 3 9 | #property indicator_label1 "up level" 10 | #property indicator_type1 DRAW_LINE 11 | #property indicator_color1 clrLimeGreen 12 | #property indicator_style1 STYLE_DOT 13 | #property indicator_label2 "down level" 14 | #property indicator_type2 DRAW_LINE 15 | #property indicator_color2 clrOrange 16 | #property indicator_style2 STYLE_DOT 17 | #property indicator_label3 "EMA" 18 | #property indicator_type3 DRAW_COLOR_LINE 19 | #property indicator_color3 clrSilver,clrLimeGreen,clrOrange 20 | #property indicator_width3 2 21 | 22 | input int inpEmaPeriod=9; // Ema period 23 | double val[],valc[],levelUp[],levelDn[]; 24 | //------------------------------------------------------------------ 25 | // 26 | //------------------------------------------------------------------ 27 | void OnInit() 28 | { 29 | SetIndexBuffer(0,levelUp,INDICATOR_DATA); 30 | SetIndexBuffer(1,levelDn,INDICATOR_DATA); 31 | SetIndexBuffer(2,val,INDICATOR_DATA); 32 | SetIndexBuffer(3,valc,INDICATOR_COLOR_INDEX); 33 | for(int i=0; i<2; i++) PlotIndexSetInteger(i,PLOT_SHOW_DATA,false); 34 | IndicatorSetString(INDICATOR_SHORTNAME,"Ema levels ("+(string)inpEmaPeriod+")"); 35 | } 36 | //------------------------------------------------------------------ 37 | // 38 | //------------------------------------------------------------------ 39 | int OnCalculate(const int rates_total, 40 | const int prev_calculated, 41 | const datetime &time[], 42 | const double &open[], 43 | const double &high[], 44 | const double &low[], 45 | const double &close[], 46 | const long &tick_volume[], 47 | const long &volume[], 48 | const int &spread[]) 49 | { 50 | if(Bars(_Symbol,_Period)0) ? (val[i]>levelDn[i-1]) ? levelUp[i-1]+alpha*(val[i]-levelUp[i-1]) : levelUp[i-1] : val[i]; 57 | levelDn[i] = (i>0) ? (val[i]levelUp[i]) ? 1 : (val[i]0) ? (val[i]==val[i-1]) ? valc[i-1]: 0 : 0; 59 | } 60 | return(i); 61 | } 62 | //+------------------------------------------------------------------+ 63 | //| Custom functions | 64 | //+------------------------------------------------------------------+ 65 | double workEma[][1]; 66 | //+------------------------------------------------------------------+ 67 | //| | 68 | //+------------------------------------------------------------------+ 69 | double iEma(double price,double period,int r,int _bars,int instanceNo=0) 70 | { 71 | if(ArrayRange(workEma,0)!=_bars) ArrayResize(workEma,_bars); 72 | 73 | workEma[r][instanceNo]=price; 74 | if(r>0 && period>1) 75 | workEma[r][instanceNo]=workEma[r-1][instanceNo]+(2.0/(1.0+period))*(price-workEma[r-1][instanceNo]); 76 | return(workEma[r][instanceNo]); 77 | } 78 | //+------------------------------------------------------------------+ 79 | 80 | 81 | -------------------------------------------------------------------------------- /i-Sessions.mq4: -------------------------------------------------------------------------------- 1 | 2 | //+------------------------------------------------------------------+ 3 | //| i-Sessions.mq4 | 4 | //| Ким Игорь В. aka KimIV | 5 | //| http://www.kimiv.ru | 6 | //| | 7 | //| 16.11.2005 Индикатор торговых сессий | 8 | //+------------------------------------------------------------------+ 9 | #property copyright "Ким Игорь В. aka KimIV" 10 | #property link "http://www.kimiv.ru" 11 | 12 | #property indicator_chart_window 13 | 14 | //------- Внешние параметры индикатора ------------------------------- 15 | extern int NumberOfDays = 50; // Количество дней 16 | extern string AsiaBegin = "01:00"; // Открытие азиатской сессии 17 | extern string AsiaEnd = "10:00"; // Закрытие азиатской сессии 18 | extern color AsiaColor = Goldenrod; // Цвет азиатской сессии 19 | extern string EurBegin = "07:00"; // Открытие европейской сессии 20 | extern string EurEnd = "16:00"; // Закрытие европейской сессии 21 | extern color EurColor = Tan; // Цвет европейской сессии 22 | extern string USABegin = "14:00"; // Открытие американской сессии 23 | extern string USAEnd = "23:00"; // Закрытие американской сессии 24 | extern color USAColor = PaleGreen; // Цвет американской сессии 25 | 26 | 27 | //+------------------------------------------------------------------+ 28 | //| Custom indicator initialization function | 29 | //+------------------------------------------------------------------+ 30 | void init() { 31 | DeleteObjects(); 32 | for (int i=0; i5) dt=decDateTradeDay(dt); 84 | } 85 | } 86 | 87 | //+------------------------------------------------------------------+ 88 | //| Прорисовка объектов на графике | 89 | //| Параметры: | 90 | //| dt - дата торгового дня | 91 | //| no - наименование объекта | 92 | //| tb - время начала сессии | 93 | //| te - время окончания сессии | 94 | //+------------------------------------------------------------------+ 95 | void DrawObjects(datetime dt, string no, string tb, string te) { 96 | datetime t1, t2; 97 | double p1, p2; 98 | int b1, b2; 99 | 100 | t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb); 101 | t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te); 102 | b1=iBarShift(NULL, 0, t1); 103 | b2=iBarShift(NULL, 0, t2); 104 | p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)]; 105 | p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)]; 106 | ObjectSet(no, OBJPROP_TIME1 , t1); 107 | ObjectSet(no, OBJPROP_PRICE1, p1); 108 | ObjectSet(no, OBJPROP_TIME2 , t2); 109 | ObjectSet(no, OBJPROP_PRICE2, p2); 110 | } 111 | 112 | //+------------------------------------------------------------------+ 113 | //| Уменьшение даты на один торговый день | 114 | //| Параметры: | 115 | //| dt - дата торгового дня | 116 | //+------------------------------------------------------------------+ 117 | datetime decDateTradeDay (datetime dt) { 118 | int ty=TimeYear(dt); 119 | int tm=TimeMonth(dt); 120 | int td=TimeDay(dt); 121 | int th=TimeHour(dt); 122 | int ti=TimeMinute(dt); 123 | 124 | td--; 125 | if (td==0) { 126 | tm--; 127 | if (tm==0) { 128 | ty--; 129 | tm=12; 130 | } 131 | if (tm==1 || tm==3 || tm==5 || tm==7 || tm==8 || tm==10 || tm==12) td=31; 132 | if (tm==2) if (MathMod(ty, 4)==0) td=29; else td=28; 133 | if (tm==4 || tm==6 || tm==9 || tm==11) td=30; 134 | } 135 | return(StrToTime(ty+"."+tm+"."+td+" "+th+":"+ti)); 136 | } 137 | //+------------------------------------------------------------------+ 138 | -------------------------------------------------------------------------------- /ma_colored.mq5: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Classic Moving Averages with colors 4 | * 5 | * Simple moving average 6 | * Exponential moving average 7 | * Smoothed moving average 8 | * Linear weighted moving average 9 | * Smoothed moving average 10 | * 11 | * The indicator displays a colored moving average. 12 | * 13 | * It has three parameters: 14 | * * Period calculation period 15 | * * Method calculation method 16 | * * Price applied prise used for calculation 17 | * 18 | * This version is faster and code is more flexible and reusable 19 | */ 20 | 21 | 22 | //+------------------------------------------------------------------ 23 | #property copyright "Copyright © 2020, mplavonil" 24 | #property description "Classic Moving Averages with colors" 25 | #property version "1.0" 26 | #property indicator_chart_window 27 | 28 | #property indicator_chart_window 29 | #property indicator_buffers 2 30 | #property indicator_plots 1 31 | 32 | #property indicator_type1 DRAW_COLOR_LINE 33 | #property indicator_color1 clrLimeGreen,clrRed 34 | #property indicator_style1 STYLE_SOLID 35 | #property indicator_width1 2 36 | 37 | enum enMATypes 38 | { 39 | _sma, // Simple 40 | _ema, // Exponential 41 | _smma, // Smoothed 42 | _lwma // Linear weighted 43 | }; 44 | 45 | input int MaPeriod = 9; // Period 46 | input enMATypes MaMethod = _sma; // Method 47 | input ENUM_APPLIED_PRICE Price = PRICE_CLOSE; // Price 48 | 49 | double MaBuffer[]; 50 | double ColorBuffer[]; 51 | 52 | //+------------------------------------------------------------------+ 53 | //| Custom indicator initialization function | 54 | //+------------------------------------------------------------------+ 55 | int OnInit() 56 | { 57 | //--- indicator buffers mapping 58 | SetIndexBuffer(0,MaBuffer,INDICATOR_DATA); 59 | SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX); 60 | IndicatorSetString(INDICATOR_SHORTNAME,shortName(MaMethod)); 61 | //--- 62 | return(INIT_SUCCEEDED); 63 | } 64 | //+------------------------------------------------------------------+ 65 | //| Custom indicator iteration function | 66 | //+------------------------------------------------------------------+ 67 | int OnCalculate( 68 | const int rates_total, 69 | const int prev_calculated, 70 | const datetime &time[], 71 | const double &open[], 72 | const double &high[], 73 | const double &low[], 74 | const double &close[], 75 | const long &TickVolume[], 76 | const long &Volume[], 77 | const int &Spread[]) 78 | { 79 | int i=(int)MathMax(prev_calculated-1,0);for (; i0) 85 | { 86 | ColorBuffer[i] = ColorBuffer[i-1]; 87 | if (MaBuffer[i]>MaBuffer[i-1]) {ColorBuffer[i]=0;} 88 | if (MaBuffer[i]=0; k++) 129 | avg += maArray[r-k]; 130 | 131 | return(avg/(double)k); 132 | } 133 | 134 | double iEMA(double price,double period,int bars, int r) 135 | { 136 | if (ArraySize(maArray)!=bars) ArrayResize(maArray,bars); 137 | maArray[r]=price; 138 | if(r>0 && period>1) 139 | maArray[r]=maArray[r-1]+(2.0/(1.0+period))*(price-maArray[r-1]); 140 | 141 | return(maArray[r]); 142 | } 143 | 144 | double iSMMA(double price,double period,int bars, int r) 145 | { 146 | if (ArraySize(maArray)!=bars) ArrayResize(maArray,bars); 147 | 148 | maArray[r]=price; 149 | if(r>1 && period>1) 150 | maArray[r]=maArray[r-1]+(price-maArray[r-1])/period; 151 | 152 | return(maArray[r]); 153 | } 154 | 155 | double iLWMA(double price,double period,int bars, int r) 156 | { 157 | if (ArraySize(maArray)!=bars) ArrayResize(maArray,bars); 158 | 159 | 160 | maArray[r] = price; if(period<1) return(price); 161 | double sumw = period; 162 | double sum = period*price; 163 | 164 | for(int k=1; k=0; k++) 165 | { 166 | double weight=period-k; 167 | sumw += weight; 168 | sum += weight*maArray[r-k]; 169 | } 170 | return(sum/sumw); 171 | } 172 | 173 | // 174 | double getPrice(ENUM_APPLIED_PRICE tprice,const double &open[],const double &close[],const double &high[],const double &low[],int i,int _bars,int instanceNo=0) 175 | { 176 | switch(tprice) 177 | { 178 | case PRICE_CLOSE: return(close[i]); 179 | case PRICE_OPEN: return(open[i]); 180 | case PRICE_HIGH: return(high[i]); 181 | case PRICE_LOW: return(low[i]); 182 | case PRICE_MEDIAN: return((high[i]+low[i])/2.0); 183 | case PRICE_TYPICAL: return((high[i]+low[i]+close[i])/3.0); 184 | case PRICE_WEIGHTED: return((high[i]+low[i]+close[i]+close[i])/4.0); 185 | } 186 | return(0); 187 | } 188 | //+--------------------------------------------------------- 189 | -------------------------------------------------------------------------------- /opentrade.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| Open Trade.mq5 | 3 | //| Copyright 2023 | 4 | //| https://www.mql5.com/en/users/neverwolf | 5 | //+------------------------------------------------------------------+ 6 | 7 | #property copyright "Neverwolf" 8 | #property link "https://www.mql5.com/en/users/neverwolf" 9 | #property version "1.00" 10 | #property script_show_inputs 11 | 12 | enum TradeType 13 | { 14 | OPEN_BUY = 0, // ORDER_TYPE_BUY 15 | OPEN_SELL = 1, // ORDER_TYPE_SELL 16 | }; 17 | 18 | input group "Open Trade"; 19 | input TradeType OrderType = OPEN_BUY; // Order Type 20 | input double Lots = 0.01; // Lots 21 | input int dev = 10; // Deviation 22 | input double TakeProfit = 0.0; // TakeProfit in Points 23 | input double StopLoss = 0.0; // StopLoss in Points 24 | input string commt = ""; // Trade Comment 25 | input int magic = 1212; // Trade Magic Number 26 | 27 | void OnStart() 28 | { 29 | OpenTrade(Symbol(), (ENUM_ORDER_TYPE)OrderType, Lots, dev, TakeProfit, StopLoss, commt, magic); 30 | } 31 | 32 | //+------------------------------------------------------------------+ 33 | //| Order Send | 34 | //+------------------------------------------------------------------+ 35 | void OpenTrade(string symbol, ENUM_ORDER_TYPE orderType, double volume, int deviation, double stopLossPoints, double takeProfitPoints, string comment, ulong magicNumber) 36 | { 37 | double getpoints = SymbolInfoDouble(symbol, SYMBOL_POINT); 38 | double getask = SymbolInfoDouble(symbol, SYMBOL_ASK); 39 | double getbid = SymbolInfoDouble(symbol, SYMBOL_BID); 40 | double minLevel = GetMinTradeLevel(symbol); 41 | double tp = 0.0, sl = 0.0, price = 0.0; 42 | 43 | // Determine if it's a Buy or Sell trade 44 | if (orderType == ORDER_TYPE_BUY) 45 | { 46 | price = getask; 47 | tp = (takeProfitPoints != 0.0) ? (getask + takeProfitPoints * getpoints) + (minLevel * getpoints) : 0.0; 48 | sl = (stopLossPoints != 0.0) ? (getask - stopLossPoints * getpoints) - (minLevel * getpoints) : 0.0; 49 | } 50 | if (orderType == ORDER_TYPE_SELL) 51 | { 52 | price = getbid; 53 | tp = (takeProfitPoints != 0.0) ? (getbid - takeProfitPoints * getpoints) - (minLevel * getpoints) : 0.0; 54 | sl = (stopLossPoints != 0.0) ? (getbid + stopLossPoints * getpoints) + (minLevel * getpoints) : 0.0; 55 | } 56 | //--- prepare a request 57 | MqlTradeRequest request = {}; 58 | ZeroMemory(request); 59 | request.action = TRADE_ACTION_DEAL; // Operation Type 60 | request.symbol = symbol; // Symbol 61 | request.volume = volume; // Volume 62 | request.type = orderType; // Type of Order 63 | request.deviation = deviation; // Deviation 64 | request.comment = comment; // Comment 65 | request.magic = magicNumber; // Magic Number 66 | request.type_filling = SetTypeFillingBySymbol(symbol); // Filling Type 67 | request.price = price; 68 | request.tp = tp; 69 | request.sl = sl; 70 | MqlTradeResult result = {}; 71 | ZeroMemory(result); 72 | // bool ok = OrderSend(request, result); 73 | bool ok = OrderSend(request, result); 74 | Print("Function > ", __FUNCTION__); 75 | } 76 | //--- 77 | //--- 78 | //--- 79 | //--- SetTypeFillingBySymbol 80 | ENUM_ORDER_TYPE_FILLING SetTypeFillingBySymbol(const string symbol) 81 | { 82 | // Get possible filling policy types by symbol 83 | uint filling = (uint)SymbolInfoInteger(symbol, SYMBOL_FILLING_MODE); 84 | 85 | if ((filling & SYMBOL_FILLING_FOK) == SYMBOL_FILLING_FOK) 86 | { 87 | return ORDER_FILLING_FOK; 88 | } 89 | else if ((filling & SYMBOL_FILLING_IOC) == SYMBOL_FILLING_IOC) 90 | { 91 | return ORDER_FILLING_IOC; 92 | } 93 | else 94 | { 95 | return ORDER_FILLING_RETURN; 96 | } 97 | } 98 | //--- 99 | //--- 100 | //--- 101 | //--- GetMinTradeLevel 102 | double GetMinTradeLevel(string symbol) 103 | { 104 | double minLevel = -1.0; 105 | double freezeLevel = -1.0; 106 | double stopsLevel = -1.0; 107 | 108 | freezeLevel = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_FREEZE_LEVEL); 109 | stopsLevel = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL); 110 | minLevel = MathMax(freezeLevel, stopsLevel); 111 | 112 | if (freezeLevel == -1 || stopsLevel == -1 || minLevel == -1) 113 | { 114 | Print("Freeze level or Stops level not available for the symbol (-1) "); 115 | return 0; 116 | } 117 | 118 | if (minLevel <= 100.0 && minLevel >= 0.0) 119 | minLevel += 1.0; 120 | else if (minLevel >= 100.0) 121 | minLevel = 100.0; 122 | 123 | return minLevel; 124 | } 125 | //--- 126 | //--- 127 | -------------------------------------------------------------------------------- /set-sl-tp.mq4: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //|Sets a stop loss and take profit to all the open orders | 3 | //| | 4 | //|Line 31 is the Take Profit default setting in Pips | 5 | //|Line 32 is the Stop Loss default setting in Pips | 6 | //|Line 38 is the Delay inbetween changes | 7 | //| | 8 | //| | 9 | //|Assigned Hotkey is any coloured button visit | 10 | //| | 11 | //|www.forexkeyboard.com to get the Hotkeys for coloured buttons | 12 | //+------------------------------------------------------------------+ 13 | 14 | 15 | 16 | #property icon "favicon-1.ico" 17 | #property copyright "Copyright Forexkeyboard.com © 2019" 18 | #property link "https://www.ForexKeyboard.com" 19 | #property version "1.10" 20 | #property strict 21 | #property description "This script sets a stop loss and take profit to all the open orders " 22 | #property description " " 23 | #property description "You can choose orders with a Magic Number or Matching Comments as an option" 24 | #property description " " 25 | #property description " " 26 | #property description "Assigned hotkey on the keyboard can be any of the coloured keys " 27 | #property description " " 28 | #property description "See www.ForexKeyborad.com/hotkeys for the keyboard layout " 29 | 30 | #property show_inputs 31 | 32 | //Configure the external variables 33 | extern int TakeProfit=40; //Take Profit in pips 34 | extern int StopLoss=20; //Stop Loss in pips 35 | extern bool OnlyMagicNumber=false; //Modify only orders matching the magic number 36 | extern int MagicNumber=0; //Matching magic number 37 | extern bool OnlyWithComment=false; //Modify only orders with the following comment 38 | extern string MatchingComment=""; //Matching comment 39 | extern double Slippage=2; //Slippage 40 | extern int Delay=0; //Delay to wait between modifying orders (in milliseconds) 41 | 42 | //Function to normalize the digits 43 | double CalculateNormalizedDigits() 44 | { 45 | if(Digits<=3){ 46 | return(0.01); 47 | } 48 | else if(Digits>=4){ 49 | return(0.0001); 50 | } 51 | else return(0); 52 | } 53 | 54 | //+------------------------------------------------------------------+ 55 | //| Script program start function | 56 | //+------------------------------------------------------------------+ 57 | void OnStart() 58 | { 59 | //--- 60 | //Counter for orders modified 61 | int TotalModified=0; 62 | 63 | //Normalization of the digits 64 | if(Digits==3 || Digits==5){ 65 | Slippage=Slippage*10; 66 | } 67 | double nDigits=CalculateNormalizedDigits(); 68 | 69 | //Scan the open orders backwards 70 | for(int i=OrdersTotal()-1; i>=0; i--){ 71 | 72 | //Select the order, if not selected print the error and continue with the next index 73 | if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ) { 74 | Print("ERROR - Unable to select the order - ",GetLastError()); 75 | continue; 76 | } 77 | 78 | //Check if the order can be modified matching the criteria, if criteria not matched skip to the next 79 | if(OrderSymbol()!=Symbol()) continue; 80 | if(OnlyMagicNumber && OrderMagicNumber()!=MagicNumber) continue; 81 | if(OnlyWithComment && StringCompare(OrderComment(),MatchingComment)!=0) continue; 82 | 83 | //Prepare the prices 84 | double TakeProfitPrice=0; 85 | double StopLossPrice=0; 86 | double OpenPrice=OrderOpenPrice(); 87 | RefreshRates(); 88 | if(OrderType()==OP_BUY){ 89 | TakeProfitPrice=NormalizeDouble(OpenPrice+TakeProfit*nDigits,Digits); 90 | StopLossPrice=NormalizeDouble(OpenPrice-StopLoss*nDigits,Digits); 91 | } 92 | if(OrderType()==OP_SELL){ 93 | TakeProfitPrice=NormalizeDouble(OpenPrice-TakeProfit*nDigits,Digits); 94 | StopLossPrice=NormalizeDouble(OpenPrice+StopLoss*nDigits,Digits); 95 | } 96 | 97 | //Try to modify the order 98 | if(OrderModify(OrderTicket(),OpenPrice,StopLossPrice,TakeProfitPrice,0,clrNONE)){ 99 | TotalModified++; 100 | } 101 | else{ 102 | Print("Order failed to update with error - ",GetLastError()); 103 | } 104 | 105 | //Wait a delay 106 | Sleep(Delay); 107 | 108 | } 109 | 110 | //Print the total of orders modified 111 | Print("Total orders modified = ",TotalModified); 112 | 113 | } 114 | //+----------------------------------------------------------------------------------------------------------+ 115 | -------------------------------------------------------------------------------- /shistoryexport: -------------------------------------------------------------------------------- 1 | https://www.mql5.com/en/code/1252 2 | -------------------------------------------------------------------------------- /shistoryexport-mql5/CheckHistory.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| CheckHistory.mqh | 3 | //| Copyright 2012-2014, komposter | 4 | //| http://www.komposter.me/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012-2014, komposter" 7 | #property link "http://www.komposter.me/" 8 | #property version "2.0" 9 | //--- 10 | #define MAX_WAITING_TIME 10000 // Максимальное время ожидания подкачки истории 11 | //--- 12 | uint StartTickCount=0; 13 | //+------------------------------------------------------------------+ 14 | //| Checks data by specified symbol's timeframe and | 15 | //| downloads it from server, if necessary. | 16 | //+------------------------------------------------------------------+ 17 | bool CheckLoadHistory(const string symbol,const ENUM_TIMEFRAMES period,const int size,bool print_info=true) 18 | { 19 | //--- don't ask for load of its own data if it is an indicator 20 | if(MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR && Period()==period && Symbol()==symbol) return(true); 21 | //--- 22 | if(size>TerminalInfoInteger(TERMINAL_MAXBARS)) 23 | { 24 | //--- Definitely won't have such amount of data 25 | printf(__FUNCTION__+": requested too much data (%d)",size); 26 | return(false); 27 | } 28 | //--- 29 | StartTickCount=GetTickCount(); 30 | if(CheckTerminalHistory(symbol,period,size) || CheckServerHistory(symbol,period,size)) 31 | { 32 | if(print_info) 33 | { 34 | double length=(GetTickCount()-StartTickCount)/1000.0; 35 | if(length>0.1) Print(symbol,", ",EnumToString(period),": history synchronized within ",DoubleToString(length,1)," sec"); 36 | } 37 | return(true); 38 | } 39 | //--- 40 | if(print_info) Print(symbol,", ",EnumToString(period),": ERROR synchronizing history!!!"); 41 | //--- failed 42 | return(false); 43 | } 44 | //+------------------------------------------------------------------+ 45 | //| Checks data in terminal. | 46 | //+------------------------------------------------------------------+ 47 | bool CheckTerminalHistory(const string symbol,const ENUM_TIMEFRAMES period,const int size) 48 | { 49 | //--- Enough data in timeseries? 50 | if(Bars(symbol,period)>=size) return(true); 51 | //--- second attempt 52 | datetime times[1]; 53 | long bars=0; 54 | //--- 55 | if(SeriesInfoInteger(symbol,PERIOD_M1,SERIES_BARS_COUNT,bars)) 56 | { 57 | //--- there is loaded data to build timeseries 58 | if(bars>size*PeriodSeconds(period)/60) 59 | { 60 | //--- force timeseries build 61 | CopyTime(symbol,period,size-1,1,times); 62 | //--- check date 63 | if(SeriesInfoInteger(symbol,period,SERIES_BARS_COUNT,bars)) 64 | { 65 | //--- Timeseries generated using data from terminal 66 | if(bars>=size) return(true); 67 | } 68 | } 69 | } 70 | //--- failed 71 | return(false); 72 | } 73 | //+------------------------------------------------------------------+ 74 | //| Downloads missing data from server. | 75 | //+------------------------------------------------------------------+ 76 | bool CheckServerHistory(const string symbol,const ENUM_TIMEFRAMES period,const int size) 77 | { 78 | //--- load symbol history info 79 | datetime first_server_date=0; 80 | while(!SeriesInfoInteger(symbol,PERIOD_M1,SERIES_SERVER_FIRSTDATE,first_server_date) && !IsStoppedExt()) Sleep(5); 81 | //--- Enough data on server? 82 | if(first_server_date>TimeCurrent()-size*PeriodSeconds(period)) return(false); 83 | //--- load data step by step 84 | int fail_cnt=0; 85 | datetime times[1]; 86 | while(!IsStoppedExt()) 87 | { 88 | //--- wait for timeseries build 89 | while(!SeriesInfoInteger(symbol,period,SERIES_SYNCHRONIZED) && !IsStoppedExt()) Sleep(5); 90 | //--- ask for built bars 91 | int bars=Bars(symbol,period); 92 | if(bars>size) return(true); 93 | //--- copying of next part forces data loading 94 | if(CopyTime(symbol,period,size-1,1,times)==1) 95 | { 96 | return(true); 97 | } 98 | else 99 | { 100 | //--- no more than 100 failed attempts 101 | if(++fail_cnt>=100) return(false); 102 | Sleep(10); 103 | } 104 | } 105 | //--- failed 106 | return(false); 107 | } 108 | //+------------------------------------------------------------------+ 109 | //| | 110 | //+------------------------------------------------------------------+ 111 | bool IsStoppedExt() 112 | { 113 | if( IsStopped() ) return(true); 114 | //--- 115 | if( GetTickCount() - StartTickCount > MAX_WAITING_TIME ) return(true); 116 | //--- 117 | return(false); 118 | } 119 | //+------------------------------------------------------------------+ 120 | -------------------------------------------------------------------------------- /shistoryexport-mql5/String.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| String.mqh | 3 | //| Copyright 2012-2014, komposter | 4 | //| http://www.komposter.me/ | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2012-2014, komposter" 7 | #property link "http://www.komposter.me/" 8 | #property version "2.0" 9 | //+------------------------------------------------------------------+ 10 | //| | 11 | //+------------------------------------------------------------------+ 12 | int StringSplitTrim(string str_from,ushort delimiter,string &array[]) 13 | { 14 | int size=StringSplit(str_from,delimiter,array); 15 | //--- 16 | if(size>0 && array[size-1]=="") 17 | { 18 | size --; 19 | ArrayResize(array,size); 20 | } 21 | //--- 22 | return( size ); 23 | } 24 | //+------------------------------------------------------------------+ 25 | //| StringToArray (string) 26 | //+------------------------------------------------------------------+ 27 | int StringToArray(string str_from,string &array[],string delimiter=",") 28 | { 29 | return( StringSplitTrim( str_from, StringGetCharacter( delimiter, 0 ), array ) ); 30 | } 31 | //+------------------------------------------------------------------+ 32 | //| StringToArray (int) 33 | //+------------------------------------------------------------------+ 34 | int StringToArray(string str_from,int &array[],string delimiter=",") 35 | { 36 | string str_array[]; 37 | int size=StringSplitTrim(str_from,StringGetCharacter(delimiter,0),str_array); 38 | //--- 39 | if(size>0) 40 | { 41 | ArrayResize(array,size); 42 | for(int s=0; s0) 56 | { 57 | ArrayResize(array,size); 58 | for(int s=0; s 13 | #include 14 | #include 15 | #include 16 | 17 | input string Main_Properties = ""; // Main properties: 18 | input string SymbolsList = "all"; // * List of symbols (or "all" MarketWatch symbols) 19 | input string TimeFramesList = "M1"; // * List of TFs (or "all" MT4 TFs) 20 | input int BarsToDownload = 0; // * Bars to download (0 - all visible in MT) 21 | 22 | #define OFFLINE_HEADER_SIZE 148 // LONG_VALUE + 64 + 12 + 4 * LONG_VALUE + 13 * LONG_VALUE 23 | #define OFFLINE_RECORD_SIZE 44 // 5 * DOUBLE_VALUE + LONG_VALUE 24 | 25 | //+------------------------------------------------------------------+ 26 | //| | 27 | //+------------------------------------------------------------------+ 28 | void OnStart() 29 | { 30 | uint start = GetTickCount(); 31 | 32 | //--- Get symbols from list 33 | string strSymbols = SymbolsList; 34 | if ( strSymbols == "all" || strSymbols == "" ) 35 | { 36 | strSymbols = ""; 37 | for ( int s = SymbolsTotal( true )-1; s >= 0; s -- ) 38 | { 39 | StringAdd( strSymbols, SymbolName( s, true ) ); 40 | if ( s != 0 ) StringAdd( strSymbols, "," ); 41 | } 42 | } 43 | 44 | string SymbolsName[]; 45 | int SymbolsCount = StringToArray( strSymbols, SymbolsName ); 46 | if ( SymbolsCount <= 0 ) 47 | { 48 | Alert( "Invalid SymbolsList (\"", SymbolsList, "\")!" ); 49 | return; 50 | } 51 | 52 | //--- Get TFs from list 53 | string strTimeFrames = TimeFramesList; 54 | if ( strTimeFrames == "all" || strTimeFrames == "" ) strTimeFrames = "M1,M5,M15,M30,H1,H4,D1"; 55 | 56 | string PeriodsName[]; 57 | int PeriodsCount = StringToArray( strTimeFrames, PeriodsName ); 58 | if ( PeriodsCount <= 0 ) 59 | { 60 | Alert( "Invalid TimeFramesList (\"", TimeFramesList, "\")!" ); 61 | return; 62 | } 63 | 64 | //--- Get bars count 65 | int BarsCount = BarsToDownload, MaxBars = TerminalInfoInteger( TERMINAL_MAXBARS ); 66 | if ( BarsCount <= 0 || BarsCount > MaxBars ) BarsCount = MaxBars; 67 | 68 | //--- 69 | int files_count = 0; 70 | for ( int s = 0; s < SymbolsCount; s ++ ) 71 | { 72 | for ( int p = 0; p < PeriodsCount; p ++ ) 73 | { 74 | Comment( "Downloading history and writing files: ", DoubleToString( (PeriodsCount*s+p)/double(SymbolsCount*PeriodsCount)*100.0, 1 ), "% complete..." ); 75 | CheckLoadHistory( SymbolsName[s], StringToPeriod( PeriodsName[p] ), BarsCount ); 76 | if ( WriteHistoryToFile( SymbolsName[s], StringToPeriod( PeriodsName[p] ), BarsCount ) ) files_count ++; 77 | } 78 | } 79 | 80 | //--- 81 | Alert( "History export finished within ", DoubleToString( (GetTickCount() - start)/1000.0, 1 ), " sec! ", IntegerToString( files_count ), " files have been written to:\n", 82 | TerminalInfoString( TERMINAL_DATA_PATH ), "\\MQL5\\Files\\History (" + AccountInfoString( ACCOUNT_SERVER ) + ")\\" ); 83 | Comment( "" ); 84 | } 85 | 86 | //+------------------------------------------------------------------+ 87 | //| | 88 | //+------------------------------------------------------------------+ 89 | bool WriteHistoryToFile( string symbol, ENUM_TIMEFRAMES period, int bars_count ) 90 | { 91 | uint start = GetTickCount(); 92 | 93 | CFileTxt FileTxt; 94 | CFileBin FileBin; 95 | 96 | MqlRates rates_array[]; 97 | ArraySetAsSeries( rates_array, true ); 98 | 99 | int copy_count = CopyRates( symbol, period, 0, bars_count, rates_array ); 100 | if ( copy_count < 0 ) return(false); 101 | 102 | int digits =(int)SymbolInfoInteger( symbol, SYMBOL_DIGITS ); 103 | int period_s = PeriodSeconds( period ) / 60; 104 | 105 | // Open a file 106 | FileTxt.Open( "History (" + AccountInfoString( ACCOUNT_SERVER ) + ")\\" + symbol + PeriodToString ( period ) + ".csv", FILE_WRITE ); 107 | FileBin.Open( "History (" + AccountInfoString( ACCOUNT_SERVER ) + ")\\" + symbol + IntegerToString( period_s ) + ".hst", FILE_ANSI|FILE_WRITE ); 108 | 109 | //--- 110 | int version = 400; 111 | string c_copyright = "Copyright 2012-2013, komposter"; 112 | int i_unused [13]; 113 | 114 | FileBin.Seek ( 0, SEEK_SET ); 115 | FileBin.WriteInteger ( version ); 116 | FileBin.WriteString ( c_copyright, 64 ); 117 | FileBin.WriteString ( symbol, 12 ); 118 | FileBin.WriteInteger ( period_s ); 119 | FileBin.WriteInteger ( digits ); 120 | FileBin.WriteInteger ( (int)TimeCurrent() ); 121 | FileBin.WriteInteger ( (int)TimeCurrent() ); 122 | FileBin.WriteArray ( i_unused, 0, 13 ); 123 | 124 | //--- 125 | for ( int i = copy_count-1; i > 0; i -- ) 126 | { 127 | string str_write = ""; 128 | StringConcatenate( str_write 129 | , TimeToString( rates_array[i].time, TIME_DATE ) 130 | , ",", TimeToString( rates_array[i].time, TIME_MINUTES ) 131 | , ",", DoubleToString( rates_array[i].open , digits ) 132 | , ",", DoubleToString( rates_array[i].high , digits ) 133 | , ",", DoubleToString( rates_array[i].low , digits ) 134 | , ",", DoubleToString( rates_array[i].close , digits ) 135 | , ",", DoubleToString( rates_array[i].tick_volume, 0 ) 136 | , "\n" ); 137 | FileTxt.WriteString( str_write ); 138 | 139 | //--- 140 | FileBin.WriteInteger ( (int)rates_array[i].time ); 141 | FileBin.WriteDouble ( rates_array[i].open ); 142 | FileBin.WriteDouble ( rates_array[i].low ); 143 | FileBin.WriteDouble ( rates_array[i].high ); 144 | FileBin.WriteDouble ( rates_array[i].close ); 145 | FileBin.WriteDouble ( rates_array[i].tick_volume ); 146 | } 147 | 148 | Print( symbol, ", ", EnumToString( period ), ": ", IntegerToString( copy_count ), " bars have been written to \"", FileTxt.FileName(), "\" and \"", FileBin.FileName(), "\" within ", DoubleToString( (GetTickCount() - start)/1000.0, 1 ), " sec!" ); 149 | FileTxt.Close(); 150 | FileBin.Close(); 151 | 152 | return(true); 153 | } 154 | -------------------------------------------------------------------------------- /socket.mq5: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| socket.mq5 | 3 | //| avoitenko | 4 | //| https://login.mql5.com/en/users/avoitenko | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "avoitenko" 7 | #property link "https://login.mql5.com/en/users/avoitenko" 8 | #property version "1.00" 9 | 10 | //+------------------------------------------------------------------+ 11 | //| Defines | 12 | //+------------------------------------------------------------------+ 13 | #define ERROR_SUCCESS 0 14 | #define SOCKET_STATUS_CONNECTED 1 15 | #define SOCKET_STATUS_DISCONNECTED 2 16 | //+------------------------------------------------------------------+ 17 | //| SOCKET_CLIENT | 18 | //+------------------------------------------------------------------+ 19 | struct SOCKET_CLIENT 20 | { 21 | uchar status; 22 | ushort sequence; 23 | uint sock; 24 | }; 25 | //+------------------------------------------------------------------+ 26 | //| ENUM_DATA_TYPE | 27 | //+------------------------------------------------------------------+ 28 | enum ENUM_DATA_TYPE 29 | { 30 | DATA_STRING,//String 31 | DATA_STRUCT //Struct 32 | }; 33 | //+------------------------------------------------------------------+ 34 | //| Inport DLL | 35 | //+------------------------------------------------------------------+ 36 | #import "socket_mql5_x86.dll" 37 | uint SocketOpen(SOCKET_CLIENT &socket,const string host,const ushort port); 38 | void SocketClose(SOCKET_CLIENT &socket); 39 | uint SocketWriteStruct(SOCKET_CLIENT &socket,const string symbol,const MqlTick &tick); 40 | uint SocketWriteString(SOCKET_CLIENT &socket,const string str); 41 | string SocketErrorString(int error_code); 42 | #import "socket_mql5_x64.dll" 43 | uint SocketOpen(SOCKET_CLIENT &socket,const string host,const ushort port); 44 | void SocketClose(SOCKET_CLIENT &socket); 45 | uint SocketWriteStruct(SOCKET_CLIENT &socket,const string symbol,const MqlTick &tick); 46 | uint SocketWriteString(SOCKET_CLIENT &socket,const string str); 47 | string SocketErrorString(int error_code); 48 | #import 49 | //+------------------------------------------------------------------+ 50 | //| SocketOpen | 51 | //+------------------------------------------------------------------+ 52 | uint SocketOpen(SOCKET_CLIENT &socket,const string host,const ushort port) 53 | { 54 | if(_IsX64)return(socket_mql5_x64::SocketOpen(socket, host, port)); 55 | return(socket_mql5_x86::SocketOpen(socket, host, port)); 56 | } 57 | //+------------------------------------------------------------------+ 58 | //| SocketClose | 59 | //+------------------------------------------------------------------+ 60 | void SocketClose(SOCKET_CLIENT &socket) 61 | { 62 | if(_IsX64)socket_mql5_x64::SocketClose(socket); 63 | else socket_mql5_x86::SocketClose(socket); 64 | } 65 | //+------------------------------------------------------------------+ 66 | //| SocketWriteData | 67 | //+------------------------------------------------------------------+ 68 | uint SocketWriteStruct(SOCKET_CLIENT &socket,const string symbol,const MqlTick &tick) 69 | { 70 | if(_IsX64)return(socket_mql5_x64::SocketWriteStruct(socket,symbol,tick)); 71 | return(socket_mql5_x86::SocketWriteStruct(socket,symbol,tick)); 72 | } 73 | //+------------------------------------------------------------------+ 74 | //| SocketWriteString | 75 | //+------------------------------------------------------------------+ 76 | uint SocketWriteString(SOCKET_CLIENT &socket,const string str) 77 | { 78 | if(_IsX64)return(socket_mql5_x64::SocketWriteString(socket,str)); 79 | return(socket_mql5_x86::SocketWriteString(socket,str)); 80 | } 81 | //+------------------------------------------------------------------+ 82 | //| SysErrorMessage | 83 | //+------------------------------------------------------------------+ 84 | string SocketErrorString(const int error_code) 85 | { 86 | if(_IsX64)return(socket_mql5_x64::SocketErrorString(error_code)); 87 | return(socket_mql5_x86::SocketErrorString(error_code)); 88 | } 89 | 90 | //+------------------------------------------------------------------+ 91 | //| Input variables | 92 | //+------------------------------------------------------------------+ 93 | input string InpHost="localhost"; // Host 94 | input ushort InpPort=777; // Port 95 | input ENUM_DATA_TYPE InpType=DATA_STRING; // Data Type 96 | 97 | //--- global variables 98 | SOCKET_CLIENT client; 99 | MqlTick last_tick; 100 | //+------------------------------------------------------------------+ 101 | //| OnInit | 102 | //+------------------------------------------------------------------+ 103 | int OnInit() 104 | { 105 | SocketOpen(client,InpHost,InpPort); 106 | return(INIT_SUCCEEDED); 107 | } 108 | //+------------------------------------------------------------------+ 109 | //| OnDeinit | 110 | //+------------------------------------------------------------------+ 111 | void OnDeinit(const int reason) 112 | { 113 | SocketClose(client); 114 | } 115 | //+------------------------------------------------------------------+ 116 | //| OnTick | 117 | //+------------------------------------------------------------------+ 118 | void OnTick() 119 | { 120 | 121 | if(!SymbolInfoTick(_Symbol,last_tick))return; 122 | 123 | string str_msg=StringFormat("symbol: %s dt: %s bid: %s ask: %s",_Symbol,TimeToString(last_tick.time,TIME_DATE|TIME_SECONDS), 124 | DoubleToString(last_tick.bid,_Digits),DoubleToString(last_tick.ask,_Digits)); 125 | 126 | switch(InpType) 127 | { 128 | case DATA_STRING: //write string 129 | { 130 | string str_out=StringFormat("%s %s %s %s",_Symbol,TimeToString(last_tick.time,TIME_DATE|TIME_SECONDS), 131 | DoubleToString(last_tick.bid,_Digits),DoubleToString(last_tick.ask,_Digits)); 132 | 133 | uint err=SocketWriteString(client,str_out); 134 | if(err!=ERROR_SUCCESS) 135 | { 136 | Print(SocketErrorString(err)); 137 | SocketOpen(client,InpHost,InpPort); 138 | } 139 | else 140 | Print(str_msg); 141 | } 142 | break; 143 | 144 | case DATA_STRUCT: //write struct 145 | { 146 | 147 | uint err=SocketWriteStruct(client,_Symbol,last_tick); 148 | if(err!=ERROR_SUCCESS) 149 | { 150 | Print(SocketErrorString(err)); 151 | SocketOpen(client,InpHost,InpPort); 152 | } 153 | else 154 | Print(str_msg); 155 | } 156 | break; 157 | }// end switch 158 | } 159 | //+------------------------------------------------------------------+ 160 | -------------------------------------------------------------------------------- /socket_mql5.cpp: -------------------------------------------------------------------------------- 1 | // https://www.mql5.com/en/code/169 2 | //+------------------------------------------------------------------+ 3 | //| SOCKET client DLL Library | 4 | //+------------------------------------------------------------------+ 5 | 6 | #define _CRT_SECURE_NO_DEPRECATE 7 | #include 8 | 9 | #pragma comment(lib, "ws2_32.lib") 10 | #pragma intrinsic(__rdtsc) 11 | 12 | #define SOCKET_STATUS_CONNECTED 1 13 | #define SOCKET_STATUS_DISCONNECTED 2 14 | 15 | typedef struct _SOCKET_CLIENT 16 | { 17 | BYTE status; 18 | USHORT sequence; 19 | ULONG sock; 20 | } SOCKET_CLIENT, *PSOCKET_CLIENT; 21 | 22 | typedef struct _MqlTick 23 | { 24 | __int64 time; 25 | double bid; 26 | double ask; 27 | double last; 28 | __int64 volume; 29 | } MqlTick; 30 | 31 | typedef struct _SOCKET_DATA 32 | { 33 | char symbol[16]; 34 | MqlTick tick; 35 | } SOCKET_DATA; 36 | 37 | //+------------------------------------------------------------------+ 38 | //| my_rand | 39 | //+------------------------------------------------------------------+ 40 | ULONG my_rand() 41 | { 42 | return (ULONG)__rdtsc(); 43 | } 44 | 45 | //+------------------------------------------------------------------+ 46 | //| Host2Ip | 47 | //+------------------------------------------------------------------+ 48 | ULONG Host2Ip(char * host) 49 | { 50 | struct hostent * p; 51 | ULONG ret; 52 | p = gethostbyname(host); 53 | if(p) ret = *(ULONG*)(p->h_addr); 54 | else ret = INADDR_NONE; 55 | return ret; 56 | } 57 | 58 | //+------------------------------------------------------------------+ 59 | //| ConnectToServer | 60 | //+------------------------------------------------------------------+ 61 | ULONG ConnectToServer(char * host, USHORT port) 62 | { 63 | struct sockaddr_in addr; 64 | BOOL bOptVal = TRUE; 65 | int bOptLen = sizeof(BOOL); 66 | 67 | ULONG ip; 68 | SOCKET sock = INVALID_SOCKET; 69 | 70 | ip = Host2Ip(host); 71 | if (ip != INADDR_NONE) 72 | { 73 | addr.sin_addr.S_un.S_addr = ip; 74 | addr.sin_port = htons(port); 75 | 76 | if (addr.sin_addr.S_un.S_addr != INADDR_NONE) 77 | { 78 | addr.sin_family = AF_INET; 79 | sock = (ULONG)socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);//IPPROTO_TCP 80 | 81 | if (sock != INVALID_SOCKET) 82 | { 83 | if (connect(sock, (struct sockaddr *)&addr, sizeof(addr))) 84 | { 85 | closesocket(sock); 86 | sock = INVALID_SOCKET; 87 | } 88 | } 89 | } 90 | } 91 | 92 | return (ULONG)sock; 93 | } 94 | 95 | //+------------------------------------------------------------------+ 96 | //| SocketOpen | 97 | //+------------------------------------------------------------------+ 98 | ULONG __stdcall SocketOpen(PSOCKET_CLIENT client, wchar_t * wc_host, USHORT port) 99 | { 100 | ULONG ret = ERROR_INVALID_HANDLE; 101 | 102 | char *host = new char[wcslen(wc_host) + 1]; 103 | wcstombs(host, wc_host, wcslen(wc_host) + 1); 104 | 105 | client->status = SOCKET_STATUS_DISCONNECTED; 106 | client->sequence = (USHORT)my_rand(); 107 | client->sock = ConnectToServer(host, port); 108 | 109 | if (client->sock == INVALID_SOCKET) 110 | { 111 | closesocket(client->sock); 112 | } 113 | else 114 | { 115 | client->status = SOCKET_STATUS_CONNECTED; 116 | ret = ERROR_SUCCESS; 117 | } 118 | delete(host); 119 | 120 | return(ret); 121 | } 122 | //+------------------------------------------------------------------+ 123 | //| SocketClose | 124 | //+------------------------------------------------------------------+ 125 | void __stdcall SocketClose(PSOCKET_CLIENT client) 126 | { 127 | if (client->status == SOCKET_STATUS_CONNECTED) 128 | { 129 | closesocket(client->sock); 130 | client->status = SOCKET_STATUS_DISCONNECTED; 131 | } 132 | } 133 | 134 | //+------------------------------------------------------------------+ 135 | //| SocketWriteStruct | 136 | //+------------------------------------------------------------------+ 137 | ULONG __stdcall SocketWriteStruct(PSOCKET_CLIENT client, wchar_t *symbol, MqlTick *tick) 138 | { 139 | SOCKET_DATA mydata={0}; 140 | char cdata[sizeof(_SOCKET_DATA)]={0}; 141 | ULONG ret = ERROR_INVALID_HANDLE; 142 | 143 | wcstombs(mydata.symbol, symbol, sizeof(mydata.symbol)); 144 | 145 | if(client->status == SOCKET_STATUS_CONNECTED) 146 | { 147 | //build data 148 | memcpy(&mydata.tick, tick, sizeof(MqlTick)); 149 | memcpy(&cdata, &mydata, sizeof(SOCKET_DATA)); 150 | 151 | //send data 152 | if (send(client->sock, cdata, sizeof(SOCKET_DATA), 0) != sizeof(SOCKET_DATA)) 153 | { 154 | client->status = SOCKET_STATUS_DISCONNECTED; 155 | ret = GetLastError(); 156 | closesocket(client->sock); 157 | } 158 | else 159 | ret = ERROR_SUCCESS; 160 | } 161 | 162 | return ret; 163 | } 164 | 165 | 166 | //+------------------------------------------------------------------+ 167 | //| SocketWriteString | 168 | //+------------------------------------------------------------------+ 169 | ULONG __stdcall SocketWriteString(PSOCKET_CLIENT client, wchar_t *wstr) 170 | { 171 | ULONG ret = ERROR_INVALID_HANDLE; 172 | 173 | char * str = new char[wcslen(wstr) + 1]; 174 | wcstombs(str, wstr, wcslen(wstr) + 1); 175 | 176 | if (client->status == SOCKET_STATUS_CONNECTED) 177 | { 178 | //--- send string 179 | if(send(client->sock, str, (int)strlen(str), 0) != strlen(str)) 180 | { 181 | client->status = SOCKET_STATUS_DISCONNECTED; 182 | ret = GetLastError(); 183 | closesocket(client->sock); 184 | } 185 | else 186 | ret = ERROR_SUCCESS; 187 | } 188 | delete (str); 189 | return ret; 190 | } 191 | 192 | 193 | //+------------------------------------------------------------------+ 194 | //| SocketErrorString | 195 | //+------------------------------------------------------------------+ 196 | wchar_t * __stdcall SocketErrorString(int error_code) 197 | { 198 | wchar_t buffer[255]={0}; 199 | if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, error_code, LANG_NEUTRAL, buffer, 255, 0)>0) 200 | { 201 | for(size_t i=0; i0 && buffer[i]<32) buffer[i]=32; 203 | } 204 | else 205 | { 206 | wchar_t strerr[16]; 207 | _itow(error_code,strerr,10); 208 | wcscpy(&buffer[0],L"Error "); 209 | wcscpy(&buffer[6],strerr); 210 | } 211 | return(&buffer[0]); 212 | } 213 | 214 | //+------------------------------------------------------------------+ 215 | //| DllMain 216 | //| https://msdn.microsoft.com/en-us/library/zxk0tw93.aspx 217 | //+------------------------------------------------------------------+ 218 | BOOL __stdcall DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 219 | { 220 | WSADATA ws; 221 | switch (ul_reason_for_call) 222 | { 223 | case DLL_PROCESS_ATTACH: 224 | WSAStartup(0x202, &ws); 225 | break; 226 | case DLL_PROCESS_DETACH: 227 | WSACleanup(); 228 | break; 229 | } 230 | return 1; 231 | } 232 | -------------------------------------------------------------------------------- /supertrend.mq5: -------------------------------------------------------------------------------- 1 | 2 | //+------------------------------------------------------------------+ 3 | //| SuperTrend.mq5 | 4 | //| Copyright 2011, FxGeek | 5 | //| http://www.mql5.com | 6 | //+------------------------------------------------------------------+ 7 | #property copyright "Copyright 2011, FxGeek" 8 | #property link " http://www.mql5.com" 9 | #property version "1.00" 10 | #property indicator_chart_window 11 | #property indicator_buffers 9 12 | #property indicator_plots 2 13 | 14 | #property indicator_label1 "Filling" 15 | #property indicator_type1 DRAW_FILLING 16 | #property indicator_color1 clrBisque, clrPaleGreen 17 | 18 | #property indicator_label2 "SuperTrend" 19 | #property indicator_type2 DRAW_COLOR_LINE 20 | #property indicator_color2 clrGreen, clrRed 21 | 22 | input int Periode=10; 23 | input double Multiplier=3; 24 | input bool Show_Filling=true; // Show as DRAW_FILLING 25 | 26 | double Filled_a[]; 27 | double Filled_b[]; 28 | double SuperTrend[]; 29 | double ColorBuffer[]; 30 | double Atr[]; 31 | double Up[]; 32 | double Down[]; 33 | double Middle[]; 34 | double trend[]; 35 | 36 | int atrHandle; 37 | int changeOfTrend; 38 | int flag; 39 | int flagh; 40 | //+------------------------------------------------------------------+ 41 | //| Custom indicator initialization function | 42 | //+------------------------------------------------------------------+ 43 | int OnInit() 44 | { 45 | //--- indicator buffers mapping 46 | SetIndexBuffer(0,Filled_a,INDICATOR_DATA); 47 | SetIndexBuffer(1,Filled_b,INDICATOR_DATA); 48 | SetIndexBuffer(2,SuperTrend,INDICATOR_DATA); 49 | SetIndexBuffer(3,ColorBuffer,INDICATOR_COLOR_INDEX); 50 | SetIndexBuffer(4,Atr,INDICATOR_CALCULATIONS); 51 | SetIndexBuffer(5,Up,INDICATOR_CALCULATIONS); 52 | SetIndexBuffer(6,Down,INDICATOR_CALCULATIONS); 53 | SetIndexBuffer(7,Middle,INDICATOR_CALCULATIONS); 54 | SetIndexBuffer(8,trend,INDICATOR_CALCULATIONS); 55 | 56 | atrHandle=iATR(_Symbol,_Period,Periode); 57 | //--- 58 | return(0); 59 | } 60 | //+------------------------------------------------------------------+ 61 | //| Custom indicator iteration function | 62 | //+------------------------------------------------------------------+ 63 | int OnCalculate(const int rates_total, 64 | const int prev_calculated, 65 | const datetime &time[], 66 | const double &open[], 67 | const double &high[], 68 | const double &low[], 69 | const double &close[], 70 | const long &tick_volume[], 71 | const long &volume[], 72 | const int &spread[]) 73 | { 74 | //--- 75 | int to_copy; 76 | if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total; 77 | else 78 | { 79 | to_copy=rates_total-prev_calculated; 80 | if(prev_calculated>0) to_copy++; 81 | } 82 | 83 | if(IsStopped()) return(0); //Checking for stop flag 84 | if(CopyBuffer(atrHandle,0,0,to_copy,Atr)<=0) 85 | { 86 | Print("Getting Atr is failed! Error",GetLastError()); 87 | return(0); 88 | } 89 | 90 | int first; 91 | if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator 92 | { 93 | first=Periode; // starting index for calculation of all bars 94 | } 95 | else 96 | { 97 | first=prev_calculated-1; // starting number for calculation of new bars 98 | } 99 | for(int i=first; iUp[i-1]) 106 | { 107 | trend[i]=1; 108 | if(trend[i-1]==-1) changeOfTrend=1; 109 | 110 | } 111 | else if(close[i]0) 128 | { 129 | flag=1; 130 | } 131 | else 132 | { 133 | flag=0; 134 | } 135 | 136 | if(trend[i]>0 && trend[i-1]<0) 137 | { 138 | flagh=1; 139 | } 140 | else 141 | { 142 | flagh=0; 143 | } 144 | 145 | if(trend[i]>0 && Down[i]Up[i-1]) 149 | Up[i]=Up[i-1]; 150 | 151 | if(flag==1) 152 | Up[i]=Middle[i]+(Multiplier*Atr[i]); 153 | 154 | if(flagh==1) 155 | Down[i]=Middle[i]-(Multiplier*Atr[i]); 156 | 157 | //-- Draw the indicator 158 | if(trend[i]==1) 159 | { 160 | SuperTrend[i]=Down[i]; 161 | if(changeOfTrend==1) 162 | { 163 | SuperTrend[i-1]=SuperTrend[i-2]; 164 | changeOfTrend=0; 165 | } 166 | ColorBuffer[i]=0.0; 167 | } 168 | else if(trend[i]==-1) 169 | { 170 | SuperTrend[i]=Up[i]; 171 | if(changeOfTrend==1) 172 | { 173 | SuperTrend[i-1]= SuperTrend[i-2]; 174 | changeOfTrend = 0; 175 | } 176 | ColorBuffer[i]=1.0; 177 | } 178 | 179 | if(Show_Filling) 180 | { 181 | Filled_a[i]= SuperTrend[i]; 182 | Filled_b[i]= close[i]; 183 | }else{ 184 | Filled_a[i]= EMPTY_VALUE; 185 | Filled_b[i]= EMPTY_VALUE; 186 | } 187 | 188 | } 189 | 190 | //--- return value of prev_calculated for next call 191 | return(rates_total); 192 | } 193 | //+------------------------------------------------------------------+ 194 | 195 | 196 | -------------------------------------------------------------------------------- /template_dec_2020.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lanastasov/mt-mql/0a5487edd3971a24a6cd811bb3fe61ed10aa6466/template_dec_2020.tpl -------------------------------------------------------------------------------- /tradingview-screener-mean-reversion: -------------------------------------------------------------------------------- 1 | https://www.tradingview.com/script/Lr5QD0kK-Screener-Mean-Reversion-Channel/ 2 | --------------------------------------------------------------------------------