This might Help. I wrote that way because I don't know which chart its attached to. Most ppl use Time[0] if attached to H1 charts. I didn't test it to work but it did compile.
int start(){ //+------------------------------------------------++------------------------------------------------+ //+------------------------------------------------++------------------------------------------------+ double Lots; datetime Time_Stamp; int varH1BiasDirection,OrderSetFlag,Pending_Order_Distance; double Price_Buy=NormalizeDouble(Ask,Digits)+(Pending_Order_Distance*Point); double Price_Sell=NormalizeDouble(Bid,Digits)-(Pending_Order_Distance*Point); if(varH1BiasDirection == 1 && Time_Stamp != Hour()) { if(OrderSend(Symbol(),OP_BUYLIMIT,Lots,Price_Buy,4,0,0,0,0,0,Green)>0) { OrderSetFlag = 1; Time_Stamp = Hour(); } if(OrderSend(Symbol(),OP_SELLLIMIT,Lots,Price_Sell,4,0,0,0,0,0,Red)>0) { OrderSetFlag = 1; Time_Stamp = Hour(); } } //+------------------------------------------------++------------------------------------------------+ //+------------------------------------------------++------------------------------------------------+ return(0);}
This might Help. I wrote that way because I don't know which chart its attached to. Most ppl use Open[0] if attached to H1 charts. I didn't test it to work but it did compile.
Does Open[0] only fire once at the start of the new hour candle?
Still not sure why the order isn't being sent here even though the code is fired:
if ( (Hour() ==0 || Hour()==1 || Hour()==2 || Hour()==3 || Hour()==4 || Hour()==5 || Hour()==6 || Hour()==7 || Hour()==8 || Hour()==9 || Hour()==10 || Hour()==11 || Hour()==12 || Hour()==13 || Hour()==14 || Hour()==15 || Hour()==16 || Hour()==17 || Hour()==18 || Hour()==19 || Hour()==20 || Hour()==21 || Hour()==22 || Hour()==23) && varH1BiasDirection == 1 && OrderSetFlag == 0) { OrderSend(Symbol(),OP_BUYLIMIT, Lots, NormalizeDouble(varLow,2), 0, NULL, NULL, NULL, 0); //TP and SL are put in by the manage code Print("Created"); Sleep(1000); OrderSetFlag = 1; }
Sorry, I ment Time[0], You'll have to change the time stamp to Time[0] ie.. Time_Stamp = Time[0] ; after the order is placed. Also, keep an eye on the distance between current price and your pending order. Brokers dont allow them to be close and that may be why your order are failing. But in you code the EA updates the Flag after OrderSend without any real verification. The best verification would be an order select loop.
Yes, but if the order failed it would show up as an error in the journal/Experts log wouldn't it?
Yes, how fast is the back-test running? I'll recommend you back-test on say 1 day worth of data and slow the speed down so that you can see every entry in the on-screen log. There's also a log file in the Test Folder Structure I believe which would be more accurate.
I was testing it on demo in a live tick environment and it wasn't doing anything apart from it loads and I can see the comment of OrderSetFlag is 0, then it changes to 1 on the next tick and that's it.
"Created" appears in the journal. I'll have a look for the log file...
I'll recommend back-testing first if you can, whenever you program something.
Back testing doesn't create any orders, which is why I tried the demo, which doesn;t either :)
Any thoughts on how to troubleshoot it?
You didn't include the codes that I give you. The EA you're working with is badly coded.
if (OrderSelect(i,SELECT_BY_POS) && OrderCloseTime()==0) { Comment ("Bias: " + varH1BiasDirection + "\nOrderSet: " + OrderSetFlag); double HAvalOpen=iCustom(NULL, 0, "Heiken Ashi",Red,Blue,Red,Blue,2,1); double HAvalClose=iCustom(NULL, 0, "Heiken Ashi",Red,Blue,Red,Blue,3,1); if (HAvalOpen<HAvalClose) varH1BiasDirection = 1; if (HAvalOpen>HAvalClose) varH1BiasDirection = -1;
It Starts out with that code. if (OrderSelect(i,SELECT_BY_POS) && OrderCloseTime()==0) but it never placed an order to begin with. Therefore, you'll never get if (HAvalOpen<HAvalClose) varH1BiasDirection = 1; and if (HAvalOpen>HAvalClose) varH1BiasDirection = -1; to change from 0. I don't have the time to fix all the mistakes I seen within it. Try playing with a different EA.
![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
I have some code to create some orders once per hour.
Do I need to run it in a for lopp for each section ie 0 to 24 to do this?