Sending Orders only on next bar!!
My EA is based on Indicators Inclination only. And I am having difficulties at the point when the inclination inside the same candle turn up and down.
My EA gives orders for buy/sell depending on the inclination and at this point where this inclination can be up and down several times inside the same bar, the EA generates lots of orders.
So I actually need that the EA recognizes the inclination and only on the next candle sends the order - open, buy or close only on next bar.
Can anyone help me?
Replies
Hi, ANbravo!
First, you need to place logic in NextBar() method instead OnQuote():
public override void NextBar()
{
//trading logic
}
It will provide you to check a fixed inclination between two bars:
//current and previous bar
var v1 = CurrentData.GetPrice(PriceType.Close, 0);
var v2 = CurrentData.GetPrice(PriceType.Close, 1);
or
//previous bar and bar before previous
var v1 = CurrentData.GetPrice(PriceType.Close, 1);
var v2 = CurrentData.GetPrice(PriceType.Close, 2);
and then
//values comparing logic
if(v1 < v2)
{
//negative inclination block
//check if we don't have open positions
if(!Positions.GetPositions().Any())
{
//place order
}
}
else
{
//positive inclination block
foreach(var pos in
Positions.GetPositions())
{
//close position
}
}
But if you use another trading scripts you need to specify positions scope like:
Positions.GetPositions().Where(p => p.MagicNumber == [MAGIC_NUMBER] && p.Instrument = Instruments.Current && p.Account == Accounts.Current)
Good Luck!
Join PTMC community to post your replies on forum