Question
//+------------------------------------------------------------------+ //| RoyalCakeTrading | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright Copyright 2023, MetaQuotes Ltd. #property link https://www.mql5.com #property version
//+------------------------------------------------------------------+ //| RoyalCakeTrading | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00"
// Indicator Inputs input int ema_period = 9; input int smma_period_1 = 21; input int smma_period_2 = 50; input int ema_period_long = 200;
// Strategy Inputs input bool trading_enabled = true; input int stop_loss = 40; input int short_stop_loss = 35; input int take_profit = 50; input int trailing_stop_loss = 40;
// Strategy Variables bool long_entry = false; double long_stop_price = 0.0; double range_start = 0.0; bool short_entry = false; double short_stop_price = 0.0;
// Initialize the indicators int OnInit() { return(INIT_SUCCEEDED); }
// Enter and exit trades on each tick void onTick() { double ema_9 = iMA (_Symbol, Period(), ema_period, 0, MODE_EMA, PRICE_CLOSE); double smma_21 = iMA(_Symbol, PERIOD_CURRENT, smma_period_1, 0, MODE_SMA, PRICE_CLOSE); double smma_50 = iMA(_Symbol, PERIOD_CURRENT, smma_period_2, 0, MODE_SMA, PRICE_CLOSE); double ema_200 = iMA(_Symbol, PERIOD_CURRENT, ema_period_long, 0, MODE_EMA, PRICE_CLOSE);
if(trading_enabled) { double high_15min = iHigh(_Symbol, PERIOD_M15, 1); double low_15min = iLow(_Symbol, PERIOD_M15, 1); double close_15min = iClose(_Symbol, PERIOD_M15, 1); double high_5min = iHigh(_Symbol, PERIOD_M5, 1); double low_5min = iLow(_Symbol, PERIOD_M5, 1); double close_5min = iClose(_Symbol, PERIOD_M5, 1); double high_1min = iHigh(_Symbol, PERIOD_M1, 1); double low_1min = iLow(_Symbol, PERIOD_M1, 1); double close_1min = iClose(_Symbol, PERIOD_M1, 1);
// Enter the long position if conditions are met if(close_1min < ema_9 && close_1min > ema_9 && smma_21 > smma_50 && smma_50 > ema_200 && !long_entry) { if(high_15min > ema_9 && low_15min > ema_9 && close_15min > smma_21) { if(high_5min > ema_9 && low_5min > ema_9 && close_5min > smma_21) { if(high_1min > ema_9 && low_1min > ema_9 && close_1min > smma_21) { long_entry = true; long_stop_price = low - stop_loss * _Point; OrderSend(_Symbol, OP_BUY, 0.1, Ask, 3, long_stop_price, Ask + take_profit * _Point, "Long Trade", MagicNumber, 0, Blue); } } } }
// Exit the long position if stop loss or take profit is hit if(long_entry) { double long_trade_profit = (Ask - long_stop_price) / _Point; if(long_trade_profit >= take_profit) { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Blue); long_entry = false; } else if(long_trade_profit <= -stop_loss) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red); long_entry = false; } else if(trailing_stop_loss > 0) { if(long_stop_price < Bid - trailing_stop_loss * _Point) { long_stop_price = Bid - trailing_stop_loss * _Point; OrderModify(OrderTicket(), OrderLots(), long_stop_price, Ask + take_profit * _Point, 0, Blue); } } }
// Enter the short position if conditions are met if(close[1] > ema_9 && close < ema_9 && smma_21 < smma_50 && smma_50 < ema_200 && !short_entry) { if(low_15min < ema_9 && high_15min < ema_9 && close_15min < smma_21) { if(low_5min < ema_9 && high_5min < ema_9 && close_5min < smma_21) { if(low_1min < ema_9 && high_1min < ema_9 && close_1min < smma_21) { short_entry = true; short_stop_price = high + stop_loss * _Point; OrderSend(_Symbol, OP_SELL, 0.1, Bid, 3, short_stop_price, Bid - take_profit * _Point, "Short Trade", MagicNumber, 0, Red); } } } }
// Exit the short position if stop loss or take profit is hit if(short_entry) { double short_trade_profit = (short_stop_price - Bid) / _Point; if(short_trade_profit >= take_profit) { OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue); short_entry = false; } else if(short_trade_profit <= -short_stop_loss) { OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red); short_entry = false; } else if(trailing_stop_loss > 0) { if(short_stop_price > Ask + trailing_stop_loss * _Point) { short_stop_price = Ask + trailing_stop_loss * _Point; OrderModify(OrderTicket(), OrderLots(), short_stop_price, short_stop_price - stop_loss * _Point, 0, Blue); } } } } }
>>>>>>>>>>can you help me debug this please?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started