初学者的问题 MQL5 MT5 MetaTrader 5 - 页 1337 1...133013311332133313341335133613371338133913401341134213431344...1503 新评论 Кирилл Смирнов 2021.08.14 10:00 #13361 你好,你能告诉我如何将一个结构传递给一个函数,以便在函数中对结构中的元素所做的改变被存储在全局创建的结构中? Vladimir Karputov 2021.08.14 10:34 #13362 Кирилл Смирнов: 你好,你能告诉我如何将一个结构传递给一个函数,以便在函数中对结构中的元素进行修改,并存储在全局创建的结构中? 通过引用传递结构。例子。 //+------------------------------------------------------------------+ //| Expert 1.mq5 | //| Copyright © 2021, Vladimir Karputov | //+------------------------------------------------------------------+ #property copyright "Copyright © 2021, Vladimir Karputov" #property version "1.00" //+------------------------------------------------------------------+ //| Structure Positions | //+------------------------------------------------------------------+ struct STRUCT_POSITION { ENUM_POSITION_TYPE pos_type; // position type double volume; // position volume (if "0.0" -> the lot is "Money management") double lot_coefficient; // lot coefficient bool waiting_transaction; // waiting transaction, "true" -> it's forbidden to trade, we expect a transaction ulong waiting_order_ticket; // waiting order ticket, ticket of the expected order bool transaction_confirmed; // transaction confirmed, "true" -> transaction confirmed //--- Constructor STRUCT_POSITION() { pos_type = WRONG_VALUE; volume = 0.0; lot_coefficient = 0.0; waiting_transaction = false; waiting_order_ticket = 0; transaction_confirmed = false; } }; STRUCT_POSITION SPosition; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- Example(SPosition); Comment(EnumToString(SPosition.pos_type)); } //+------------------------------------------------------------------+ //| Example | //+------------------------------------------------------------------+ void Example(STRUCT_POSITION &struct_position) { int res=MathRand(); if(res<32767/2) struct_position.pos_type=POSITION_TYPE_BUY; else struct_position.pos_type=POSITION_TYPE_SELL; } //+------------------------------------------------------------------+ 附加的文件: Expert_1.mq5 6 kb Kira27 2021.08.14 11:25 #13363 Vladimir Karputov:通过引用传递结构。例子。 谢谢!这个例子是从哪里来的? 我只是在帮助中寻找与我的问题有关的东西,但没有找到(())。 Vladimir Karputov 2021.08.14 12:05 #13364 Kira27:谢谢!这个例子是从哪里来的? 我只是在帮助中寻找与我的问题有关的东西,但没有找到(())。 例如,真实的实施+编造的功能。 Kira27 2021.08.14 13:40 #13365 Vladimir Karputov:真实的实施+捏造的函数为例。 好的,再次感谢! Alexey Viktorov 2021.08.14 14:56 #13366 Vladimir Karputov:真实的实施+捏造的函数为例。 坏的例子。一个结构,以及任何全局声明的变量,都可以在程序的任何部分被访问。 这样也会有效果。 //+------------------------------------------------------------------+ //| Structure Positions | //+------------------------------------------------------------------+ struct STRUCT_POSITION { ENUM_POSITION_TYPE pos_type; // position type double volume; // position volume (if "0.0" -> the lot is "Money management") double lot_coefficient; // lot coefficient bool waiting_transaction; // waiting transaction, "true" -> it's forbidden to trade, we expect a transaction ulong waiting_order_ticket; // waiting order ticket, ticket of the expected order bool transaction_confirmed; // transaction confirmed, "true" -> transaction confirmed //--- Constructor STRUCT_POSITION() { pos_type = WRONG_VALUE; volume = 0.0; lot_coefficient = 0.0; waiting_transaction = false; waiting_order_ticket = 0; transaction_confirmed = false; } }; STRUCT_POSITION SPosition; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- Example(); Comment(EnumToString(SPosition.pos_type)); } //+------------------------------------------------------------------+ //| Example | //+------------------------------------------------------------------+ void Example() { int res=MathRand(); if(res<32767/2) SPosition.pos_type=POSITION_TYPE_BUY; else SPosition.pos_type=POSITION_TYPE_SELL; } //+------------------------------------------------------------------+ 如果结构变量是本地声明的,那就不同了。 //+------------------------------------------------------------------+ //| Structure Positions | //+------------------------------------------------------------------+ struct STRUCT_POSITION { ENUM_POSITION_TYPE pos_type; // position type double volume; // position volume (if "0.0" -> the lot is "Money management") double lot_coefficient; // lot coefficient bool waiting_transaction; // waiting transaction, "true" -> it's forbidden to trade, we expect a transaction ulong waiting_order_ticket; // waiting order ticket, ticket of the expected order bool transaction_confirmed; // transaction confirmed, "true" -> transaction confirmed //--- Constructor STRUCT_POSITION() { pos_type = WRONG_VALUE; volume = 0.0; lot_coefficient = 0.0; waiting_transaction = false; waiting_order_ticket = 0; transaction_confirmed = false; } }; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- STRUCT_POSITION SPosition; Example(SPosition); Comment(EnumToString(SPosition.pos_type)); } //+------------------------------------------------------------------+ //| Example | //+------------------------------------------------------------------+ void Example(STRUCT_POSITION &struct_position) { int res=MathRand(); if(res<32767/2) struct_position.pos_type=POSITION_TYPE_BUY; else struct_position.pos_type=POSITION_TYPE_SELL; } //+------------------------------------------------------------------+ Alexey Kolybelnikov 2021.08.15 09:48 #13367 大家好。MT5在使用多个工具时正在加载数千兆字节的数据。是否有办法在设置中限制它?我希望月线图、周线图和日线图能像在MT4中那样绘制,即每个条形图都是(开、高、低、收),没有任何额外的内部历史。而且已经根据目前的MT5原则(实施)建立了带有日内条形图的图表。 Valeriy Yastremskiy 2021.08.16 16:35 #13368 Vladimir Makhnin: 如何用mt5增加/减少时间框架? 关于交易、自动交易系统和策略测试的论坛 指标:用热键改变时间框架 SanAlex, 2020.08.07 11:59 我认为这对MT4和MT5来说是一样的。 //+------------------------------------------------------------------+ //| hotKeys.mq5 | //| Copyright 2015,Mohit Marwaha | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Mohit Marwaha" #property link "marwaha1@gmail.com" #property version "1.20" #property indicator_chart_window #property indicator_plots 0 #property description "Keys 1 through 9 change timeframes from 1 minute to Monthly" #define KEY_MONTHLY 57 #define KEY_WEEKLY 56 #define KEY_DAILY 55 #define KEY_4HOUR 54 #define KEY_1HOUR 53 #define KEY_30MIN 52 #define KEY_15MIN 51 #define KEY_5MIN 50 #define KEY_1MIN 49 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping Comment("Copyright MohitMarwaha"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_KEYDOWN) { switch(int(lparam)) { case KEY_WEEKLY: ChartSetSymbolPeriod(0,NULL,PERIOD_W1); break; case KEY_DAILY: ChartSetSymbolPeriod(0,NULL,PERIOD_D1); break; case KEY_4HOUR: ChartSetSymbolPeriod(0,NULL,PERIOD_H4); break; case KEY_1HOUR: ChartSetSymbolPeriod(0,NULL,PERIOD_H1); break; case KEY_5MIN: ChartSetSymbolPeriod(0,NULL,PERIOD_M5); break; case KEY_30MIN: ChartSetSymbolPeriod(0,NULL,PERIOD_M30); break; case KEY_15MIN: ChartSetSymbolPeriod(0,NULL,PERIOD_M15); break; case KEY_MONTHLY: ChartSetSymbolPeriod(0,NULL,PERIOD_MN1); break; case KEY_1MIN: ChartSetSymbolPeriod(0,NULL,PERIOD_M1); break; } ChartRedraw(); } } //+------------------------------------------------------------------+ Kira27 2021.08.16 18:45 #13369 Alexey Viktorov:坏的例子。一个结构,以及任何全局声明的变量,都可以在程序的任何部分被访问。这也会起作用。如果结构变量是本地声明的,那就不同了。 谢谢你!!!。 Vladimir Makhnin 2021.08.17 08:50 #13370 Valeriy Yastremskiy: 谢谢你 1...133013311332133313341335133613371338133913401341134213431344...1503 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
你好,你能告诉我如何将一个结构传递给一个函数,以便在函数中对结构中的元素进行修改,并存储在全局创建的结构中?
通过引用传递结构。例子。
通过引用传递结构。例子。
谢谢!这个例子是从哪里来的? 我只是在帮助中寻找与我的问题有关的东西,但没有找到(())。
谢谢!这个例子是从哪里来的? 我只是在帮助中寻找与我的问题有关的东西,但没有找到(())。
例如,真实的实施+编造的功能。
真实的实施+捏造的函数为例。
好的,再次感谢!
真实的实施+捏造的函数为例。
坏的例子。一个结构,以及任何全局声明的变量,都可以在程序的任何部分被访问。
这样也会有效果。
如果结构变量是本地声明的,那就不同了。
如何用mt5增加/减少时间框架?
关于交易、自动交易系统和策略测试的论坛
指标:用热键改变时间框架
SanAlex, 2020.08.07 11:59
我认为这对MT4和MT5来说是一样的。
坏的例子。一个结构,以及任何全局声明的变量,都可以在程序的任何部分被访问。
这也会起作用。
如果结构变量是本地声明的,那就不同了。
谢谢你!!!。