I want to make candle stick delay when place orders.
For example, buy condition matched and place order.
How can I code (add) to delay order?
For example, if buy_condition is matched and after 5 candle stick later, I want to place order.
First have a function which checks if new bar has appeared:
datetime lastBarOpenTime; //+------------------------------------------------------------------+ bool IsNewBar() //+------------------------------------------------------------------+ { datetime thisBarOpenTime = Time[0]; if(thisBarOpenTime != lastBarOpenTime) { lastBarOpenTime = thisBarOpenTime; return (true); } else { return (false); } }
Then in your original function keep adding a count variable. Once count reaches 5 place order and reset count to 0:
// These 2 should be globals: bool isBuyOn = false; uint count_delay = 0; // Inside your function: if (buy_condition==1){ isBuyOn = true; } if(IsNewBar() && isBuyOn == true) { if(count_delay == 5) { // Reset count_delay = 0; isBuyOn = false; // Do Buy Buy_order return; } else count_delay++; }
This will make your code a bit complicated.
If you are using say an indicator value for your buy signal, you can always use iCustom and it's "shift" argument as 5 to get a 5 bars delayed signal.
But I hope this helps.
Hi, Abir
Thank you for your code sample.
Now I understand how to do this.
I don't use icustom, so I may count new bar after BUY signals is made and if count dalay=5, then open order.
Your code sample really helped me.
Thank you so much.
- 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 want to make candle stick delay when place orders.
For example, buy condition matched and place order.
How can I code (add) to delay order?
For example, if buy_condition is matched and after 5 candle stick later, I want to place order.