Heikin Ashi Can’t do Buy Orders


Category:
0
0

Sir,

I used your code from another post to attempt to create a strategy based on Heiken Ashi.   I would like to buy to open on the second green bar, and sell to close on the first following red bar.  And conversely to sell to open on the second red bar and buy to close on the next green bar.

So far all the strategy does is sell to open and buy to close.  And I can’t seem to get it to close on the first green bar, it closes on the second green bar.

Appreciate any assistance, I have tried to structure my question according to your guidelines!

I attached my code, clearly I am still learning.

Thank you,

 

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on July 26, 2020 12:18 pm
170 views
0
Private answer

I'm not sure why you included "can't do buy orders" in your question title. I have reviewed these details several times and cannot see how that fits the context.

But I understand you are trying to trigger a long entry on the second green, a long exit on the first red. The for the short side you are trying to trigger a short entry on the second red bar and a short exit on the first green bar.

There is nothing in your code that defines a pattern consisting of two green bars or two red bars. Your signal is for first green or first red. In the AddOrder statements you are manipulating the index value of the entry price in some missguided attempt to influence when the order is plotted. What you end up with are some entry prices that are not even part of the candle (example, below the low of the bar or above the high of the bar). Very dangerous.

So before you go any further you need to read my solution in the following post and use the examples I provided to practice until you understand this bit. It is exyremely important you understand how to get the entry prices correct. Nothing else matters until you can master that.

https://www.hahn-tech.com/ans/parablic-sar-signal-not-firing-in-tos-strategy/

Please don't go any further until you have fully understand and practiced what I demonstrate in that post. As I said, if you get this part wrong nothing else you do will be worth a hill of beans.

Now, in the few minutes I have left I will try to help you with those signals. I don't have time to fix everything in this post. So hopefully these lines of code will help you understand how to build the signals you need for your strategy:

def firstGreenCandle = haColor and !haColor[1];
def secondGreenCandle = firstGreenCandle[1] and haColor;
def firstRedCandle = !haColor and haColor[1];
def secondRedCandle = firstRedCandle[1] and !haColor;

Sorry, out of time. Hope that helps.

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on July 26, 2020 1:35 pm
0
Yes it helps quite a bit, thank you. It shows me that I have a lot more sudying to do, I will read your other post until I understatnd it, as you suggested. Again, I appreciate the response.
( at July 26, 2020 3:12 pm)