Hello, I want to add a filter in an EA that if it signals, to check the High/Low of the candle against the spread and if the candle is smaller than the currency spread then pass on the trade. The code below probably is wrong so if some knows what I'm talking about
![](https://c.mql5.com/forextsd/smiles/smile.png)
bool Filter1 = ((High[1]+Low[1]) < (Point + Spread));
ThanksHello !
It will be more like that:
bool tradeOrNot = false;
if((High[1] - Low[1])/Point)<MarketInfo(Symbol(),MODE_SPREAD)) tradeOrNot = true;
if(tradeOrNot) OrderSend(... and so on);
Hello !
It will be more like that:
bool tradeOrNot = false;
if((High[1] - Low[1])/Point)<MarketInfo(Symbol(),MODE_SPREAD)) tradeOrNot = true;
if(tradeOrNot) OrderSend(... and so on);Cool, I'll try it out, thanks
You are welcome.
ShowSpreads EA
I just created a simple EA to show the current spread on whatever chart it is applied to.
It also writes each tick's Symbol, Ask, Bid, Spread and timestamp to a text file in CSV format (this was the reason I made it, to collect price info). The plotting of the spreads on the charts was an after thought, but turns out to be quite useful.
Its very simple and thus you should understand from the code how the output file is named and where it is created.
Not sure of the protocol or etiquette of posting code, so if I've infringed any rules then please chastise me. However, don't poke fun at the coding
Thanks, 4of7.
//---------------------------------------------------------------------------------------
// Created by 4of7@thecollectivefx.com
//
// Home
//
// Simple EA to plot the spread of the current symbol on the chart and
// write that data to a "CSV" log file.
// V1.0
int init()
{
return(0);
}
int deinit()
{
return(0);
}
//-----------------------------------------------------------------------
// Start. This routine is called automatically by the platform every time
// a tick comes into the chart that the EA is applied to.
int start()
{
ProcessTicks(); // Call the main processing routine.
return(0);
}
//-----------------------------------------------------------------------
// Plot and save price information for every tick that arrives.
int ProcessTicks()
{
string SpreadString;
string LogString;
double Spread;
double AskPrice;
double BidPrice;
int TickLogFileHandle; // Handle for the file open function.
string TickLogFileName;// The file to write to.
AskPrice = MarketInfo(Symbol(), MODE_ASK); // Current ASK price for this CurrencyPair
BidPrice = MarketInfo(Symbol(), MODE_BID); // Current BID price for this CurrencyPair
//------------------------------------------
// Just in case this is applied to a Chart from a Broker
// that doesn't quote in fractional pips then ensure that we
// calculate the pip values correctly.
if (Point == 0.00001) // Calculate the spread in pips for symbols quoted to 5 decimal places
{
Spread = ((MarketInfo(Symbol(), MODE_ASK) - MarketInfo(Symbol(), MODE_BID)) / (Point*10)); // Current Spread price for this CurrencyPair in pip form.
}
if (Point == 0.0001) // Calculate the spread in pips for symbols quoted to 4 decimal places
{
Spread = ((MarketInfo(Symbol(), MODE_ASK) - MarketInfo(Symbol(), MODE_BID)) / (Point)); // Current Spread price for this CurrencyPair in pip form.
}
if (Point == 0.001) // Calculate the spread in pips for symbols quoted to 3 decimal places
{
Spread = ((MarketInfo(Symbol(), MODE_ASK) - MarketInfo(Symbol(), MODE_BID)) / (Point*10)); // Current Spread price for this CurrencyPair in pip form.
}
if (Point == 0.01) // Calculate the spread in pips for symbols quoted to 2 decimal places
{
Spread = ((MarketInfo(Symbol(), MODE_ASK) - MarketInfo(Symbol(), MODE_BID)) / (Point)); // Current Spread price for this CurrencyPair in pip form.
}
SpreadString = "\r" + "\n" + "Spread = " + DoubleToStr(Spread,2) + " pips"; // Create string to plot on the chart.
Comment(SpreadString); // Plot the spread on the current chart
LogString = Symbol() + "," +
AskPrice + "," +
BidPrice + "," +
DoubleToStr(Spread,2) + "," +
TickTimeStamp();
TickLogFileName = "\\" + Symbol() + ".ticks"; // Create the name of the log file.
TickLogFileHandle = FileOpen(TickLogFileName, FILE_CSV|FILE_READ|FILE_WRITE, ','); // Open the file.
FileSeek(TickLogFileHandle,0,SEEK_END); // Goto end of log file.
FileWrite(TickLogFileHandle, LogString); // Write the price data.
FileClose(TickLogFileHandle); // Close the file.
return(0);
}
//-----------------------------------------------------------------------
// Create a Timestamp string.
string TickTimeStamp()
{
string TimeStamp; // String to return.
TimeStamp = TimeMonth(TimeCurrent()) + "/" +
TimeDay(TimeCurrent()) + "/" +
TimeYear(TimeCurrent()) + " " +
TimeToStr(TimeCurrent(), TIME_SECONDS);
return(TimeStamp);
}
//-------------------------------END-------------------------------------
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I want to add a filter in an EA that if it signals, to check the High/Low of the candle against the spread and if the candle is smaller than the currency spread then pass on the trade. The code below probably is wrong so if some knows what I'm talking about
can you please give me the correct syntax.
bool Filter1 = ((High[1]+Low[1]) < (Point + Spread));
Thanks