• Home
  • Forums
  • News
  • Calendar
  • Market
  • Login
  • Join
  • User/Email: Password:
  • 10:57pm
Menu
  • Forums
  • News
  • Calendar
  • Market
  • Login
  • Join
  • 10:57pm
Sister Sites
  • Metals Mine
  • Crypto Craft
  • Forex Factory

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

MQL4 code help 12 replies

Help - any tools that can easily convert MQL4 code to Easy Language code? 7 replies

MQL4 Language Most Recent Version is it updated beyond the tutorial on the mql4 websi 6 replies

Need some help with MQL4 code... 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 4
Attachments: MQL4/5 Code Corner
Exit Attachments
Tags: MQL4/5 Code Corner
Cancel

MQL4/5 Code Corner

  • Post #1
  • Quote
  • First Post: Edited 10:14am Mar 16, 2023 7:02am | Edited 10:14am
  •  Georgebaker
  • | Joined Nov 2009 | Status: Member | 509 Posts
This space is for code examples!

This is NOT a space for "can you code this for me"! We already have that in this group https://www.forexfactory.com/thread/...indicators-for

I'm using a ton of time looking up code snippet/examples and when i finally, after a whole day search, find something that seems to be what i'm looking for, it doesn't work. MQL5 have a lot of documentation and that is fine, but they do not have so much code examples and i know we are many that need code examples to learn from.

Ways of improve our code is also very welcome in here so we can learn from that.
It could be like "Easiest way of making a rectangle on the chart"
Or maybe simplest way to show a obj-label on the chart
Stuff like that

IMPORTANT: Upload only code examples that you have tested so when you upload it you know it works so others is not wasting their time on things that do not work. If i see code that do not work it will be remove!

More to come, Let's begin
Blindly following others will make you blind!
  • Post #2
  • Quote
  • Last Post: Edited 12:03pm Mar 16, 2023 7:35am | Edited 12:03pm
  •  Georgebaker
  • | Joined Nov 2009 | Status: Member | 509 Posts
How to run a script from an indicator

This example is using a DLL file, so if you don't like that, this example is not for you
(I have looked for other ways to do it but could not find something that worked, will still search for it though)

From this link below (Go to post 7) unzip the zip file and find the DLL file. Copy that DLL file into your library in the mq4 folder.
https://www.forexfactory.com/thread/...from-indicator

Inserted Code
//+------------------------------------------------------------------+
//|                                               StartScriptBox.mq4 |
//|               For educational purpose only, use on your own risk |
//|                             Coded by Georgebaker aka FXSniperGuy |
//|                                                 Date: 16.03.2023 |
//+------------------------------------------------------------------+
#import "rsfExpander.dll"
   bool LoadMqlProgramW(int hChart, int programType, string programName);
#import
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
 
// MQL program types
#define PROGRAMTYPE_INDICATOR   1
#define PROGRAMTYPE_EXPERT      2
#define PROGRAMTYPE_SCRIPT      4
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   int  hChart = WindowHandle(Symbol(), NULL);
   bool result = LoadMqlProgramW(hChart, PROGRAMTYPE_SCRIPT, "Box1");
   Print("result=", result);  
//---
   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);
  }
//+------------------------------------------------------------------+

Source code file:
Attached File(s)
File Type: mq4 StartScriptBox.mq4   2 KB | 13 downloads


This is the script i trigger form the indicator: (The code in this script is so messy and it could probably have been a lot easier, but here it is)
Attached File(s)
File Type: mq4 Box1.mq4   10 KB | 13 downloads

Attached File(s)
File Type: ex4 Box1.ex4   14 KB | 13 downloads


See the short video on how it works
Attached File(s)
File Type: mp4 StartScriptBox.mp4   178 KB | 15 downloads



Tags: #mq4 #run #script #indicator
Blindly following others will make you blind!
 
 
  • Platform Tech
  • /
  • MQL4/5 Code Corner
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About EE
  • Mission
  • Products
  • User Guide
  • Blog
  • Contact
EE Products
  • Forums
  • Calendar
  • News
  • Market
EE Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow EE
  • Facebook
  • Twitter

EE Sister Sites:

  • Metals Mine
  • Crypto Craft
  • Forex Factory

Energy EXCH™ is a brand of Fair Economy, Inc.

Terms of Service / ©2023