Results 1 to 2 of 2
 0 Attachment(s)    

Thread: Enable/Disable Expert advisor Button By Expert advsior

  1. #1

    Default Enable/Disable Expert advisor Button By custom indicator

    Dear Funyoo

    i read an article in this website Programmatically Refresh your charts | metatrader.info

    maybe you can make a sample indicator with Enable/Disable Expert advisor Button function by order specified time.
    i had idea to make disable Expert advisor button when news coming ie 18:30, and enable Expert advisor when news passed ie 19:30.

    [Ctrl+E] hot key for Enable/Disable Expert advisor

    thanks

    here sample custom indicator to refresh chart Alt+C+R

    // Indicator
    // programming to refresh chart Alt+C+R

    #import "user32.dll"
    void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);
    #import

    #define KEYEVENTF_EXTENDEDKEY 0x0001
    #define KEYEVENTF_KEYUP 0x0002

    #define VK_0 48
    #define VK_1 49
    #define VK_2 50
    #define VK_3 51
    #define VK_4 52
    #define VK_5 53
    #define VK_6 54
    #define VK_7 55
    #define VK_8 56
    #define VK_9 57
    #define VK_A 65
    #define VK_B 66
    #define VK_C 67
    #define VK_D 68
    #define VK_E 69
    #define VK_F 70
    #define VK_G 71
    #define VK_H 72
    #define VK_I 73
    #define VK_J 74
    #define VK_K 75
    #define VK_L 76
    #define VK_M 77
    #define VK_N 78
    #define VK_O 79
    #define VK_P 80
    #define VK_Q 81
    #define VK_R 82
    #define VK_S 83
    #define VK_T 84
    #define VK_U 85
    #define VK_V 86
    #define VK_W 87
    #define VK_X 88
    #define VK_Y 89
    #define VK_Z 90

    #define VK_LBUTTON 1 //Left mouse button
    #define VK_RBUTTON 2 //Right mouse button
    #define VK_CANCEL 3 //Control-break processing
    #define VK_MBUTTON 4 //Middle mouse button (three-button mouse)
    #define VK_BACK 8 //BACKSPACE key
    #define VK_TAB 9 //TAB key
    #define VK_CLEAR 12 //CLEAR key
    #define VK_RETURN 13 //ENTER key
    #define VK_SHIFT 16 //SHIFT key
    #define VK_CONTROL 17 //CTRL key
    #define VK_MENU 18 //ALT key
    #define VK_PAUSE 19 //PAUSE key
    #define VK_CAPITAL 20 //CAPS LOCK key
    #define VK_ESCAPE 27 //ESC key
    #define VK_SPACE 32 //SPACEBAR
    #define VK_PRIOR 33 //PAGE UP key
    #define VK_NEXT 34 //PAGE DOWN key
    #define VK_END 35 //END key
    #define VK_HOME 36 //HOME key
    #define VK_LEFT 37 //LEFT ARROW key
    #define VK_UP 38 //UP ARROW key
    #define VK_RIGHT 39 //RIGHT ARROW key
    #define VK_DOWN 40 //DOWN ARROW key
    #define VK_PRINT 42 //PRINT key
    #define VK_SNAPSHOT 44 //PRINT SCREEN key
    #define VK_INSERT 45 //INS key
    #define VK_DELETE 46 //DEL key
    #define VK_HELP 47 //HELP key
    #define VK_LWIN 91 //Left Windows key (Microsoft® Natural® keyboard)
    #define VK_RWIN 92 //Right Windows key (Natural keyboard)
    #define VK_APPS 93 //Applications key (Natural keyboard)
    #define VK_SLEEP 95 //Computer Sleep key
    #define VK_NUMPAD0 96 //Numeric keypad 0 key
    #define VK_NUMPAD1 97 //Numeric keypad 1 key
    #define VK_NUMPAD2 98 //Numeric keypad 2 key
    #define VK_NUMPAD3 99 //Numeric keypad 3 key
    #define VK_NUMPAD4 100 //Numeric keypad 4 key
    #define VK_NUMPAD5 101 //Numeric keypad 5 key
    #define VK_NUMPAD6 102 //Numeric keypad 6 key
    #define VK_NUMPAD7 103 //Numeric keypad 7 key
    #define VK_NUMPAD8 104 //Numeric keypad 8 key
    #define VK_NUMPAD9 105 //Numeric keypad 9 key
    #define VK_MULTIPLY 106 //Multiply key
    #define VK_ADD 107 //Add key
    #define VK_SEPARATOR 108 //Separator key
    #define VK_SUBTRACT 109 //Subtract key
    #define VK_DECIMAL 110 //Decimal key
    #define VK_DIVIDE 111 //Divide key
    #define VK_F1 112 //F1 key
    #define VK_F2 113 //F2 key
    #define VK_F3 114 //F3 key
    #define VK_F4 115 //F4 key
    #define VK_F5 116 //F5 key
    #define VK_F6 117 //F6 key
    #define VK_F7 118 //F7 key
    #define VK_F8 119 //F8 key
    #define VK_F9 120 //F9 key
    #define VK_F10 121 //F10 key
    #define VK_F11 122 //F11 key
    #define VK_F12 123 //F12 key
    #define VK_F13 124 //F13 key
    #define VK_NUMLOCK 144 //NUM LOCK key
    #define VK_SCROLL 145 //SCROLL LOCK key
    #define VK_LSHIFT 160 //Left SHIFT key
    #define VK_RSHIFT 161 //Right SHIFT key
    #define VK_LCONTROL 162 //Left CONTROL key
    #define VK_RCONTROL 163 //Right CONTROL key
    #define VK_LMENU 164 //Left MENU key
    #define VK_RMENU 165 //Right MENU key

    //---- indicator settings
    #property indicator_separate_window
    #property indicator_buffers 2
    #property indicator_color1 Silver
    #property indicator_color2 Red
    //---- indicator parameters
    extern int FastEMA=12;
    extern int SlowEMA=26;
    extern int SignalSMA=9;
    extern int SecondsToRefresh = 60;
    //---- indicator buffers
    double ind_buffer1[];
    double ind_buffer2[];

    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //---- drawing settings
    SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
    SetIndexDrawBegin(1,SignalSMA);
    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1 );
    //---- indicator buffers mapping
    if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2))
    Print("cannot set indicator buffers!");
    //---- name for DataWindow and indicator subwindow label
    IndicatorShortName("MACD("+FastEMA+","+SlowEMA+"," +SignalSMA+")");
    SetIndexLabel(0,"MACD");
    SetIndexLabel(1,"Signal");
    //---- initialization done
    return(0);
    }
    //+------------------------------------------------------------------+
    //| Moving Averages Convergence/Divergence |
    //+------------------------------------------------------------------+
    int start()
    {
    int limit;
    int counted_bars=IndicatorCounted();
    //---- check for possible errors
    if(counted_bars<0) return(-1);
    //---- last counted bar will be recounted
    if(counted_bars>0) counted_bars--;
    limit=Bars-counted_bars;
    //---- macd counted in the 1-st buffer
    for(int i=0; i<limit; i++)
    ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
    //---- signal line counted in the 2-nd buffer
    for(i=0; i<limit; i++)
    ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA, i);
    //---- done
    Refresh(SecondsToRefresh);
    return(0);
    }

    void Refresh(int seconds = 60)
    {
    datetime cur = CurTime();
    static datetime last = 0;

    if (last == 0) {last = cur;}

    if (cur > last + seconds)
    {
    last = cur;

    SendKey (VK_MENU);
    SendKey (VK_C);
    ReleaseKey(VK_MENU);
    ReleaseKey(VK_C);
    SendKey (VK_R);
    ReleaseKey(VK_R);

    }
    }

    void SendKey(int key,bool release = false)
    {
    keybd_event (key, 0, 0, 0);
    if(release)
    keybd_event (key, 0, KEYEVENTF_KEYUP, 0);

    }
    void ReleaseKey(int key)
    {
    keybd_event (key, 0, KEYEVENTF_KEYUP, 0);
    }
    Last edited by Trint; 10-18-2010 at 10:40. Reason: Change ea into custom indicator.

  2. #2

    Default

    here sample news filter ON OFF by FFcal
    i dont know it's works or not. perhaps funyoo can fix it
    thanks
    #import "user32.dll"
    void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);
    #import

    #define KEYEVENTF_EXTENDEDKEY 0x0001
    #define KEYEVENTF_KEYUP 0x0002


    #define VK_E 69
    #define VK_CONTROL 17 //CTRL key
    /*
    #define VK_0 48
    #define VK_1 49
    #define VK_2 50
    #define VK_3 51
    #define VK_4 52
    #define VK_5 53
    #define VK_6 54
    #define VK_7 55
    #define VK_8 56
    #define VK_9 57
    #define VK_A 65
    #define VK_B 66
    #define VK_C 67
    #define VK_D 68
    #define VK_F 70
    #define VK_G 71
    #define VK_H 72
    #define VK_I 73
    #define VK_J 74
    #define VK_K 75
    #define VK_L 76
    #define VK_M 77
    #define VK_N 78
    #define VK_O 79
    #define VK_P 80
    #define VK_Q 81
    #define VK_R 82
    #define VK_S 83
    #define VK_T 84
    #define VK_U 85
    #define VK_V 86
    #define VK_W 87
    #define VK_X 88
    #define VK_Y 89
    #define VK_Z 90

    #define VK_LBUTTON 1 //Left mouse button
    #define VK_RBUTTON 2 //Right mouse button
    #define VK_CANCEL 3 //Control-break processing
    #define VK_MBUTTON 4 //Middle mouse button (three-button mouse)
    #define VK_BACK 8 //BACKSPACE key
    #define VK_TAB 9 //TAB key
    #define VK_CLEAR 12 //CLEAR key
    #define VK_RETURN 13 //ENTER key
    #define VK_SHIFT 16 //SHIFT key

    #define VK_CONTROL 17 //CTRL key

    #define VK_MENU 18 //ALT key
    #define VK_PAUSE 19 //PAUSE key
    #define VK_CAPITAL 20 //CAPS LOCK key
    #define VK_ESCAPE 27 //ESC key
    #define VK_SPACE 32 //SPACEBAR
    #define VK_PRIOR 33 //PAGE UP key
    #define VK_NEXT 34 //PAGE DOWN key
    #define VK_END 35 //END key
    #define VK_HOME 36 //HOME key
    #define VK_LEFT 37 //LEFT ARROW key
    #define VK_UP 38 //UP ARROW key
    #define VK_RIGHT 39 //RIGHT ARROW key
    #define VK_DOWN 40 //DOWN ARROW key
    #define VK_PRINT 42 //PRINT key
    #define VK_SNAPSHOT 44 //PRINT SCREEN key
    #define VK_INSERT 45 //INS key
    #define VK_DELETE 46 //DEL key
    #define VK_HELP 47 //HELP key
    #define VK_LWIN 91 //Left Windows key (Microsoft® Natural® keyboard)
    #define VK_RWIN 92 //Right Windows key (Natural keyboard)
    #define VK_APPS 93 //Applications key (Natural keyboard)
    #define VK_SLEEP 95 //Computer Sleep key
    #define VK_NUMPAD0 96 //Numeric keypad 0 key
    #define VK_NUMPAD1 97 //Numeric keypad 1 key
    #define VK_NUMPAD2 98 //Numeric keypad 2 key
    #define VK_NUMPAD3 99 //Numeric keypad 3 key
    #define VK_NUMPAD4 100 //Numeric keypad 4 key
    #define VK_NUMPAD5 101 //Numeric keypad 5 key
    #define VK_NUMPAD6 102 //Numeric keypad 6 key
    #define VK_NUMPAD7 103 //Numeric keypad 7 key
    #define VK_NUMPAD8 104 //Numeric keypad 8 key
    #define VK_NUMPAD9 105 //Numeric keypad 9 key
    #define VK_MULTIPLY 106 //Multiply key
    #define VK_ADD 107 //Add key
    #define VK_SEPARATOR 108 //Separator key
    #define VK_SUBTRACT 109 //Subtract key
    #define VK_DECIMAL 110 //Decimal key
    #define VK_DIVIDE 111 //Divide key
    #define VK_F1 112 //F1 key
    #define VK_F2 113 //F2 key
    #define VK_F3 114 //F3 key
    #define VK_F4 115 //F4 key
    #define VK_F5 116 //F5 key
    #define VK_F6 117 //F6 key
    #define VK_F7 118 //F7 key
    #define VK_F8 119 //F8 key
    #define VK_F9 120 //F9 key
    #define VK_F10 121 //F10 key
    #define VK_F11 122 //F11 key
    #define VK_F12 123 //F12 key
    #define VK_F13 124 //F13 key
    #define VK_NUMLOCK 144 //NUM LOCK key
    #define VK_SCROLL 145 //SCROLL LOCK key
    #define VK_LSHIFT 160 //Left SHIFT key
    #define VK_RSHIFT 161 //Right SHIFT key
    #define VK_LCONTROL 162 //Left CONTROL key
    #define VK_RCONTROL 163 //Right CONTROL key
    #define VK_LMENU 164 //Left MENU key
    #define VK_RMENU 165 //Right MENU key
    */

    extern bool NewsFilter = true;
    extern bool High_Impact = true;
    extern int MinsUntilNextHighNews = 90;
    extern int MinsSincePrevHighNews = 90;
    extern bool Medium_Impact = true;
    extern int MinsUntilNextMediumNews = 40;
    extern int MinsSincePrevMediumNews = 40;
    extern bool Low_Impact = false;
    extern int MinsUntilNextLowNews = 5;
    extern int MinsSincePrevLowNews = 5;

    int gi_1204;
    int gi_1220;
    bool On_Trade = FALSE;
    int On_Minute = -1;

    //---- indicator settings
    #property indicator_separate_window
    #property indicator_buffers 2
    #property indicator_color1 Silver
    #property indicator_color2 Red
    //---- indicator parameters
    int FastEMA=12;
    int SlowEMA=26;
    int SignalSMA=9;
    //---- indicator buffers
    double ind_buffer1[];
    double ind_buffer2[];
    //---- input parameters


    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //---- drawing settings
    SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
    SetIndexDrawBegin(1,SignalSMA);
    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1 );
    //---- indicator buffers mapping
    if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2))
    Print("cannot set indicator buffers!");
    //---- name for DataWindow and indicator subwindow label
    IndicatorShortName("News("+FastEMA+","+SlowEMA+"," +SignalSMA+")");
    SetIndexLabel(0,"News");
    SetIndexLabel(1,"Signal");
    //---- initialization done
    return(0);
    }

    int start()
    {

    int limit;
    int counted_bars=IndicatorCounted();
    //---- check for possible errors
    if(counted_bars<0) return(-1);
    //---- last counted bar will be recounted
    if(counted_bars>0) counted_bars--;
    limit=Bars-counted_bars;
    //---- macd counted in the 1-st buffer
    for(int i=0; i<limit; i++)
    ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
    //---- signal line counted in the 2-nd buffer
    for(i=0; i<limit; i++)
    ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA, i);
    //+------------------------------------------------------------------+
    // logic to OFF EXPERT ADVISOR Button
    if ( AllowTrading()==1 ) {
    DisplayText("ex", "News Time !!!, EA Halted ", "Verdana ", 13, Red, 225, 55);
    DisplayText("eb", "Check Expert Advisor Button Must Be Disable ", "Verdana ", 13, Red, 225, 85);
    SendKey (VK_CONTROL);
    SendKey (VK_E);
    return (0);
    }
    ObjectDelete("ex");
    ObjectDelete("eb");
    Release(MinsUntilNextHighNews *2 *60); // logic to ON EXPERT ADVISOR Button need improvment
    return(0);


    }

    //+------------------------------------------------------------------+
    void SendKey(int key,bool release = false)
    {
    keybd_event (key, 0, 0, 0);
    if(release)
    keybd_event (key, 0, KEYEVENTF_KEYUP, 0);

    }
    void ReleaseKey(int key)
    {
    keybd_event (key, 0, KEYEVENTF_KEYUP, 0);
    }

    int AllowTrading() {
    int HiNews0;
    int HiNews1;
    int MedHiNews0;
    int MedHiNews1;
    int LowHiNews0;
    int LowHiNews1;
    if (NewsFilter == FALSE) return (0);
    if (NewsFilter ) {
    HiNews0 = iCustom(NULL, 0, "FFCal", 1, 0, 0, 1, 1, 1, 0);
    HiNews1 = iCustom(NULL, 0, "FFCal", 1, 0, 0, 1, 1, 1, 1);
    MedHiNews0 = iCustom(NULL, 0, "FFCal", 0, 1, 0, 1, 1, 1, 0);
    MedHiNews1 = iCustom(NULL, 0, "FFCal", 0, 1, 0, 1, 1, 1, 1);
    LowHiNews0 = iCustom(NULL, 0, "FFCal", 0, 0, 1, 1, 1, 1, 0);
    LowHiNews1 = iCustom(NULL, 0, "FFCal", 0, 0, 1, 1, 1, 1, 1);
    if (Minute() != On_Minute) {
    On_Trade = FALSE;
    On_Minute = Minute();
    if (High_Impact)
    if (HiNews1 <= MinsUntilNextHighNews || HiNews0 <= MinsSincePrevHighNews) On_Trade = TRUE;
    if (Medium_Impact)
    if (MedHiNews1 <= MinsUntilNextMediumNews || MedHiNews0 <= MinsSincePrevMediumNews) On_Trade = TRUE;
    if (Low_Impact)
    if (LowHiNews1 <= MinsUntilNextLowNews || LowHiNews0 <= MinsSincePrevLowNews) On_Trade = TRUE;
    }
    }
    return (On_Trade);
    }

    void Release(int seconds = 60)
    {
    datetime cur = CurTime();
    static datetime last = 0;

    if (last == 0) {last = cur;}

    if (cur > last + seconds)
    {
    last = cur;
    ReleaseKey(VK_CONTROL);
    ReleaseKey(VK_E);
    }
    }

    void DisplayText(string a_name_0, string a_text_8, string a_fontname_16, int a_fontsize_24, color a_color_28, int a_x_32, int a_y_36) {
    ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0);
    ObjectSetText(a_name_0, a_text_8, a_fontsize_24, a_fontname_16, a_color_28);
    ObjectSet(a_name_0, OBJPROP_CORNER, 0);
    ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_32);
    ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_36);
    }

Similar Threads

  1. SAR ADX Expert Advisor
    By funyoo in forum Expert advisors backtesting
    Replies: 29
    Last Post: 07-01-2015, 16:43
  2. The BEST Expert Advisor on the market, WallStreet Expert Advisor
    By Jacob Godly in forum Commercial expert advisors
    Replies: 0
    Last Post: 03-21-2013, 13:05
  3. SAR ADX Expert Advisor
    By funyoo in forum Expert advisors live statements
    Replies: 0
    Last Post: 02-10-2009, 13:27

Tags for this Thread

100, add, advisor, color, custom indicator, date, divergence, expert, expert advisor, high, home, indicator, limit, low, macd, metatrader, news, programming, sample, time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •