MACD Coding Error
Forums › ProRealTime English forum › ProOrder support › MACD Coding Error
- This topic has 6 replies, 3 voices, and was last updated 1 year ago by Nicolas.
-
-
05/10/2023 at 8:08 PM #214480
Hi
Hoping somebody might be able to assist please to check code as I’m getting an error message for my MACD calculation.
The variables and code are as follows
fastLength = 12
slowLength = 26
signalLength = 9
emaLength = 200
stopLossPercentage = 1 // Stop loss percentage
takeProfitPercentage = 2 // Take profit percentage
useRiskRewardRatio = 1 // Use risk/reward ratio
riskRewardRatio = 2 // Risk/reward ratio// Calculate MACD
[macdLine, signalLine, _] = MACD[close, fastLength, slowLength, signalLength]the error message says Characters missing. Suggesstions: end of code
I have changed the parenthesis to brackets and taken the close out of the main string and added to the end in brackets but this hasn’t worked.
Appreciate any assistance
Thanks in advance
05/10/2023 at 8:30 PM #21448105/10/2023 at 10:23 PM #214483Thank you for checking and amending that code. Error resolved. Much appreciated.
05/10/2023 at 10:55 PM #214484Hi, I seem to be getting some further errors for the strategy for the buy & sell signals and notifications. The strategy is as follows:-
A buy signal is generated when the MACD crosses up over the MACD Signal line and the signal line and MACD are below the Zero line, and price closes above the 200 Exponential Moving Average. An email notification is to be generated when the condition is met and an alert is to appear on the chart.
A sell signal is generated when the MACD crosses under the MACD signal line and the signal line and MACD are above the MACD Zero line, and price closes below the 200 EMA. An email notification is to be generated when the condition is met and an alert is to appear on the chart.
A stop loss for a buy signal is based on the most recent swing low and/or the 200 period Exponential Moving Average whichever is nearest the price when the trade is taken.
A stop loss for a sell signal is based on the most recent swing high and/or the 200 period Exponential Moving average whichever is nearest the price when the trade is taken.
Take Profit can be option 1 an adjustable Risk/Reward ratio (Trailing Stop loss to be at 0) and option 2 an adjustable Trailing Stop loss percentage (risk /reward ratio to be at 0).
My code is as follows:-
fastLength = 12
slowLength = 26
signalLength = 9
emaLength = 200
stopLossPercentage = 1 // Stop loss percentage
takeProfitPercentage = 2 // Take profit percentage
useRiskRewardRatio = 1 // Use risk/reward ratio
riskRewardRatio = 2 // Risk/reward ratio// Calculate MACD
MyMACD = MACDline[fastLength, slowLength, signalLength](close)// Calculate 200 EMA
ema200 = average[close, emaLength]// Generate buy signal
buySignal = crossOver(macdLine, signalLine) and macdLine < 0 and signalLine < 0 and close > ema200// Generate sell signal
sellSignal = crossUnder(macdLine, signalLine) and macdLine > 0 and signalLine > 0 and close < ema200// Generate alerts and email notifications
if buySignal then
alert(“Buy Signal”)
sendmail(“Buy Signal”, “A buy signal has been generated.”)if sellSignal then
alert(“Sell Signal”)
sendmail(“Sell Signal”, “A sell signal has been generated.”)// Calculate stop loss for buy signal
buyStopLoss = close – (close * stopLossPercentage / 100)// Calculate stop loss for sell signal
sellStopLoss = close + (close * stopLossPercentage / 100)// Calculate take profit levels
if useRiskRewardRatio then
buyTakeProfit = close + (close – buyStopLoss) * riskRewardRatio
sellTakeProfit = close – (sellStopLoss – close) * riskRewardRatio
else
buyTakeProfit = close + (close * takeProfitPercentage / 100)
sellTakeProfit = close – (close * takeProfitPercentage / 100)// Place trades
if buySignal then
buy at close stoploss buyStopLoss takeprofit buyTakeProfitif sellSignal then
sell at close stoploss sellStopLoss takeprofit sellTakeProfit05/11/2023 at 9:24 AM #214501Here is on error that is repeated twice
1sellSignal = crossUnder(macdLine, signalLine) and macdLine > 0 and signalLine > 0 and close < ema200- Should be Crosses Under (same for Crosses Over).
- What Indicator is crossing under / Crosses Under?
05/11/2023 at 9:25 AM #214502Alert and sendmail are not allowed in ProOrder code.
1234567if buySignal thenalert("Buy Signal")sendmail("Buy Signal", "A buy signal has been generated.")if sellSignal thenalert("Sell Signal")sendmail("Sell Signal", "A sell signal has been generated.")05/11/2023 at 9:37 AM #214505 -
AuthorPosts
Find exclusive trading pro-tools on