aliasgari524: Hi guys, i want convert some pine Script indicator code to MQL4 but im beginner in MQL pls help me that is some code i want use it in MQL but i dont know how ... `
If you don't know how, then consider placing a job request in the Freelance section.
Trading applications for MetaTrader 5 to order
- 2022.12.26
- www.mql5.com
The largest freelance service with MQL5 application developers
aliasgari524:
Hi guys, i want convert some pine Script indicator code to MQL4 but im beginner in MQL pls help me that is some code i want use it in MQL but i dont know how ... `
Here you go
#property copyright "Copyright 2095, Galactic Outreach Division Corps." #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot p #property indicator_label1 "p" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 input int atr_period=50;//atr period //--- indicator buffers double p[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,p); //--- 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[]) { //--- int calcs=rates_total-prev_calculated; int from=calcs; if(calcs>atr_period){ from=rates_total-atr_period-6; } for(int i=from;i>=0;i--) { double T=Close[i]-Open[i]; double L=High[i]-Low[i]; double k=0.0; if(L>0.0){k=MathAbs(T)/(L);} double atr=iATR(_Symbol,_Period,atr_period,i); double s_div=(MathMin(Close[i],Open[i])-Low[i]); double s=0.0; if(s_div!=0.0){s=(High[i]-MathMax(Close[i],Open[i]))/s_div;} if(High[i+2]>High[i+1]&&High[i+2]>High[i]&&High[i+2]>High[i+3]&&High[i+2]>High[i+4]&&Close[i]<Open[i]&&Close[i+1]<Open[i+1]&&Close[i+3]>Open[i+3]&&Close[i+4]>Open[i+4]&&Low[i]<Low[i+4]){ p[i]=1000*(-1+High[i+2]/MathMin(Low[i+1],Low[i])); } else if(Low[i+2]<Low[i+1]&&Low[i+2]<Low[i]&&Low[i+2]<Low[i+3]&&Low[i+2]<Low[i+4]&&Close[i]>Open[i]&&Close[i+1]>Open[i+1]&&Close[i+3]<Open[i+3]&&Close[i+4]<Open[i+4]&&High[i]>High[i+4]){ p[i]=1000*(-1+Low[i+2]/MathMax(High[i+1],High[i])); } else{ p[i]=0.0; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- } //+------------------------------------------------------------------+
Hello ,Whats up :S can you help me to convert this pine script code to MQL4? :S pls
wicks = input(false, "Take Wicks into Account ?") highlightState = input(true, "Highlight State ?") ma(source, length, type) => type == "SMA" ? ta.sma(source, length) : type == "EMA" ? ta.ema(source, length) : type == "SMMA (RMA)" ? ta.rma(source, length) : type == "WMA" ? ta.wma(source, length) : type == "VWMA" ? ta.vwma(source, length) : na show_ma1 = input(true , "MA High", inline="MA #1", group="Channel №1") ma1_type = input.string("SMA" , "" , inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Channel №1") ma1_source = input(high , "" , inline="MA #1", group="Channel №1") ma1_length = input.int(200 , "" , inline="MA #1", minval=1, group="Channel №1") ma1_color = input(color.green, "" , inline="MA #1", group="Channel №1") ma1 = ma(ma1_source, ma1_length, ma1_type) show_ma2 = input(true , "MA Low", inline="MA #2", group="Channel №1") ma2_type = input.string("SMA" , "" , inline="MA #2", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Channel №1") ma2_source = input(low , "" , inline="MA #2", group="Channel №1") ma2_length = input.int(200 , "" , inline="MA #2", minval=1, group="Channel №1") ma2_color = input(color.red, "" , inline="MA #2", group="Channel №1") ma2 = ma(ma2_source, ma2_length, ma2_type) showLabels1 = input(true, "Show Buy/Sell Labels ?", group="Channel №1") showLabels2 = input(true, "Show Buy/Sell Labels ?", group="Channel №2") Hlv1 = float(na) Hlv1 := (wicks ? high : close) > ma1 ? 1 : (wicks ? low : close) < ma2 ? -1 : Hlv1[1] sslUp1 = Hlv1 < 0 ? ma2 : ma1 sslDown1 = Hlv1 < 0 ? ma1 : ma2 Color1 = Hlv1 == 1 ? ma1_color : ma2_color fillColor1 = highlightState ? (color.new(Color1, 90)) : na highLine1 = plot(show_ma1 ? sslUp1 : na, title="UP", linewidth=2, color = Color1) lowLine1 = plot(show_ma2 ? sslDown1 : na, title="DOWN", linewidth=2, color = Color1) plotshape(show_ma1 and showLabels1 and Hlv1 == 1 and Hlv1[1] == -1, title="Buy Label", text="Buy", location=location.belowbar, style=shape.labelup, size=size.tiny, color=Color1, textcolor=color.white) plotshape(show_ma2 and showLabels1 and Hlv1 == -1 and Hlv1[1] == 1, title="Sell Label", text="Sell", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=Color1, textcolor=color.white) fill(highLine1, lowLine1, color = fillColor1)
can you help me to convert this Pine Script code to MQL4?
this is a good strategy with 70+ win rate:
Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.
Hover your mouse over your post and select "edit" ... ![]()
Hello, please help me convert the RSI indicator from tradingview to mq4, thank you very much
Pine Script code on tradingview here:
//@version=5
indicator(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings", display = display.data_window)
maLengthInput = input.int(14, title="MA Length", group="MA Settings", display = display.data_window)
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings", display = display.data_window)
showDivergence = input.bool(false, title="Show Divergence", group="RSI Settings", display = display.data_window)
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"
rsiPlot = plot(rsi, "RSI", color=#7E57C2)
plot(rsiMA, "RSI-based MA", color=color.yellow)
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)
fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill")
midLinePlot = plot(50, color = na, editable = false, display = display.none)
fill(rsiPlot, midLinePlot, 100, 70, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100), title = "Overbought Gradient Fill")
fill(rsiPlot, midLinePlot, 30, 0, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill")
// Divergence
lookbackRight = 5
lookbackLeft = 5
rangeUpper = 60
rangeLower = 5
bearColor = color.red
bullColor = color.green
textColor = color.white
noneColor = color.new(color.white, 100)
plFound = na(ta.pivotlow(rsi, lookbackLeft, lookbackRight)) ? false : true
phFound = na(ta.pivothigh(rsi, lookbackLeft, lookbackRight)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
rangeLower <= bars and bars <= rangeUpper
//------------------------------------------------------------------------------
// Regular Bullish
// rsi: Higher Low
rsiHL = rsi[lookbackRight] > ta.valuewhen(plFound, rsi[lookbackRight], 1) and _inRange(plFound[1])
// Price: Lower Low
priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
bullCondAlert = priceLL and rsiHL and plFound
bullCond = showDivergence and bullCondAlert
plot(
plFound ? rsi[lookbackRight] : na,
offset=-lookbackRight,
title="Regular Bullish",
linewidth=2,
color=(bullCond ? bullColor : noneColor)
)
plotshape(
bullCond ? rsi[lookbackRight] : na,
offset=-lookbackRight,
title="Regular Bullish Label",
text=" Bull ",
style=shape.labelup,
location=location.absolute,
color=bullColor,
textcolor=textColor
)
//------------------------------------------------------------------------------
// Regular Bearish
// rsi: Lower High
rsiLH = rsi[lookbackRight] < ta.valuewhen(phFound, rsi[lookbackRight], 1) and _inRange(phFound[1])
// Price: Higher High
priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)
bearCondAlert = priceHH and rsiLH and phFound
bearCond = showDivergence and bearCondAlert
plot(
phFound ? rsi[lookbackRight] : na,
offset=-lookbackRight,
title="Regular Bearish",
linewidth=2,
color=(bearCond ? bearColor : noneColor)
)
plotshape(
bearCond ? rsi[lookbackRight] : na,
offset=-lookbackRight,
title="Regular Bearish Label",
text=" Bear ",
style=shape.labeldown,
location=location.absolute,
color=bearColor,
textcolor=textColor
)
alertcondition(bullCondAlert, title='Regular Bullish Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.")
alertcondition(bearCondAlert, title='Regular Bearish Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi guys, i want convert some pine Script indicator code to MQL4 but im beginner in MQL pls help me that is some code i want use it in MQL but i dont know how ... `