http://code.google.com/p/mt4tradeduplicator/
There is no divide operator in the code you posted. There is no Print("OUT") either. The problem lies elsewhere.
kolier:
http://code.google.com/p/mt4tradeduplicator/
http://code.google.com/p/mt4tradeduplicator/
Thanks but this is not what I am trying to achieve. I need to copy trades in backtesting, not between terminals.
WHRoeder:
There is no divide operator in the code you posted. There is no Print("OUT") either. The problem lies elsewhere.
Print("OUT") was supposed to go after the FileClose(fh) statement at the very bottom. Is it possible to get a "zero divide" error without explicitly diving by zero? I'd post my whole code but I'm sure no one wants to weed through that.
There is no divide operator in the code you posted. There is no Print("OUT") either. The problem lies elsewhere.
You were right WHRoeder, the problem was in something completely unrelated. However now that its fixed I have another problem. Instead of reading a the next set of variables, my EA keeps re-reading the ifirst set. Is this because my FileOpen() statement is in my start function? I tried to switch it to the init function but for some reason it give me messages like this: "handle 1 does not exist in FileIsEnding." How can I read the next set?
Here is my updated (relevant) code:
double price = 0, sl= 0, tp=0,lots=0.1; int LinesCNT=0,i,ticket,pos; double p; datetime t; string s_; int error = 0; int fh=FileOpen(FileNameForRead,FILE_CSV|FILE_READ,';'); // to test the file, it is necessary to pout it into tester\files\TL_DATA.txt if(fh<0) { Print("Error opening file \"" + FileNameForRead + "\"","ERROR", IDOK + MB_ICONERROR); return(1); } while(true) { string Operation=FileReadString(fh); if(FileIsEnding(fh)) break; // file ended? - exit // count the section coordinates string st1=FileReadString(fh); datetime t1=StrToTime(st1); string MarkComent = "X"; // Print(st1," ",Operation); //Print (MarkComent); //********************************************************************************** // 2) block opening orders as soon as the beginning of the pattern section is passed. //********************************************************************************** bool OrderNotPresent=true; // a sign showing that we haven't opened such an order yet if (error>0){ Print("GetLastError() = ",error); } if(t1<=TimeCurrent()) // time to open - make sure that this order is not opened { Print("t1 = ",t1," timecurrent = ",TimeCurrent()); for(i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue; if(OrderComment()==MarkComent) { OrderNotPresent=false; break; } // åñòü òàêîé îðäåð } for(i=0;i<OrdersHistoryTotal() && OrderNotPresent;i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue; // â îðäåð â èñòîðèè äîïèñûâàåòñÿ â õâîñò íå÷òî âðîäå "[sl]" - åãî íóæíî îòðåçàòü!! pos = StringFind(OrderComment(),"["); string CurOrderComment = StringSubstr(OrderComment(),0,pos); if(CurOrderComment==MarkComent) { OrderNotPresent=false; break; } // åñòü òàêîé îðäåð } if(OrderNotPresent) // no such order - open it { // open an order if(Operation=="B") // Buy { price = NormalizeDouble(Ask,Digits); sl = If(StopLoss > 0, NormalizeDouble(price - StopLoss*pt,Digits), 0); tp = If(TakeProfit > 0, NormalizeDouble(price + TakeProfit*pt,Digits), 0); lots = NormalizeDouble(Lots,LotDigits); ticket=OrderSend(Symbol(),OP_BUY,lots,price,3,sl,tp,MarkComent,111,0,Blue); OrderSelect(ticket,SELECT_BY_TICKET); } else if (Operation=="S") // Sell { price = NormalizeDouble(Bid,Digits); sl = If(StopLoss > 0, NormalizeDouble(price + StopLoss*pt,Digits), 0); tp = If(TakeProfit > 0, NormalizeDouble(price - TakeProfit*pt,Digits), 0); lots = NormalizeDouble(Lots,LotDigits); ticket=OrderSend(Symbol(),OP_SELL,lots,price,3,sl,tp,MarkComent,111,0,Red); OrderSelect(ticket,SELECT_BY_TICKET); } } } FileClose(fh);
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to load a text file I saved with FileWrite() that contains order open times and directions (buy or sell). My intention is to use these variables to replicate all the orders opened by one of my EAs (EA#1) within another EA (EA#2). That way I can see if EA#2 is better at closing EA#1's orders than EA#1 itself.
My text file looks like this:
The first variable's value is "B" or "S" (which represents OP_BUY or OP_SELL), and the second variable is the OrderOpenTime().
The code I am having issues with is the read/execute portion; its written below. I found it on this website in this article and modified it from there:
When I run this I get this in my journal (print statements left in to make debugging easier)
I have been trying to pin down the source of the zero divide error but I just can't seem to get it right. I'd really appreciate a little help :)
Edit: Perhaps it has something to do with this statement?: