Converting Pine Script into MQL4 language (Easy Indicator)

Converting Pine Script into MQL4 language (Easy Indicator)

Manage alerts

Loading saved threads...

Lilyyyy · External communityPost link
External question — Stack Overflow Stack Exchange Author: Lilyyyy Original post: https://stackoverflow.com/questions/65981209 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. This is a High/Low indicator in Pine Script language. Can anyone help me to convert it into MQL4. It should be very easy for some of you ;) lenH = input(title="Length High", type=input.integer, defval=5, minval=1) lenL = input(title="Length Low", type=input.integer, defval=5, minval=1) fun(src, len, isHigh, _style, _yloc, _color) => p = nz(src[len]) isFound = true for i = 0 to len - 1 if isHigh and src[i] > p isFound := false if not isHigh and src[i] < p isFound := false for i = len + 1 to 2 * len if isHigh and src[i] >= p isFound := false if not isHigh and src[i] <= p isFound := false if isFound label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color) fun(close, lenH, true, label.style_labeldown, yloc.abovebar, color.lime) fun(close, lenL, false, label.style_labelup, yloc.belowbar, color.red) The result should be like this in 1hr timeframe. enter image description here
Quote
Report
Lilyyyy · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Lilyyyy Original post: https://stackoverflow.com/a/65983031 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. oh, I have found the answer la. #include <stdlib.mqh> #include <stderror.mqh> //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 1 #property indicator_color1 0x4800FF #property indicator_label1 "HIGH" #property indicator_type2 DRAW_ARROW #property indicator_width2 1 #property indicator_color2 0x2FFF00 #property indicator_label2 "LOW" //--- indicator buffers double Buffer1[]; double Buffer2[]; int i = 0; int j = 0; double myPoint; //initialized in OnInit void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | Pivot Point @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } else if(type == "order") { } else if(type == "modify") { } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(2); SetIndexBuffer(0, Buffer1); SetIndexEmptyValue(0, EMPTY_VALUE); SetIndexArrow(0, 67); SetIndexBuffer(1, Buffer2); SetIndexEmptyValue(1, EMPTY_VALUE); SetIndexArrow(1, 67); //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 3) { myPoint *= 10; } 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[]) { //--- main loop int HighCandle = iHighest(NULL,0,MODE_CLOSE,11,1); int LowCandle = iLowest(NULL,0,MODE_CLOSE,11,1); if(HighCandle == 6) { Buffer1[6] = Close[6]; }else if(LowCandle == 6) { Buffer2[6] = Close[6]; } return(rates_total); } //+------------------------------------------------------------------+ Enjoy d:)
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Lilyyyy Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/65983031 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. oh, I have found the answer la. #include <stdlib.mqh> #include <stderror.mqh> //--- indicator settings #property indicator_chart_window #property indicator_buffers 2 #property indicator_type1 DRAW_ARROW #property indicator_width1 1 #property indicator_color1 0x4800FF #property indicator_label1 "HIGH" #property indicator_type2 DRAW_ARROW #property indicator_width2 1 #property indicator_color2 0x2FFF00 #property indicator_label2 "LOW" //--- indicator buffers double Buffer1[]; double Buffer2[]; int i = 0; int j = 0; double myPoint; //initialized in OnInit void myAlert(string type, string message) { if(type == "print") Print(message); else if(type == "error") { Print(type+" | Pivot Point @ "+Symbol()+","+IntegerToString(Period())+" | "+message); } else if(type == "order") { } else if(type == "modify") { } } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(2); SetIndexBuffer(0, Buffer1); SetIndexEmptyValue(0, EMPTY_VALUE); SetIndexArrow(0, 67); SetIndexBuffer(1, Buffer2); SetIndexEmptyValue(1, EMPTY_VALUE); SetIndexArrow(1, 67); //initialize myPoint myPoint = Point(); if(Digits() == 5 || Digits() == 3) { myPoint *= 10; } 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[]) { //--- main loop int HighCandle = iHighest(NULL,0,MODE_CLOSE,11,1); int LowCandle = iLowest(NULL,0,MODE_CLOSE,11,1); if(HighCandle == 6) { Buffer1[6] = Close[6]; }else if(LowCandle == 6) { Buffer2[6] = Close[6]; } return(rates_total); } //+------------------------------------------------------------------+ Enjoy d:)

Cancel quote

Checking account access…