//--------------------------------------------------------------------------------------- // The Collective FX LLC // www.thecollectivefx.com // "A Boutique Brokerage With Institutional Level Pricing For AutoTraders By Autotraders" // // 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-------------------------------------