Download MetaTrader 5
To add comments, please log in or register
Find out how to use widgets at MQL5.community
maria-2014
75
maria-2014 2014.02.25 16:13 

hello

please help me i want to find method for close my trades from my indicator by Win API or find method for call script or EA by indicator

thank you

maria-2014
75
maria-2014 2014.02.25 16:26  

how i can call theses button

darksideofthemoon
57
darksideofthemoon 2014.02.25 16:27  

There is several methods - for one such method look here: https://www.mql5.com/en/docs/eventfunctions/eventchartcustom

whroeder1
13627
whroeder1 2014.02.25 16:36  
maria2014: please help me i want to find method for close my trades from my indicator by Win API or find method for call script or EA by indicator

Indicators can not trade. Stop trying to shoe horn mt4 to your way of thinking. Likely hundreds of lines of code.

Use it how MQ designed it. Create a script or EA. Have the EA monitor the indicator via iCustom. When the condition occurs, close the orders (OrderSelect loop/OrderClose.) Likely a dozen or so lines of code.


maria-2014
75
maria-2014 2014.02.25 18:20  

hello thank you my friends

i know that we can not trade by indicator,can you close open trade with

PostMessageA(GetAncestor(WindowHandle(Symbol(),Period()),2),WM_COMMAND,35451,0);

but you will not delete the pending trade with it .

Now i want to call automatically a script, i will create a script by via indicator like same file and i will compile it by command prompt, please please help me for can call script automatically


darksideofthemoon
57
darksideofthemoon 2014.02.25 21:34  

maria2014:

please please help me for can call script automatically



ok, if you do want to do some messaging..


1. you have to do this:

#import "user32.dll"
        int SendMessageA(int, int, int, char&[]);
        int RegisterWindowMessageA(char&[]);
#import


2. you have to do this:

char sz_mt4imsg[];
char sz_script[];

string scriptname = "startme"; // name of the script

int mt4imsg;


3. you have to do this in OnInit():

StringToCharArray("MetaTrader4_Internal_Message", sz_mt4imsg);
StringToCharArray(scriptname, sz_script);
mt4imsg = RegisterWindowMessageA(sz_mt4imsg);


4. you have to do this in OnCalculate() to start script:

SendMessageA(WindowHandle(Symbol(), Period()), mt4imsg, 16, sz_script);




Here an example:

// indicator code

#property strict

#import "user32.dll"
        int SendMessageA(int, int, int, char&[]);
        int RegisterWindowMessageA(char&[]);
#import

char sz_mt4imsg[];
char sz_script[];

string scriptname = "startme"; // call the script to be started "startme"

int mt4imsg;

int OnInit() {
        StringToCharArray("MetaTrader4_Internal_Message", sz_mt4imsg);
        StringToCharArray(scriptname, sz_script);
        mt4imsg = RegisterWindowMessageA(sz_mt4imsg);
        return 0;
}

int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[],
const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) {

        // start script
        SendMessageA(WindowHandle(Symbol(), Period()), mt4imsg, 16, sz_script);
        return rates_total;
}
maria-2014
75
maria-2014 2014.02.26 09:00  

hello 2cent thank you very much you are great programer

please i want to ask you with https://www.mql5.com/en/docs/eventfunctions/eventchartcustom

i did not find how we can close order from indicator i found only a buttons, please we can close and delete the pending orders by it ?


if not please give me function detects if script name runs on chart or no and function for delete this script name


thank you very much


darksideofthemoon
57
darksideofthemoon 2014.02.26 09:46  
The idea behind EventChartCustom() function is that it can generate a custom chart event;

an attached EA that implements OnChartEvent() function can thus be notified this way and perform trading actions.
maria-2014
75
maria-2014 2014.02.26 10:15  
please 2cent give an example about trade or close trade by these from indicator please my friend
darksideofthemoon
57
darksideofthemoon 2014.02.26 10:55  

ok, here an example of how an indicator can trigger an expert advisor (run both on the same chart):


first the expert code:

// EA code
#property strict
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) {
        if(id == CHARTEVENT_CUSTOM)
                Print(sparam);
}


now the indicator:

// indicator code
#property strict
#property indicator_chart_window
string message = "Indi triggers EA!";
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
        EventChartCustom(0, 0, 0, 0, message);
        return(rates_total);
}
maria-2014
75
maria-2014 2014.02.26 11:31  

waw you are great programmer thank you very much

please our great programer

it is final question please i want a function for know if the script is run or no by script name, and function for delete (stop) the script in the chart,please

thank you

/ /12
To add comments, please log in or register