Color Candle EA

Profit factor:
0.65
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Indicator of the average true rangeParabolic Stop and Reverse system
6 Views
0 Downloads
0 Favorites
Color Candle EA
//+----------------------------------------------------------+
//| 4/8/2007 preBar.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+----------------------------------------------------------+
int MAGICMA=20070705; 

extern double Lots = 0.1;
extern double MaximumRisk = 0.03;
extern double stopFactor = 1;
extern double TakeProfit1 = 150;
extern double Stoploss1 = 140;
extern bool takeProfit = true;
extern bool sartrail = false;
extern bool MoneyManagement = false;
//+----------------------------------------------------------+
//| Calculate open positions |
//+----------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{

int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; 

if(OrderSymbol()==symbol && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
} 

double LotsOptimized()
{
//---- select lot size
int lot;
lot = NormalizeDouble( (AccountFreeMargin()*MaximumRisk)/( 
iATR(NULL,0,20,0)*(1/Point) )*0.1,1); 

//---- return lot size
if(lot<0.1) lot=0.1;
return(lot);
}
//+----------------------------------------------------------+
//| Check for open order conditions |
//+----------------------------------------------------------+
void CheckForOpen()
{

if(!NewBar())
return;
int res;
if(MoneyManagement)
Lots = LotsOptimized(); 

double close1 = Close[1];
double open1 = Open[1];

if ( close1< open1 )
{
openSell();
return;
}

//---- buy conditions
if ( close1> open1 )
{
openBuy();

return;
}

//----
}

void openBuy(){
Stoploss1 = stopFactor * iATR(NULL,0,20,0)+ MarketInfo (Symbol(), 
MODE_SPREAD) * Point;
int res;
if(takeProfit)

res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss1,Ask+TakeProfit1*Point 
,"preBar",MAGICMA,0,Blue);
else

res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss1,0,"preBar",MAGICMA,0, 
Blue);
if(res>0)
{
if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
Comment("preBar opened buy order " + Ask);
}
else Print("Error opening SELL order : ",GetLastError());

}

void openSell(){
Stoploss1 = stopFactor * iATR(NULL,0,20,0)+ MarketInfo (Symbol(), 
MODE_SPREAD) * Point;
int res;
if(takeProfit)

res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss1,Bid-TakeProfit1*Point,"preBar",MAGICMA,0,Red);
else

res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss1,0,"preBar",MAGICMA,0 ,Red);
if(res>0)
{
if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
Comment("preBar opened sell order " + Bid);
}
else Print("Error opening SELL order : ",GetLastError());

}

//+----------------------------------------------------------+
//| Check for close order conditions |
//+----------------------------------------------------------+
void CheckForClose()
{ 

//----
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
if(!takeProfit && NewBar() && Open[1]> Close[1])
{ OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
openSell();
}
// should it be closed?
// Function version check Sell condition to exit Buy

// check for trailing stop
if ( sartrail && (iSAR(NULL,0,0.02,0.2,1) > OrderStopLoss()) && 
(Bid > iSAR(NULL,0,0.02,0.2,1)) && (OrderOpenPrice() < 
iSAR(NULL,0,0.02,0.2,1)) && (iSAR(NULL,0,0.02,0.2,1) > 
iSAR(NULL,0,0.02,0.2,2)))
{

OrderModify(OrderTicket(),OrderOpenPrice(),iSAR(NULL,0,0.02,0.2,1),OrderTakeProfit(),0,Blue);
Print("Order # ",OrderTicket()," updated at ",Hour(),":",Minute(),":",Seconds());
return(0);
}

}
if(OrderType()==OP_SELL)
{
if(!takeProfit && NewBar() && Open[1]< Close[1])
{ OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
openBuy();
}

// should it be closed?
// Function version check Buy condition to exit Sell

if (sartrail && (iSAR(NULL,0,0.02,0.2,1) < OrderStopLoss()) && (Ask < 
iSAR(NULL,0,0.02,0.2,1)) && (OrderOpenPrice() > iSAR(NULL,0,0.02,0.2,1)) && 
(iSAR(NULL,0,0.02,0.2,1) < iSAR(NULL,0,0.02,0.2,2)))
{

OrderModify(OrderTicket(),OrderOpenPrice(),iSAR(NULL,0,0.02,0.2,1),OrderTakeProfit(),0,Blue);
Print("Order # ",OrderTicket()," updated at ",Hour(),":",Minute(),":",Seconds());
return(0);
}

}
}
}
return(0);
}
// the end.
//----
//+----------------------------------------------------------+
//| Start function |
//+----------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return; 

//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();
//----
}
//+----------------------------------------------------------
bool NewBar()
{
static datetime lastbar;
datetime curbar = Time[0];
if(lastbar!=curbar){
lastbar=curbar;
return (true);
} else
{ return(false); }
} 

Profitability Reports

NZD/USD Jul 2025 - Sep 2025
0.65
Total Trades 446
Won Trades 120
Lost trades 326
Win Rate 26.91 %
Expected payoff -2.16
Gross Profit 1800.00
Gross Loss -2763.60
Total Net Profit -963.60
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.72
Total Trades 730
Won Trades 283
Lost trades 447
Win Rate 38.77 %
Expected payoff -2.30
Gross Profit 4245.00
Gross Loss -5924.20
Total Net Profit -1679.20
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.21
Total Trades 539
Won Trades 144
Lost trades 395
Win Rate 26.72 %
Expected payoff -11.07
Gross Profit 1542.58
Gross Loss -7507.81
Total Net Profit -5965.23
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.52
Total Trades 907
Won Trades 373
Lost trades 534
Win Rate 41.12 %
Expected payoff -3.71
Gross Profit 3631.69
Gross Loss -6996.27
Total Net Profit -3364.58
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.90
Total Trades 798
Won Trades 315
Lost trades 483
Win Rate 39.47 %
Expected payoff -0.66
Gross Profit 4712.50
Gross Loss -5240.10
Total Net Profit -527.60
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.73
Total Trades 470
Won Trades 131
Lost trades 339
Win Rate 27.87 %
Expected payoff -1.52
Gross Profit 1960.70
Gross Loss -2675.20
Total Net Profit -714.50
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.71
Total Trades 555
Won Trades 223
Lost trades 332
Win Rate 40.18 %
Expected payoff -1.77
Gross Profit 2378.15
Gross Loss -3357.88
Total Net Profit -979.73
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.64
Total Trades 356
Won Trades 130
Lost trades 226
Win Rate 36.52 %
Expected payoff -3.04
Gross Profit 1950.00
Gross Loss -3031.50
Total Net Profit -1081.50
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.74
Total Trades 677
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -2.41
Gross Profit 4635.00
Gross Loss -6269.40
Total Net Profit -1634.40
-100%
-50%
0%
50%
100%

Comments