I have a code in tradingview Pinescript and need it converting to mql4

MQL5 In conversione

Lavoro terminato

Tempo di esecuzione 225 giorni

Specifiche

here is the script its small

//@version=5
strategy("US500 Trading Strategy", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=1000)

// Input parameters
sma14 = ta.sma(close, 14)
sma50 = ta.sma(close, 50)
sma100 = ta.sma(close, 100)

// Function to check if SMA100 is in a distinct trend
isDistinctTrend(len) =>
    uptrend = true
    downtrend = true
    for i = 0 to len - 1
        if sma100[i] <= sma100[i+1]
            uptrend := false
        if sma100[i] >= sma100[i+1]
            downtrend :=//@version=5
 false
    [uptrend, downtrend]

[distinctUptrend, distinctDowntrend] = isDistinctTrend(10)

// Fibonacci levels
high_12h = ta.highest(high, 720)
low_12h = ta.lowest(low, 720)
fib_range = high_12h - low_12h
upper_15_percent = high_12h - fib_range * 0.15
lower_15_percent = low_12h + fib_range * 0.15

// Check if price is within top or bottom 15% of Fibonacci range
inFibZone = close > upper_15_percent or close < lower_15_percent

// New high/low condition
newHigh = ta.highest(high, 60) == high
newLow = ta.lowest(low, 60) == low
retraceAfterHigh = newHigh and high - low < 4
retraceAfterLow = newLow and high - low < 4

// Flat range condition
flatRange = math.abs(sma100 - sma50) < 4 and math.abs(ta.change(sma100)) < 0.1 and math.abs(ta.change(sma50)) < 0.1

// Entry conditions
longCondition = ta.crossover(sma14, sma50) and distinctUptrend and not inFibZone and not retraceAfterHigh and not flatRange
shortCondition = ta.crossunder(sma14, sma50) and distinctDowntrend and not inFibZone and not retraceAfterLow and not flatRange

// Override condition
longOverride = flatRange and close > sma100 and close > sma14
shortOverride = flatRange and close < sma100 and close < sma14

// Calculate position size
position_size = math.round(strategy.equity * 0.01)

// PineConnector Inputs
PC_ID = input.string("7531755372757", title = "ID Pineconnector",  group="PineConnector")
inputsym = input.string("US500", title = "Ticker", group="PineConnector")
PC_RISK = input.float(1, "Risk Contracts/Equity", group="PineConnector")
PC_LIMIT = input.bool(true, "Use Market Order", group="PineConnector")
PC_LIMIT_PIPS = input.float(5, "Lots Limit Order Distance", group="PineConnector")

// Execute trades
if longCondition or longOverride
    strategy.entry("Long", strategy.long, qty=position_size, alert_message = str.tostring(PC_ID)+',buy,'+inputsym+ ',risk='+str.tostring(PC_RISK))

if shortCondition or shortOverride
    strategy.entry("Short", strategy.short, qty=position_size,alert_message = str.tostring(PC_ID)+',sell,'+inputsym+ ',risk='+str.tostring(PC_RISK))

// Stop loss and take profit management
strategy.exit("Long SL/TP", "Long", stop=strategy.position_avg_price * 0.9825, trail_points=100, trail_offset=35, alert_message =str.tostring(PC_ID)+',closelong,'+inputsym)
strategy.exit("Short SL/TP", "Short", stop=strategy.position_avg_price * 1.0175, trail_points=100, trail_offset=35, alert_message = str.tostring(PC_ID)+',closeshort,'+inputsym)

// Plot SMAs
plot(sma14, color=color.blue, title="SMA 14")
plot(sma50, color=color.red, title="SMA 50")
plot(sma100, color=color.green, title="SMA 100")


Con risposta

1
Sviluppatore 1
Valutazioni
(102)
Progetti
105
60%
Arbitraggio
0
In ritardo
0
Gratuito
2
Sviluppatore 2
Valutazioni
(20)
Progetti
32
9%
Arbitraggio
0
In ritardo
0
Gratuito
3
Sviluppatore 3
Valutazioni
(77)
Progetti
240
73%
Arbitraggio
7
100% / 0%
In ritardo
1
0%
Gratuito
4
Sviluppatore 4
Valutazioni
(183)
Progetti
314
24%
Arbitraggio
23
35% / 13%
In ritardo
24
8%
Gratuito
Pubblicati: 3 codici
5
Sviluppatore 5
Valutazioni
(104)
Progetti
134
43%
Arbitraggio
0
In ritardo
3
2%
In elaborazione
6
Sviluppatore 6
Valutazioni
(132)
Progetti
178
39%
Arbitraggio
4
25% / 50%
In ritardo
14
8%
Gratuito
7
Sviluppatore 7
Valutazioni
(2)
Progetti
3
0%
Arbitraggio
8
13% / 88%
In ritardo
1
33%
Gratuito
8
Sviluppatore 8
Valutazioni
(10)
Progetti
6
33%
Arbitraggio
6
0% / 67%
In ritardo
1
17%
In elaborazione

Informazioni sul progetto

Budget
40+ USD
Scadenze
a 1 giorno(i)