How To Check Previous candles in EA Creation?

 

Hi friends. I hope that you are fine. I built an strategy and I want to make an EA of it. I've already written the basic code, but I have a problem that I will explain. I'll attach a picture to this post showing the indicator results of my strategy with arrows up and down. In this picture you will see four vertical lines. I'll tell you what those lines mean. The blue line is on the candle that shows an arrow up after its last arrow which is down with a red vertical line on the candle. The candle after the candle which has a blue vertical line is my  long entry. My exist will be the candle after the candle which has an arrow down and a brown vertical line on it. Also notice that the last arrow is an up one which is on the candle with a green vertical line. At the exit, I want to open a short position too, and exit when a candle after the candle which an arrow up appears on it; And not to mention that there's an arrow down before it. And here again is a long position entry and this cycle goes on and on. I want to check previous candles to see two candles; one with arrow up after the one with arrow down, and vice versa, to make a new position at the current candle and also close the last position. I hope you can help me with the code.

If you have additional question, don't hesitate to ask me :)

Files:
Screenshot.png  129 kb
 
I hope - the coders will help you on this thread (I am not a coder).
If not so you may consider to use Freelance service for example.
 
Sergey Golubev:
I hope - the coders will help you on this thread (I am not a coder).
If not so you may consider to use Freelance service for example.
Thank you. I hope that too. But I will take a consideration of your suggestion too.
 
I think I can help you, I  just want to know what do you use to determine the arrows?
 
Brian Rumbles:
I think I can help you, I  just want to know what do you use to determine the arrows?

Thanks for your reply! Actually I use signal="buy" and signal="sell" instead of the arrows.

here's part of my code (I've already defined the sell conditions and buy conditions but for obvious reasons I can't share them here):

  string signal="";
  bool buy_condition_1 = 
  bool buy_condition_2 = 
  bool buy_condition_3 = 
  bool buy_condition_4 = 
  bool buy_condition_5 = 
  bool sell_condition_1 = 
  bool sell_condition_2 = 
  bool sell_condition_3 = 
  bool sell_condition_4 = 
  bool sell_condition_5 = 
     
     if(buy_condition_1 && buy_condition_2 && buy_condition_3 && buy_condition_4 && buy_condition_5)
     {
     signal="buy";
     }
     if(sell_condition_1 && sell_condition_2 && sell_condition_3 && sell_condition_4 && sell_condition_5)
     {
     signal="sell";
     }

if you want to see the whole code, please send me a private message.

 

So basically if the 2nd last arrow was down (candle2) and the last arrow was Up(candle1) then buy on the open of the current candle 0.

When 2nd last arrow up (candle2) and last arrow Down (candle1) then on current candle0 open: close trade and open new Sell trade.


And the arrows are your own custom indicator or are fractals?

 
Brian Rumbles:

So basically if the 2nd last arrow was down (candle2) and the last arrow was Up(candle1) then buy on the open of the current candle 0 and close the trade.

When 2nd last arrow up (candle2) and last arrow Down (candle1) then on current candle0 open: close trade and open new Sell trade.


And the arrows are your own custom indicator or are fractals?

I added something to your first line, but basically you got it right! Thanks!

These arrows are my custom indicator, not fractals.

Reason: