Error in my code

 

The EA is supposed to buy when the previous candle was bullish and sell if the previous candle was bearish.


input double takeProfitPips = 100; // Take Profit (in pips)

input double stopLossPips = 100; // Take Profit (in pips)

input double lot = 0.1;

datetime LastActionTime = 0;



//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---



   //---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---



  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTick()

  {

//---

       {

         // Check if the previous candle was bullish

         if (IsBullishCandle() == 1)

            {

               // open Buy order

               double sl = SymbolInfoDouble(_Symbol, SYMBOL_BID) - stopLossPips;

               double tp = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + takeProfitPips;

               ulong ticket = OrderSend(ORDER_TYPE_BUY, lot, stopLossPips, takeProfitPips);

               if (ticket == -1)

                  {

                     Print("Buy Order failed with error #", GetLastError());

                  }

               else

                  Print("Buy Order placed successfully");

             }



         // Check if the previous candle was Bearish

         else if (IsBullishCandle() == 0)

            {

               // open Sell order

               double sl = SymbolInfoDouble(_Symbol, SYMBOL_ASK) + stopLossPips;

               double tp = SymbolInfoDouble(_Symbol, SYMBOL_BID) - takeProfitPips;

               ulong ticket = OrderSend(ORDER_TYPE_BUY, lot, stopLossPips, takeProfitPips);

               if (ticket == -1)

                  {

                     Print("Sell Order failed with error #", GetLastError());

                  }

               else

                  Print("Sell Order placed successfully");

             }



       }

  }

//+------------------------------------------------------------------+



Here's another code that's supposed to do the same thing: 



// External parameters

input int lastCandleNumber = 1; // Number of the previous candle to check



input double LotSize = 0.1; // Lots

input double StopLossPips = 100; // Stop Loss (in pips)

input double TakeProfitPips = 100; // Take Profit (in pips)



bool OrderSend(

   string          symbol,         // symbol

   int             cmd,            // operation type

   double          volume,         // volume

   double          price,          // price

   int             slippage,       // slippage

   double          stoploss,       // stop loss

   double          takeprofit,     // take profit

   string          comment=NULL,   // comment

   int             magic=0,        // magic number

   datetime        expiration=0,   // pending order expiration time

   color           arrow_color=clrNONE // color of the opening arrow on the chart

);





// Function to check the type of the last candle

#define LastCandleNB(int) (iClose(_Symbol,_Period,int)>=iOpen(_Symbol,_Period,int))?"BuyCandle":"SellCandle"



// The main EA logic

int OnStart()

{

    // Check the previous candle

    string candleType = LastCandleNB(lastCandleNumber);



    // Open Buy or Sell based on the previous candle

    if (candleType == "BuyCandle") {

        // Place your buy order logic here

        // For example: 

        OrderSend(Symbol(), ORDER_TYPE_BUY, LotSize, SymbolInfoDouble(Symbol(), SYMBOL_ASK), 3, SymbolInfoDouble(Symbol(), SYMBOL_ASK) - StopLossPips * _Point, SymbolInfoDouble(Symbol(), SYMBOL_ASK) + TakeProfitPips * _Point, "Buy Order", 0, 0, clrGreen);

    } else if (candleType == "SellCandle") {

        // Place your sell order logic here

        // For example: 

        OrderSend(Symbol(), ORDER_TYPE_SELL, LotSize, SymbolInfoDouble(Symbol(), SYMBOL_BID), 3, SymbolInfoDouble(Symbol(), SYMBOL_BID) + StopLossPips * _Point, SymbolInfoDouble(Symbol(), SYMBOL_BID) - TakeProfitPips * _Point, "Sell Order", 0, 0, clrRed);

    }

    else {

            // Handle the situation if OrderSend fails

        }



    return (0);

}





 
Teboho_Mosikidi:

The EA is supposed to buy when the previous candle was bullish and sell if the previous candle was bearish.

1. What's the error? Is it a compiler error or just not working as expected?

2. This is intended to be run manually, and only make one trade? Or you're trying to build an algorithm?