AlunParticipant
Average
Is there a way for my code to ignore the previous candle close condition when it first starts?
I would like the code to look for the condition only from the first candle after the automatic trade has started.
I think ProOrder does what you say by default. If you have a daily timeframe and you start your robot at noon, your robot wont do anything before midnight, even if the buy conditions were met at midnight the day before.
Maybe another member can confirm what I say.
Yes above is correct … Algo code would be read at end of the first complete candle after starting Algo … no matter what the TF.
Somehow I think the OP means / is asking something else??
AlunParticipant
Average
When I started my code, there was already a daily green candle >8ema completed on the chart from the previous day. It looks like the code (or robot) read the previous green candle as >8ema even though the first candle after starting the code was a red candle closing below the 8ema. The code looks for Open>8ema[1], Close>8ema[1] and Close>Open.
I am not sure why the code seems to have read the previous candle as satisfying my code criteria, and executed a buy at market above the first red candle.
When I started my code, there was already a daily green candle >8ema completed on the chart from the previous day.
The first two conditions below fit the scenario above and so a trade would execute (at the open of the next candle) if Close > Open on the current candle?
Open>8ema[1], Close>8ema[1] and Close>Open.
Alun wrote:
code to ignore the previous candle close condition when it first starts?
To get above, you would need your code written as …
If Open>8ema[0] AND Close>8ema[0] and Close>Open Then
Buy at Market
Endif
Let us know if it works?
AlunParticipant
Average
Providing this is a valid expression, would the IF criteria “Today[0] > 202012029” prevent the code from using the candle before the code started.
OR
Is there a slight “bug” going on where the code has been triggered just before the start of the new candle? Should I start the code at a time (5 or 10 minutes) just after the market has opened to allow the first candle to start forming to avoid this issue?
AlunParticipant
Average
Thank you GraHal for your suggestion. I would like the current candle to open and close > the previous 8ema (not the current 8ema):-
Open>8ema[1] AND Close>8ema[1] and Close>Open
So I want the code to use the candle that appears after starting the code (not the candle before the code started) and compare the Open and Close to the previous 8ema.
Open > ExponentialAverage[8](close) AND Close > ExponentialAverage[8](close) AND Close > Open
Are you saying you want the above to be read at end of the candle following the candle on which you start your code?
EDIT / PS
NOTE: In the above condition, EMA is for 8 periods and so will use candle values for the previous 7 candles + the candle value of the candle on which the code is read, i.e. the current candle.
AlunParticipant
Average
Apologies if my explanations are confusing. Here is the code and a screen shot (see the attachment) of what actually happened. I started the autotrade code at 22:15 on 28th Dec on the daily timeframe after the Inverted Hammer had formed (d’ly). The next day it immediately opened a position at 88.8 – it took the previous days’ inverted hammer candle as satisfying the criteria below when the market opened the following day on 29th Dec. The light blue line is the 8ema.
Is it possible to have the code ignore the previous days candle only when the code starts (but not on subsequent days after the code continues to run)?
// Conditions to enter long positions
indicator1 = ExponentialAverage[8](close)
c1 = (close > indicator1[1])
c2 = (open >= indicator1[1])
c3 = (close > open)
IF c1 AND c2 AND c3 AND NOT onmarket THEN
BUY X PERPOINT AT MARKET
ENDIF
Alun – Please follow the forum rules and use the ‘Insert PRT Code’ button when putting code in your posts. I tidied up your post.
Your description is confusing. Your strategy did what is normal. All code is read through at the close of a candle and orders sent to the market at the open of the following candle. So if at the close of the first candle your entry conditions are met your trade will open at the opening of the following candle. If you want to skip a candle then just start a count and don’t trade until it is 2.
count = count + 1
// Conditions to enter long positions
indicator1 = ExponentialAverage[8](close)
c1 = (close > indicator1[1])
c2 = (open >= indicator1[1])
c3 = (close > open)
IF c1 AND c2 AND c3 AND NOT onmarket and count >= 2 THEN
BUY X PERPOINT AT MARKET
ENDIF
AlunParticipant
Average
Many thanks for clarifying and advising the solution, Vonasi. Apologies again for any confusion!