cvuforex.com
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A place where serious Forex trading efforts meet! Back to Home page of FxBussiness.com

Latest topics
» Mar 2023 project
MT4 Coding EmptyFri Apr 14, 2023 2:20 am by Admin

» Subscription Key for text to speech
MT4 Coding EmptyFri Mar 31, 2023 9:29 pm by Admin

» Mar 2023 - Forex filing
MT4 Coding EmptyMon Mar 06, 2023 12:13 pm by Admin

» MT4 Coding
MT4 Coding EmptySun Mar 05, 2023 10:50 pm by Admin

» EA that work with scripts & Indicators
MT4 Coding EmptySun Mar 05, 2023 10:49 pm by Admin

» Trade Assistance EA
MT4 Coding EmptySun Mar 05, 2023 10:49 pm by Admin

» New strategy
MT4 Coding EmptySun Mar 05, 2023 10:48 pm by Admin

» From other forum
MT4 Coding EmptyThu Mar 17, 2022 2:19 pm by Admin

» Trading Notes
MT4 Coding EmptyThu Mar 17, 2022 1:37 pm by Admin

Test only

You are not connected. Please login or register

MT4 Coding

Go down  Message [Page 1 of 1]

1MT4 Coding Empty MT4 Coding Sun Mar 05, 2023 10:50 pm

Admin

Admin
Admin

MT4 Coding
Post by admin » Fri Apr 08, 2022 10:05 am

1. Great way to call a script in an EA or to trigger an EA from an indicator :
https://www.mql5.com/en/forum/149967

A/ Extracted here the way to call a script from an indicator (may work for EA too):
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;
}


B/ Extracted here the way to have an indicator trigger the EA (that is attached to 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);
}

https://fxbusiness.forumotion.com

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum