Specification
Looking for someone to examine and correct a pine script and convert into MQL4 script to perform the following functions as a robot & also an indicator for both Pine Script & MQL.
The robot needs to:
Determine total available balance for trading.
Useable on all trading timeframes (5min, 15min, 1Hr, 4Hr, Daily, Weekly) charts & Forex Pairs
Enter a Buy order of 10% of total available equity when 100 EMA crosses under 200 EMA (close of bar).
Enter a Sell order of 10% of total available equity when 100 EMA crosses over 200 EMA (close of bar).
(Example: $10,000 cash deposit on a 1:10 ratio account = $100,000 available including margin; trades = each trade uses 10% of $100,000 to each trade and no more than 50% of total margin or 5 trades open at one time reserving 50% of margin for drawdown.)
Ability to turn off either the Buy or the Sell so robot only performs Buy or the Sell trades leaving it up to the trader to include or exclude one or the other.
No more than 5 trades can be open at one time.
Trades opens at cross.
Long take profit @ .4 percent of price.
Stop loss @ .5 percent of price
Plots both the 100 (color:red) & 200 (color:white) EMA's
Plots trade entry & exit with arrows. (red for Sell, green for Buy)
Ability to adjust parameters like the Take Profit & Stop Loss %'s & pyramid amount.
Audible alert of trade entry & exit.
Here's the Pine Script I have thus far (Please make any changes to meet the needs described above):
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ForexDestiny
//@version=3
strategy(title="Take profit (% of instrument price)", calc_on_order_fills=true,calc_on_every_tick =true, initial_capital=100000,commission_value=.05,overlay=true,pyramiding=5, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
StartYear = input(2021, "Backtest Start Year")
StartMonth = input(1, "Backtest Start Month")
StartDay = input(1, "Backtest Start Day")
// STEP 1:
// Make inputs that set the take profit % (optional)
longProfitPerc = input(title="Long Take Profit (%)",
type=float, minval=0.0, step=0.1, defval=1) * 0.01
shortProfitPerc = input(title="Short Take Profit (%)",
type=float, minval=0.0, step=0.1, defval=1) * 0.01
longLossPerc = input(title="Long Stop Loss (%)",
type=float, minval=0.0, step=0.1, defval=5) * 0.01
// Calculate moving averages
EMA100 = ema(close, 100)
EMA200 = ema(close, 200)
// Calculate trading conditions
enterLong = crossunder(EMA100, EMA200)
enterShort = crossover(EMA100, EMA200)
// Plot moving averages
plot(series=EMA100, color=teal)
plot(series=EMA200, color=orange)
// STEP 2:
// Figure out take profit price
longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)
// Determine Stop Loss price
longStopPrice = strategy.position_avg_price * (1 - longLossPerc)
// Plot take profit values for confirmation
plot(series=(strategy.position_size > 0) ? longExitPrice : na,
color=green, style=circles,
linewidth=3, title="Long Take Profit")
plot(series=(strategy.position_size < 0) ? shortExitPrice : na,
color=red, style=circles,
linewidth=3, title="Short Take Profit")
// Plot stop loss values for confirmation
plot(series=(strategy.position_size > 0) ? longStopPrice : na,
color=red, style=cross,
linewidth=2, title="Long Stop Loss")
// Submit entry orders
if (enterLong)
strategy.entry(id="EL", long=true)
// STEP 3:
// Submit exit orders based on take profit price
if (strategy.position_size > 0)
strategy.exit(id="XL TP", limit=longExitPrice)
// Submit exit orders based on calculated stop loss price
if (strategy.position_size > 0)
strategy.exit(id="XL STP", stop=longStopPrice)