EA does not take trades based on requirements

Taariq Gamieldien
11
Taariq Gamieldien  

Hi guys hopefully someone can help. I have an EA that should take trades at a certain time of the day and based on a bullish or bearish candlestick but it does not execute anything and there are no errors. 


This is how my code looks:


input string TP = "Make sure its not zero and over a certain amount otherwise it will not work";

extern int TakeProfitForSell = 50;

extern int TakeProfitForBuy = 50;

input string SL = "Make sure its not zero and over a certain amount otherwise it will not work";

extern int StopLossForSell = 150;

extern int StopLossForBuy = 150;


double BuyBullish = Open[0]<Close[0];

double SellBearish = Open[0]>Close[0];




void OnTick()

  {




double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //get the ask price

double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //get the bid price

datetime time = TimeLocal(); //get the local time

string hoursAndMinutes = TimeToString(time,TIME_MINUTES); //format the time and create a string

Comment (hoursAndMinutes); //writes text in the corner






//----------------------------Buy------------------------------//

//buy trade if substring equals to the specified time in this format "00:00" and bullish candle

if (StringSubstr(hoursAndMinutes,0,5)=="04:28" && BuyBullish)

{


Alert("bullish so a buy order was executed"); //Shows a pop up message

   

   OrderSend

    (

    Symbol(), //Currency pair

    OP_BUY, //open buy position

    0.01, //Lot size

    Ask, //buying price

    3, //Slippage

    Ask-StopLossForBuy*_Point, //Stop loss

    Ask+TakeProfitForBuy*_Point, //Take profit

    NULL, //Comment

    Blue //arrow colour

    );

    }


//----------------------------------------------------------------------//

  

  

  

  

  

  

  

//----------------------------Sell------------------------------//

//sell trade if substring equals to the specified time in this format "00:00" and bearish candle

else if (StringSubstr(hoursAndMinutes,0,5)=="04:28" && SellBearish)

{


Alert("bearish so a sell order was executed"); //Shows a pop up message

   

   OrderSend

    (

    Symbol(), //Currency pair

    OP_SELL, //open buy position

    0.01, //Lot size

    Bid, //buying price

    3, //Slippage

    Bid-StopLossForSell*_Point, //Stop loss

    Bid+TakeProfitForSell*_Point, //Take profit

    NULL, //Comment

    Red //arrow colour

    );

    }


//----------------------------------------------------------------------// 

  

  }



   

   

Keith Watford
Moderator
28022
Keith Watford  
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.

Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.