Question about writing an EA. Can you advise where to find material on bar analysis from another timeframe? Perhaps there are standard functions? Or maybe there are already templates available so I don't have to write the code all over again?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Please help me to add a stop loss to your EA, I've tried everything, but it does not work.
-----------------------------------------+
//| Order_v_Day.mq4 |
//| Copyright © 2010, forex-grail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, forex-grail.ru"
#property link "forex-grail.ru"
double Lots = 0.01; // lot
extern int H = 0 ; // order placing hour
extern int SL = 0; // Stop Loss in pips.
extern int TP = 20; // TakeProfit in pips.
int Slippage = 2; // slippage
int Magic = 70111; // magic
int ticketsell, ticketbuy;
double bid, ask;
string com = "O&D";
int init()
{
return(0);
}
int deinit()
{
return(0);
}
bool isBullish(int shift, int tf = PERIOD_D1) { return(iClose(NULL, tf, shift) > iOpen(NULL, tf, shift)); }
bool isBearish(int shift, int tf = PERIOD_D1) { return(iClose(NULL, tf, shift) < iOpen(NULL, tf, shift)); }
int start()
{
int TotalNumber = 0;
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if (OrderMagicNumber() != Magic || OrderSymbol() != Symbol()) continue;
TotalNumber++;
}
if (TotalNumber == 0)
{
ticketsell = 0;
ticketbuy = 0;
}
if(Hour() == H && Minute() == 5 && TotalNumber == 0) // Order open time
{
if(isBearish(1)) // If a previous candle on D1 is "inter-bearish", then buy
{
RefreshRates();
double ask = NormalizeDouble(MarketInfo(Symbol(),MODE_ASK), Digits);
ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage,0,ask+TP*Point,com,Magic,0,Blue);
}
if (isBullish(1)) // If the previous candle is bullish on D1, then sell
{
RefreshRates();
double bid = NormalizeDouble(MarketInfo(Symbol(),MODE_BID), Digits);
OrderSend(Symbol(),OP_SELL,Lots,bid,Slippage,0,bid-TP*Point,com,Magic,0,Red);
}
}
return(0);
}
Upload the archive. I'll have a look at mine.
EURUSD5.csv file of 44.5 MB, compressed by EURUSD5.rar to 7.7 MB
http://files.mail.ru/E2FN87
EURUSD5.csv file of 44.5 MB has been resized by EURUSD5.rar to 7.7 MB
http://files.mail.ru/E2FN87
Instead of
ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage, 0, ask+TP*Point,com,Magic,0,Blue);
try
ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage,bid-SL* Point, ask+TP*Point,com,Magic,0,Blue);
=======================
And forticketsell, similarly
instead of zero: ask+SL* Point
Instead of
ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage, 0, ask+TP*Point,com,Magic,0,Blue);
try
ticketbuy = OrderSend(Symbol(),OP_BUY,Lots,ask,Slippage,bid-SL* Point, ask+TP*Point,com,Magic,0,Blue);
=======================
And forticketsell, similarly
instead of zero: ask+SL* Point
The meta trader writes:2011.10.02 13:34:37 2010.11.23 00:05 Order_v_Day_v_1.0 EURUSD,Daily: invalid stoploss for OrderSend function
In upload
(the predefined variables Ask & Bid are capitalised)
On download
It's a CSV!!! It needs to be converted to HST to be visible on the chart. Use the import in the quote archive.
Import does not convert anything, and export does not export a format such as HST