//+------------------------------------------------------------------+ //| EASPC.mq5 | //| Azotskiy Aktiniy ICQ:695710750 | //| https://login.mql5.com/ru/users/aktiniy | //+------------------------------------------------------------------+ #property copyright "Azotskiy Aktiniy ICQ:695710750" #property link "https://login.mql5.com/ru/users/aktiniy" #property version "1.00" //+------------------------------------------------------------------+ //| Type Drawing | //+------------------------------------------------------------------+ enum type_drawing { spindles=0, // Spindles line_histogram=1, // Line and histogram }; //+------------------------------------------------------------------+ //| Type Price | //+------------------------------------------------------------------+ enum type_price { open=0, // Open high=1, // High low=2, // Low close=3, // Close middle=4, // Middle }; //--- input parameters input long magic_numb=65758473787389; // Magic number input type_drawing type_draw=1; // Type of indicator drawing input int period_VR=10; // Volume Ratio formation period input int correct_VR=4; // Volume Ratio correction number input int period_VWMA=10; // Volume Weighted Moving Average formation period input int spindles_num=10; // Number of spindles input type_price type_price_VWMA=0; // Price type for plotting Volume Weighted Moving Average // open=0; high=1; low=2; close=3; middle=4 input double lot=0.01; // Lot size input int stop=1000; // Stop Loss //--- input char p1=1; // Actions on patterns 1-buy, 2-sell, 3-close position, 4-do nothing input char p2=1; input char p3=1; input char p4=1; input char p5=1; input char p6=1; input char p7=1; input char p8=1; input char p9=1; input char p10=1; input char p11=1; input char p12=1; input char p13=1; input char p14=1; input char p15=1; input char p16=1; input char p17=1; input char p18=1; input char p19=1; input char p20=1; input char p21=1; input char p22=1; input char p23=1; input char p24=1; input char p25=1; input char p26=1; input char p27=1; input char p28=1; input char p29=1; input char p30=1; //--- int handle_SPC; // indicator handle long position_type; // position type //--- buffers for indicator's copied values double Buff_up[3]; // buffer of the upper points of the histogram double Buff_down[3]; // Buffer of the lower points of the histogram double Buff_color_up_down[3]; // buffer of the color of the histogram double Buff_open_ext[3]; // Open price buffer double Buff_close_ext[3]; // Close price buffer double Buff_VWMA_ext[3]; // Volume Weighted Moving Average buffer //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- handle_SPC=iCustom(_Symbol,PERIOD_CURRENT,"SPC.ex5",magic_numb,type_draw,period_VR,correct_VR,period_VWMA,spindles_num,type_price_VWMA); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if(func_new_bar(PERIOD_CURRENT)==true) { //--- copy the indicator buffers CopyBuffer(handle_SPC,0,1,3,Buff_up); CopyBuffer(handle_SPC,1,1,3,Buff_down); CopyBuffer(handle_SPC,2,1,3,Buff_color_up_down); CopyBuffer(handle_SPC,3,1,3,Buff_open_ext); CopyBuffer(handle_SPC,4,1,3,Buff_close_ext); CopyBuffer(handle_SPC,5,1,3,Buff_VWMA_ext); //--- analyze the situation //--- check if there is an order placed if(PositionSelect(_Symbol)==true) { position_type=PositionGetInteger(POSITION_TYPE); // BUY=0, SELL=1 } else { position_type=-1; // no position for the symbol } //--- prepare values to compare double body=Buff_open_ext[2]-Buff_close_ext[2]; body=MathAbs(body); double shadow=Buff_up[2]-Buff_down[2]; shadow=MathAbs(shadow); if(shadow==0)shadow=1;// prevent division by zero double body_shadow=body/shadow; //--- variables for function answer char afun_1_1=func_one(body_shadow); char afun_2_1=func_two(Buff_up[2],Buff_down[2],Buff_VWMA_ext[2]); char afun_3_1=func_three(Buff_open_ext[2],Buff_close_ext[2],Buff_VWMA_ext[2]); //--- switch(int(Buff_color_up_down[2])) { case 0: { switch(afun_1_1) { case 1: func_pre_work(afun_2_1,afun_3_1,p1,p2,p3,p4,p5); break; case 2: func_pre_work(afun_2_1,afun_3_1,p6,p7,p8,p9,p10); break; case 3: func_pre_work(afun_2_1,afun_3_1,p11,p12,p13,p14,p15); break; } } break; case 1: { switch(afun_1_1) { case 1: func_pre_work(afun_2_1,afun_3_1,p16,p17,p18,p19,p20); break; case 2: func_pre_work(afun_2_1,afun_3_1,p21,p22,p23,p24,p25); break; case 3: func_pre_work(afun_2_1,afun_3_1,p26,p27,p28,p29,p30); break; } } break; } } } //+------------------------------------------------------------------+ //| Func Pre Work | //+------------------------------------------------------------------+ void func_pre_work(char f_2, // result of the Func Two function char f_3, // result of the Func Three function char pat_1, // pattern 1 char pat_2, // pattern 2 char pat_3_1, // pattern 3_1 char pat_3_2, // pattern 3_2 char pat_3_3) // pattern 3_3 { switch(f_2) { case 1: //1 func_work(pat_1); break; case 2: //2 func_work(pat_2); break; case 3: { switch(f_3) { case 1: //3_1 func_work(pat_3_1); break; case 2: //3_2 func_work(pat_3_2); break; case 3: //3_3 func_work(pat_3_3); break; } } break; } } //+------------------------------------------------------------------+ //| Func Work | //+------------------------------------------------------------------+ void func_work(char pattern) { switch(pattern) { case 1: // buy if(position_type!=-1)func_delete_position(); func_send_order(ORDER_TYPE_BUY,lot); break; case 2: // sell if(position_type!=-1)func_delete_position(); func_send_order(ORDER_TYPE_SELL,lot); break; case 3: // close position if(position_type!=-1)func_delete_position(); break; case 4: // do nothing break; } } //+------------------------------------------------------------------+ //| Func New Bar | //+------------------------------------------------------------------+ bool func_new_bar(ENUM_TIMEFRAMES period_time) { static datetime old_times; // old values storage variable bool res=false; // analysis result variable datetime new_time[1]; // new bar time int copied=CopyTime(_Symbol,period_time,0,1,new_time); // copy the time of the last bar into the new_time cell if(copied>0) // data copied { if(old_times!=new_time[0]) // if the bar's old time is not equal to new one { if(old_times!=0) res=true; // if it is not the first launch, true = new bar old_times=new_time[0]; // store the bar's time } } return(res); } //+------------------------------------------------------------------+ //| Func Send Order | //+------------------------------------------------------------------+ bool func_send_order(ENUM_ORDER_TYPE type_order,// type of the placed order double volume) // lot deal volume { bool x=false; // variable for answer //--- declare variables for sending order MqlTradeRequest order_request={0}; MqlTradeResult order_result={0}; //--- set the variable for sending order order_request.action=TRADE_ACTION_DEAL; order_request.deviation=3; order_request.magic=555; order_request.symbol=_Symbol; order_request.type=type_order; order_request.type_filling=ORDER_FILLING_FOK; order_request.volume=volume; if(type_order==ORDER_TYPE_BUY) { order_request.price=SymbolInfoDouble(_Symbol,SYMBOL_ASK); order_request.sl=order_request.price-(_Point*stop); } if(type_order==ORDER_TYPE_SELL) { order_request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID); order_request.sl=order_request.price+(_Point*stop); } //--- send order bool y=OrderSend(order_request,order_result); if(y!=true)Alert("Order sending error."); //--- check the result if(order_result.retcode==10008 || order_result.retcode==10009) x=true; return(x); } //+------------------------------------------------------------------+ //| Func Delete Position | //+------------------------------------------------------------------+ bool func_delete_position() { bool x=false; //--- mark the position to work with PositionSelect(_Symbol); double vol=PositionGetDouble(POSITION_VOLUME); long type=PositionGetInteger(POSITION_TYPE); ENUM_ORDER_TYPE type_order; if(type==POSITION_TYPE_BUY)type_order=ORDER_TYPE_SELL; else type_order=ORDER_TYPE_BUY; //--- declare variables for sending order MqlTradeRequest order_request={0}; MqlTradeResult order_result={0}; //--- set the variable for sending order order_request.action=TRADE_ACTION_DEAL; order_request.deviation=3; order_request.magic=555; order_request.symbol=_Symbol; order_request.type=type_order; order_request.type_filling=ORDER_FILLING_FOK; order_request.volume=vol; if(type_order==ORDER_TYPE_BUY)order_request.price=SymbolInfoDouble(_Symbol,SYMBOL_ASK); if(type_order==ORDER_TYPE_SELL)order_request.price=SymbolInfoDouble(_Symbol,SYMBOL_BID); //--- send order bool y=OrderSend(order_request,order_result); if(y!=true)Alert("Order sending error."); //--- check the result if(order_result.retcode==10008 || order_result.retcode==10009) x=true; return(x); } //+------------------------------------------------------------------+ //| Func One | //+------------------------------------------------------------------+ char func_one(double body_shadow_in) { char x=0; // variable for answer if(body_shadow_in<=(double(1)/double(3))) x=1; if(body_shadow_in>(double(1)/double(3)) && body_shadow_in<=(double(2)/double(3))) x=2; if(body_shadow_in>(double(2)/double(3)) && body_shadow_in<=1) x=3; return(x); } //+------------------------------------------------------------------+ //| Func Two | //+------------------------------------------------------------------+ char func_two(double up, // high [Buff_up] double down, // low [Buff_down] double VWMA) // VWMA [Buff_VWMA_ext] { char x=0; // variable for answer if(VWMA>=up) x=1; if(VWMA<=down) x=2; else x=3; return(x); } //+------------------------------------------------------------------+ //| Func Three | //+------------------------------------------------------------------+ char func_three(double open, // open [Buff_open_ext] double close,// close [Buff_close_ext] double VWMA) // VWMA [Buff_VWMA_ext] { char x=0; // variable for answer if(open>=VWMA && close>=VWMA) x=1; if(open<=VWMA && close<=VWMA) x=2; else x=3; return(x); } //+------------------------------------------------------------------+