Forex



Go Back   Forex Trading > Programming > Metatrader Programming






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

 
 
Thread Tools
 
Old 05-28-2008, 03:10 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
matrixebiz is on a distinguished road
Is there code to check the spread?

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

Last edited by matrixebiz; 05-28-2008 at 03:25 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 05-28-2008, 03:28 PM
Kalenzo's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 718
Kalenzo is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
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
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);
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 05-28-2008, 03:32 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
matrixebiz is on a distinguished road
Quote:
Originally Posted by Kalenzo View Post
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 05-28-2008, 03:51 PM
Kalenzo's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 718
Kalenzo is on a distinguished road
You are welcome.
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-01-2009, 10:01 PM
Member
 
Join Date: Apr 2009
Posts: 50
4of7 is on a distinguished road
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-------------------------------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 

Bookmarks
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please check my first EA :) matrixebiz Expert Advisors - Metatrader 4 19 03-12-2008 01:55 PM
Check this out!!! tznef Non Related Discussions 15 12-17-2007 09:16 AM
How to check for check for currency symbol tak145 Expert Advisors - Metatrader 4 1 05-12-2007 02:16 PM
can anyone please help me to code a spread indicator? alexpio Metatrader 4 mql 4 - Development course 4 12-17-2006 05:05 PM
Can someone please check this indicator? iboersma Metatrader 4 2 04-17-2006 03:09 PM


All times are GMT. The time now is 02:28 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.