Does Bars.ClosePrices give me the actual close price of a bar ?
Does Bars.ClosePrices give me the actual close price of a bar ?
20 Feb 2024, 10:36
I am not understanding what sort of info I get from Bars.OpenPrices/Bars.ClosePrices. I have coded this logic so that it looks for a certain pattern and the logic isn't doing what I want it to do.
private bool IsBullishPullBack() {
double AClose4 = Bars.ClosePrices.Last(4);
double AClose3 = Bars.ClosePrices.Last(3);
double ALow3 = Bars.LowPrices.Last(3);
double AOpen3 = Bars.OpenPrices.Last(3);
double AOpen2 = Bars.OpenPrices.Last(2);
double AClose2 = Bars.ClosePrices.Last(2);
double AOpen1 = Bars.OpenPrices.Last(1);
if (
(AClose3 < AClose4) &&
(AClose3 < AOpen2 && AOpen2 > ALow3 && AClose2 >= AOpen3 ) &&
AOpen1 >= AOpen2
)
{
return false;
}
return true;
}
Here is an example pic from the backtest :
You can see here although in the code the close of bar 2 should be greater than or equal to the open of bar 3 but in this pic its tell yet the Bot still took the trade .
In case you wondering what the rest code is like :
// parent method to check rules and open bullish trade or send signal.
private void TradeRulesBullish()
{
// flag to open a trade if all rules true.
bool OpenBuyTrade = false;
if (IsBullishSignal() && !IsBullishPullBack() )
{
OpenBuyTrade = true;
}
if (OpenBuyTrade)
{
if (!IsBullish)
{
if (!IsTradeOpen(TradeType.Buy))
{
double AClose3 = Bars.ClosePrices.Last(3);
double StopLoss1 = AClose3;
double takeprofits = TakeProfit;
OpenTrade(TradeType.Buy,StopLoss1,takeprofits);
}
}
IsBullish = true;
}
else
{
IsBullish = false;
}
}
Replies
mihlali700
21 Feb 2024, 04:01
RE: Does Bars.ClosePrices give me the actual close price of a bar ?
firemyst said:
I don't understand what you're saying. Read that sentence outloud to yourself, especially the italics part:
“You can see here although in the code the close of bar 2 should be greater than or equal to the open of bar 3 but in this pic its tell yet the Bot still took the trade .”
In the screen capture you provided, the close of 2 bars back is greater than the close of the 3rd bar back from the current bar.
Not the close price the open price , the close of 2 bars back should be greater or equal to the open of the third bar back.
Its in the code :
if (
(AClose3 < AClose4) &&
(AClose3 < AOpen2 && AOpen2 > ALow3 && AClose2 >= AOpen3 ) &&
AOpen1 >= AOpen2
)
“ Aclose2 > = Aopen3” This isn't true yet the bot still took the trade and i don't know why.
The point is to find this pattern :
@mihlali700
PanagiotisCharalampous
21 Feb 2024, 07:06
Hi there,
As far as I can see, the trade was taken three bars ago. Therefore these are the bars you should be looking at
@PanagiotisCharalampous
mihlali700
21 Feb 2024, 08:04
RE: Does Bars.ClosePrices give me the actual close price of a bar ?
PanagiotisCharalampous said:
Hi there,
As far as I can see, the trade was taken three bars ago. Therefore these are the bars you should be looking at
I have been changing the code and testing it in the back tester and as far as I can tell for some reason the trades are entered late after the pattern has appeared and I'm not understanding why .
Even just using this code :
// returns true if bullish pullback
private bool IsBullishPullBack() {
double AClose4 = Bars.ClosePrices.Last(4);
double AClose3 = Bars.ClosePrices.Last(3);
double ALow3 = Bars.LowPrices.Last(3);
double AOpen3 = Bars.OpenPrices.Last(3);
double AOpen2 = Bars.OpenPrices.Last(2);
double AClose2 = Bars.ClosePrices.Last(2);
double AOpen1 = Bars.OpenPrices.Last(1);
double AClose1 = Bars.ClosePrices.Last(1);
if (
(AClose3 < AClose4) &&
(AClose3 < AOpen2 && AOpen2 > ALow3 && AClose2 >= AOpen3 ) &&
AOpen1 >= AOpen2 && AClose1 >=AClose2
)
{
return false;
}
return true;
}
And nothing else when looking to open trades it still enters the trades late
@mihlali700
mihlali700
21 Feb 2024, 08:19
RE: RE: Does Bars.ClosePrices give me the actual close price of a bar ?
mihlali700 said:
PanagiotisCharalampous said:
Hi there,
As far as I can see, the trade was taken three bars ago. Therefore these are the bars you should be looking at
I have been changing the code and testing it in the back tester and as far as I can tell for some reason the trades are entered late after the pattern has appeared and I'm not understanding why .
Even just using this code :
// returns true if bullish pullback
private bool IsBullishPullBack() {
double AClose4 = Bars.ClosePrices.Last(4);
double AClose3 = Bars.ClosePrices.Last(3);
double ALow3 = Bars.LowPrices.Last(3);
double AOpen3 = Bars.OpenPrices.Last(3);
double AOpen2 = Bars.OpenPrices.Last(2);
double AClose2 = Bars.ClosePrices.Last(2);
double AOpen1 = Bars.OpenPrices.Last(1);
double AClose1 = Bars.ClosePrices.Last(1);
if (
(AClose3 < AClose4) &&
(AClose3 < AOpen2 && AOpen2 > ALow3 && AClose2 >= AOpen3 ) &&
AOpen1 >= AOpen2 && AClose1 >=AClose2
)
{
return false;
}
return true;
}
And nothing else when looking to open trades it still enters the trades late
Here is an example on the live market , why did it take this trade ? I don't understand cause the pattern isn't there . Whats going on ? This order was made on 8:15 so I know that the pattern isn't there during that time and that its not possible for it to be an old oder.
@mihlali700
PanagiotisCharalampous
21 Feb 2024, 10:01
Hi,
I still do not understand what the problem is. The cBot does exactly what you have programmed it to do. Here are the bars you are checking. The Open price is higher than the previous close price.
@PanagiotisCharalampous
RJM1
24 Feb 2024, 00:43
( Updated at: 24 Feb 2024, 05:20 )
RE: RE: RE: Does Bars.ClosePrices give me the actual close price of a bar ?
mihlali700 said:
mihlali700 said:
PanagiotisCharalampous said:
Hi there,
As far as I can see, the trade was taken three bars ago. Therefore these are the bars you should be looking at
I have been changing the code and testing it in the back tester and as far as I can tell for some reason the trades are entered late after the pattern has appeared and I'm not understanding why .
Even just using this code :
// returns true if bullish pullback
private bool IsBullishPullBack() {
double AClose4 = Bars.ClosePrices.Last(4);
double AClose3 = Bars.ClosePrices.Last(3);
double ALow3 = Bars.LowPrices.Last(3);
double AOpen3 = Bars.OpenPrices.Last(3);
double AOpen2 = Bars.OpenPrices.Last(2);
double AClose2 = Bars.ClosePrices.Last(2);
double AOpen1 = Bars.OpenPrices.Last(1);
double AClose1 = Bars.ClosePrices.Last(1);
if (
(AClose3 < AClose4) &&
(AClose3 < AOpen2 && AOpen2 > ALow3 && AClose2 >= AOpen3 ) &&
AOpen1 >= AOpen2 && AClose1 >=AClose2
)
{
return false;
}
return true;
}
And nothing else when looking to open trades it still enters the trades lateHere is an example on the live market , why did it take this trade ? I don't understand cause the pattern isn't there . Whats going on ? This order was made on 8:15 so I know that the pattern isn't there during that time and that its not possible for it to be an old oder.
Hello, hopefully I can help a little bit.
Delete: AOpen2 > ALow3. <---- because this factor is already confirmed with: AClose3 < AOpen2 (I found it easier to follow the flow as: AOpen2 > AClose3).
Changed: AClose2 >= AOpen3 <---- Why not just make it AClose2 >= AOpen2, because: AOpen2 > AClose3 ensures the intended outcome.
(AClose3 < AClose4) && /// Bearish candle
AOpen2 > AClose3 && AClose2 >= AOpen2 && /// Bullish/spinner candle with gap
AOpen1 >= AOpen2 && AClose1 >=AClose2 /// Bullish candle
Also, are you using tick data?
I hope this helps, I wouldn't mind testing if the full code is available.
Good luck
@RJM1
firemyst
21 Feb 2024, 01:25
I don't understand what you're saying. Read that sentence outloud to yourself, especially the italics part:
“You can see here although in the code the close of bar 2 should be greater than or equal to the open of bar 3 but in this pic its tell yet the Bot still took the trade .”
In the screen capture you provided, the close of 2 bars back is greater than the close of the 3rd bar back from the current bar.
@firemyst