Hello.
This EA open a position by the size of the candle, if I set 25.0 pips, open a position when the candle reach that 25.0 pips but I dont need that, what I need is that the EA open a position at the close of the candle if the 25.0 pips or more are reached, but at the closed not before.
PLease help me
This EA open a position by the size of the candle, if I set 25.0 pips, open a position when the candle reach that 25.0 pips but I dont need that, what I need is that the EA open a position at the close of the candle if the 25.0 pips or more are reached, but at the closed not before.
PLease help me
Inserted Code
//---User Setting Variable
extern double trigger = 0.0010;
extern double stopLoss = 0.0010;
extern double takeProfit = 0.0010;
extern double percentPerTrade = 0.01;
extern int tradeStartTimeMT4 = 0;
extern int tradeEndTimeMT4 = 23;
//---Variables
double currentPrice = 0.00000;
static datetime barStart;
string openTrades = "none";
int ticket;
double lotSize;
string permit = "suspended";
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start(){
currentPrice = iClose(NULL,0,0);
Comment("Price Continuation\n",
"Status: ",status()
);
//----Trade Algorithm
//trade hours value...
if(tradeStartTimeMT4 <= Hour() && Hour() <= tradeEndTimeMT4){
if(openTrades == "none" && permit == "approved"){
requestLongOrder();
requestShortOrder();
}
else{
requestPermit();
}
}
if(openTrades == "long"){
manageLongTrade();
}
if(openTrades == "short"){
manageShortTrade();
}
return(0);
}
//---FUNCTIONS---
string status(){
string status = "Status not reported.. check system for errors";
if(openTrades == "none"){
status = "Waiting for trade";
}
else if(openTrades == "long"){
status = "Trade is Active LONG";
}
else if(openTrades == "short"){
status = "Trade is Active SHORT";
}
else{
status = "System Malfunction!";
}
return(status);
}
//calculation for the lot size...
double lotSizeCalc(double x){
double lotSize = (AccountBalance() * percentPerTrade / x / 10);
return(lotSize);
}
//--
void requestLongOrder(){
if(Open[0]-Close[0] >= trigger){
//--
lotSize = lotSizeCalc(stopLoss*10000);
ticket = OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,currentPrice-stopLoss,currentPrice+takeProfit,"My order ",06010,0,Green);
if(ticket<0){
//add email/sms alert here with GetLastError();
}
if(ticket>0){
openTrades = "long";
permit = "suspended";
}
}
}
void requestShortOrder(){
if(Open[0]-Close[0] >= trigger){
//--
lotSize = lotSizeCalc(stopLoss*10000);
ticket = OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,currentPrice+stopLoss,currentPrice-takeProfit,"My order ",06010,0,Green);
if(ticket<0){
//add email/sms alert here with GetLastError();
}
if(ticket>0){
openTrades = "short";
permit = "suspended";
}
}
}
void manageLongTrade(){
OrderSelect(ticket, SELECT_BY_TICKET);
if(OrderCloseTime() != 0){
openTrades = "none";
}
}
void manageShortTrade(){
OrderSelect(ticket, SELECT_BY_TICKET);
if(OrderCloseTime() != 0){
openTrades = "none";
}
}
void requestPermit(){
if(Minute() == 00){
permit = "approved";
}
else{
permit = "suspended";
}
}
//+------------------------------------------------------------------+