ME:
can you write for me a very minimal hello world type of an indicator for metatrader4 that reads the "target" variable from https://janicekelly.com/dash and displays that line onto the chart directly?
RESPONSE FROM AI:
I'll create a minimal MQL4 indicator that fetches the "target" value from your website and displays it on the chart. Based on the scraped content, the target value is 1.149350. mql4
This indicator will:
Fetch data from https://janicekelly.com/dash every 60 seconds
Parse the response to find the "target" line
Display the target value on your chart in the top-right corner by default
The indicator includes customizable parameters for:
The URL to fetch from
Text color and size
Position on the chart
To install it:
Save the code in MetaEditor as "Target Fetcher.mq4"
Compile it
Add it to your chart from the Navigator window
Would you like me to modify any aspects of this indicator, such as the update frequency or display formatting?
can you write for me a very minimal hello world type of an indicator for metatrader4 that reads the "target" variable from https://janicekelly.com/dash and displays that line onto the chart directly?
RESPONSE FROM AI:
I'll create a minimal MQL4 indicator that fetches the "target" value from your website and displays it on the chart. Based on the scraped content, the target value is 1.149350. mql4
Inserted Code
//+------------------------------------------------------------------+
//| Target Fetcher.mq4 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net"
#property version "1.00"
#property strict
#property indicator_chart_window
// Input parameters
input string URL = "https://janicekelly.com/dash";
input color LabelColor = clrWhite;
input int LabelSize = 12;
input int Corner = 1; // 0=Top-left, 1=Top-right, 2=Bottom-left, 3=Bottom-right
input int XDistance = 10;
input int YDistance = 10;
// Global variables
string objName = "TargetLabel";
int updateInterval = 60; // Update every 60 seconds
datetime lastUpdateTime = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Create the label object
if(!ObjectCreate(0, objName, OBJ_LABEL, 0, 0, 0))
{
Print("Error creating label: ", GetLastError());
return(INIT_FAILED);
}
// Set label properties
ObjectSetInteger(0, objName, OBJPROP_CORNER, Corner);
ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, XDistance);
ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, YDistance);
ObjectSetString(0, objName, OBJPROP_TEXT, "Fetching target...");
ObjectSetInteger(0, objName, OBJPROP_COLOR, LabelColor);
ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, LabelSize);
ObjectSetString(0, objName, OBJPROP_FONT, "Arial");
// Force an update on initialization
lastUpdateTime = 0;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Clean up
ObjectDelete(0, objName);
}
//+------------------------------------------------------------------+
//| 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[])
{
// Check if it's time to update
datetime currentTime = TimeCurrent();
if(currentTime - lastUpdateTime >= updateInterval)
{
// Update the target value
UpdateTargetValue();
lastUpdateTime = currentTime;
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Update target value from website |
//+------------------------------------------------------------------+
void UpdateTargetValue()
{
string headers;
string data;
char result[];
char result_headers[];
// Reset last error
ResetLastError();
// Make the web request
int timeout = 5000; // 5 seconds timeout
int res = WebRequest("GET", URL, "", timeout, data, result, result_headers);
if(res == 200)
{
// Convert result to string
string response = CharArrayToString(result);
// Extract the target value
string targetValue = ExtractTargetValue(response);
// Update the label
if(targetValue != "")
{
ObjectSetString(0, objName, OBJPROP_TEXT, "Target: " + targetValue);
Print("Target updated: ", targetValue);
}
else
{
ObjectSetString(0, objName, OBJPROP_TEXT, "Target: Not found");
Print("Could not extract target value from response");
}
}
else
{
ObjectSetString(0, objName, OBJPROP_TEXT, "Error: " + IntegerToString(res));
Print("WebRequest failed with error: ", GetLastError(), " HTTP code: ", res);
}
}
//+------------------------------------------------------------------+
//| Extract target value from response text |
//+------------------------------------------------------------------+
string ExtractTargetValue(const string& response)
{
// Look for the line containing "target:"
string lines[];
StringSplit(response, '\n', lines);
for(int i = 0; i < ArraySize(lines); i++)
{
string line = lines[i];
StringTrimLeft(line);
StringTrimRight(line);
// Check if this line contains "target:"
if(StringFind(line, "target:", 0) == 0)
{
// Extract the value after "target:"
string parts[];
StringSplit(line, ':', parts);
if(ArraySize(parts) >= 2)
{
StringTrimLeft(parts[1]);
StringTrimRight(parts[1]);
return parts[1];
}
}
}
return ""; // Not found
}
//+------------------------------------------------------------------+ This indicator will:
Fetch data from https://janicekelly.com/dash every 60 seconds
Parse the response to find the "target" line
Display the target value on your chart in the top-right corner by default
The indicator includes customizable parameters for:
The URL to fetch from
Text color and size
Position on the chart
To install it:
Save the code in MetaEditor as "Target Fetcher.mq4"
Compile it
Add it to your chart from the Navigator window
Would you like me to modify any aspects of this indicator, such as the update frequency or display formatting?