Hi, I have written this simple strategy and I would like to convert this to mql4 so I can run it on my mt4.
Any kind souls able to help me with it? Or is there a way to help automate this strategy, I have been googling and trying all sorts of stuffs but to no avail. I tried coding it on mql4 but it failed, the language is too hard for me.
// Script
//version=4
// Author: Soon Meng Yao
strategy("200EMA Scalp", overlay=true, default_qty_value=1000, slippage = 00)
ema20 = ema(close, 20)
ema50 = ema(close, 50) //for display
ema200 = ema(close, 200) //for display
plot(ema20, title="20", color=#0000FF, linewidth=1)
plot(ema50, title="50", color=#FF0000, linewidth=1)
plot(ema200, title="200", color=#800080, linewidth=1)
//Strategy Testing
//Variables
precHighAboveEMA = (high[1] >= ema200)
prevClose2AboveEMA = (close[2] >= ema200)
prevLowBelowEMA = (low[1] <= ema200)
prevClose2BelowEMA = (close[2] <= ema200)
//LONG WHEN -
//2 Candles before close above EMA
//Previous Low below EMA
// Current Close above EMA
currentCloseAboveEMA = (close[0] > ema200)
longcondition = prevLowBelowEMA and prevClose2AboveEMA and currentCloseAboveEMA
// SELL WHEN -
//2 Candles before close below EMA
//Previous High above EMA
// Current Close Below EMA
currentCloseBelowEMA = (close[0] < ema200)
shortcondition = precHighAboveEMA and prevClose2BelowEMA and currentCloseBelowEMA
TakeProfit = input(defval = 60, title = "Take Profit", minval = 0)
StopLoss = input(defval = 30, title = "Stop Loss", minval = 0)
TrailStop = input(defval = 5, title = "Trailing Stop Loss", minval = 0)
strategy.entry("Long", strategy.long, when = longcondition)
strategy.exit("Exit Long", "Long", profit = TakeProfit, loss = StopLoss, trail_points = TrailStop)
strategy.entry("Short", strategy.short, when = shortcondition)
strategy.exit("Exit Short", "Short", profit = TakeProfit, loss = StopLoss, trail_points = TrailStop)
Any kind souls able to help me with it? Or is there a way to help automate this strategy, I have been googling and trying all sorts of stuffs but to no avail. I tried coding it on mql4 but it failed, the language is too hard for me.
// Script
//version=4
// Author: Soon Meng Yao
strategy("200EMA Scalp", overlay=true, default_qty_value=1000, slippage = 00)
ema20 = ema(close, 20)
ema50 = ema(close, 50) //for display
ema200 = ema(close, 200) //for display
plot(ema20, title="20", color=#0000FF, linewidth=1)
plot(ema50, title="50", color=#FF0000, linewidth=1)
plot(ema200, title="200", color=#800080, linewidth=1)
//Strategy Testing
//Variables
precHighAboveEMA = (high[1] >= ema200)
prevClose2AboveEMA = (close[2] >= ema200)
prevLowBelowEMA = (low[1] <= ema200)
prevClose2BelowEMA = (close[2] <= ema200)
//LONG WHEN -
//2 Candles before close above EMA
//Previous Low below EMA
// Current Close above EMA
currentCloseAboveEMA = (close[0] > ema200)
longcondition = prevLowBelowEMA and prevClose2AboveEMA and currentCloseAboveEMA
// SELL WHEN -
//2 Candles before close below EMA
//Previous High above EMA
// Current Close Below EMA
currentCloseBelowEMA = (close[0] < ema200)
shortcondition = precHighAboveEMA and prevClose2BelowEMA and currentCloseBelowEMA
TakeProfit = input(defval = 60, title = "Take Profit", minval = 0)
StopLoss = input(defval = 30, title = "Stop Loss", minval = 0)
TrailStop = input(defval = 5, title = "Trailing Stop Loss", minval = 0)
strategy.entry("Long", strategy.long, when = longcondition)
strategy.exit("Exit Long", "Long", profit = TakeProfit, loss = StopLoss, trail_points = TrailStop)
strategy.entry("Short", strategy.short, when = shortcondition)
strategy.exit("Exit Short", "Short", profit = TakeProfit, loss = StopLoss, trail_points = TrailStop)
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.