12/02/2026
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CheckForNewOrder();
CheckForPendingOrders();
}
//+------------------------------------------------------------------+
//| Check for new order and place market orders |
//+------------------------------------------------------------------+
void CheckForNewOrder()
{
// Check if there are any open positions
if(PositionSelect(_Symbol) == false)
{
// Get the current candle
double open = iOpen(_Symbol, PERIOD_CURRENT, 1);
double close = iClose(_Symbol, PERIOD_CURRENT, 1);
// Place market orders based on candle type
if(close > open) // Bullish candle
{
MarketBuyOrder();
}
else if(close < open) // Bearish candle
{
MarketSellOrder();
}
}
}
//+------------------------------------------------------------------+
//| Check for pending orders and place new ones |
//+------------------------------------------------------------------+
void CheckForPendingOrders()
{
// Check if there are any open positions
if(PositionSelect(_Symbol))
{
// Get the position type
long positionType = PositionGetInteger(POSITION_TYPE);
// Get the position open price