i keep getting error 130 on the journal and implicit conversion from number to string from compiler output i cant figure it out kindly assist guys
There is also the line number and the cursor position of where the error occurs.
- When providing code for review, please use the SRC button.
- Please provide a screenshot of your compiler errors.
Thank you.
- Jack
- When you post code please use the SRC button! Please edit your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum for(count=0;count<=OrdersHistoryTotal();count++) { OrderSelect (count, SELECT_BY_POS, MODE_HISTORY);
If there are N positions their index is [0..N-1] OrderSelect( OrdersHistoryTotal() ... ) will always fail. Check your return codes for errors and report them.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles-
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
int ticket = OrderSend(Symbol(), OP_BUY , 0.1, NormalizeDouble(ask,5), 3, NormalizeDouble(ask-StopLoss,5), NormalizeDouble(ask+TakeProfit,5), "", 0, TimeCurrent() + 300, Green); FileWrite(file_handle,"kula mavy"); if(TimeMinute(TimeCurrent())== TimeMinute(OrderOpenTime())+5){ OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(bid,5), 10, Blue);
You can not use any Trade Functions until you select an order.-
You buy at the Ask and sell at the Bid.
- Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
-
Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at
a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3 - The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)
- After Sleep and between server calls the market will have changed, you must update your variables. To use any pre-defined variables
and series arrays you must call RefreshRates
RefreshRates - Timeseries and Indicators Access - MQL4 Reference - Use the debugger or print out your variables, including _LastError and find out why.
Fix these problems first. This will fix some very obvious code issues.
After you do that, show us a screenshot of the compiler without the errors. Then we can move on to the other problems.
Fix these problems first. This will fix some very obvious code issues.
After you do that, show us a screenshot of the compiler without the errors. Then we can move on to the other problems.
Thanks Jack, over the last several days I have tried and I can't for the life of me, figure out what the issue is. I guess what I am saying is that I am stuck. I have tried the following:
I, changing all my ordersend arguments with and without normalized double where applicable
ii, used bid instead of ask where appropriate on the ordersend arguments
iii, I placed an order select function before the use of orderopentime function as advised above but still I get thee same warnings in strict mode and error 130 in normal mode when I run the tester.
Thanks Jack, over the last several days I have tried and I can't for the life of me, figure out what the issue is. I guess what I am saying is that I am stuck. I have tried the following:
I, changing all my ordersend arguments with and without normalized double where applicable
ii, used bid instead of ask where appropriate on the ordersend arguments
iii, I placed an order select function before the use of orderopentime function as advised above but still I get thee same warnings in strict mode and error 130 in normal mode when I run the tester.
I appoloize didn't rrealize it wasn't captured.
//+------------------------------------------------------------------+ //| nadex5mins.mq4 | //| Copyright 2017, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" /#property strict //General variables extern double TakeProfit =0.0009; extern double StopLoss =-0.0009; string filename; int file_handle,Date; //--- parameters for writing data to file input string InpFileName="deta.csv"; // File name input string InpDirectoryName="Data"; // Folder name //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int init() { //--- file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV); if(file_handle!=INVALID_HANDLE) { PrintFormat("%s file is available for writing",InpFileName); PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH)); } else PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError()); //--- return (0); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { int count; for(count=0;count<=OrdersHistoryTotal()-1;count++) { OrderSelect (count, SELECT_BY_POS, MODE_HISTORY); FileWrite(file_handle,Symbol()+" "+TimeDayOfYear(OrderOpenTime())+" "+TimeHour(OrderOpenTime())+":"+TimeMinute(OrderOpenTime())+" "+OrderOpenPrice()+" "+TimeHour(OrderCloseTime())+":"+TimeMinute(OrderCloseTime())+" "+OrderClosePrice()+" "+TimeDayOfYear(OrderCloseTime())+" "+OrderType()); } //--- close the file. FileClose(file_handle); PrintFormat("Data is written, %s file is closed",InpFileName); return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- Date = DayOfYear(); //int ticket; double LONG_TP = NormalizeDouble(TakeProfit,5); double LONG_SL = NormalizeDouble(StopLoss,5); if(TimeMinute(TimeCurrent())%5 == 0) // int Tyme = TimeMinute(TimeCurrent())%5; // if(Tyme == 5) { RefreshRates(); double bid =MarketInfo(Symbol(),MODE_BID); // Request for the value of Bid double ask =MarketInfo(Symbol(),MODE_ASK); // Request for the value of Ask int ticket = OrderSend(Symbol(),OP_BUY ,0.1,NormalizeDouble(ask,5),3,NormalizeDouble(bid-StopLoss,5),NormalizeDouble(bid+TakeProfit,5),"",0, 0, Green); RefreshRates(); if(OrderSelect(ticket,SELECT_BY_TICKET)==TRUE){ if(TimeMinute(TimeCurrent())== TimeMinute(OrderOpenTime())+5){ OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(bid,5), 10, Blue); }} } //---- return(0); }
FileWrite(file_handle,Symbol()+" "+TimeDayOfYear(OrderOpenTime())+" "+TimeHour(OrderOpenTime())+":"+TimeMinute(OrderOpenTime())+ " "+OrderOpenPrice()+" "+TimeHour(OrderCloseTime())+":"+TimeMinute(OrderCloseTime())+" "+OrderClosePrice()+ " "+TimeDayOfYear(OrderCloseTime())+" "+OrderType());
Implicit int or double to string. Format your output
FileWrite(file_handle, StringFormat("%s %i %i:%i %g %i:%i %g %i %i", Symbol(), TimeDayOfYear(OrderOpenTime()), TimeHour(OrderOpenTime()), TimeMinute(OrderOpenTime()), OrderOpenPrice(), TimeHour(OrderCloseTime()), TimeMinute(OrderCloseTime()), OrderClosePrice(), TimeDayOfYear(OrderCloseTime()), OrderType() ));
![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
//| nadex5mins.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern double TakeProfit =0.0015;
extern double StopLoss =-0.0015;
string filename;
int file_handle,Date;
//--- parameters for writing data to file
input string InpFileName="deta.csv"; // File name
input string InpDirectoryName="Data"; // Folder name
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//---
file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);
if(file_handle!=INVALID_HANDLE)
{
PrintFormat("%s file is available for writing",InpFileName);
PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH)); }
else
PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());
//---
return (0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
int count;
for(count=0;count<=OrdersHistoryTotal();count++)
{
OrderSelect (count, SELECT_BY_POS, MODE_HISTORY);
FileWrite(file_handle,Symbol()+" "+TimeDayOfYear(OrderOpenTime())+" "+TimeHour(OrderOpenTime())+":"+TimeMinute(OrderOpenTime())+" "+OrderOpenPrice()+" "+TimeHour(OrderCloseTime())+":"+TimeMinute(OrderCloseTime())+" "+OrderClosePrice()+" "+TimeDayOfYear(OrderCloseTime())+" "+OrderType());
}
//--- close the file.
FileClose(file_handle);
PrintFormat("Data is written, %s file is closed",InpFileName);
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
Date = DayOfYear();
//int ticket;
double LONG_TP = NormalizeDouble(TakeProfit,5);
double LONG_SL = NormalizeDouble(StopLoss,5);
if(TimeMinute(TimeCurrent())%5 == 0)
// int Tyme = TimeMinute(TimeCurrent())%5;
// if(Tyme == 5)
{
RefreshRates();
double bid =MarketInfo(Symbol(),MODE_BID); // Request for the value of Bid
double ask =MarketInfo(Symbol(),MODE_ASK); // Request for the value of Ask
int ticket = OrderSend(Symbol(),OP_BUY ,0.1,NormalizeDouble(ask,5),3,NormalizeDouble(ask-StopLoss,5),NormalizeDouble(ask+TakeProfit,5),"",0, TimeCurrent() + 300, Green);
FileWrite(file_handle,"kula mavy");
if(TimeMinute(TimeCurrent())== TimeMinute(OrderOpenTime())+5){
OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(bid,5), 10, Blue);
}
}
//----
return(0);
}