TTM_Wave Strategy – Buy Cyan/Sell Blue – above 0


Category:
0
0

Hi,

I am trying to add a custom strategy using the following thinkscript. Buy when the C Wave turns Cyan (expansion) above zero and sell when you get a blue (contraction) C Wave bar.  Can you tell me what code needs to be added so that it only exectes order when the Wave is above zero, I am missing that part. thanks!

 

def cWaveUpper = TTM_Wave().Wave2High;
def cWaveLower = TTM_Wave().Wave2Low;
def cWaveDiff = cWaveUpper – cWaveLower;
def changesToCyan = cWaveDiff > cWaveDiff[1];
def changesToBlue = cWaveDiff < cWaveDiff[1];

AddOrder(OrderType.BUY_AUTO, changesToCyan, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = “WaveCyanLE”);
AddOrder(OrderType.SELL_AUTO, changesToBlue, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = “WaveBlueLX”);

 

Marked as spam
Posted by (Questions: 2, Answers: 2)
Asked on September 30, 2020 8:25 pm
580 views
0
When I add the ">0" it buys and sells the wrong bars. def cWaveUpper = TTM_Wave().Wave2High; def cWaveLower = TTM_Wave().Wave2Low; def aboveZeroUpper = cWaveUpper > 0; def aboveZeroLower = cWaveLower > 0; def cWaveDiff = aboveZeroUpper - aboveZeroLower; def changesToCyan = cWaveDiff > cWaveDiff[1]; def changesToBlue = cWaveDiff < cWaveDiff[1]; AddOrder(OrderType.BUY_AUTO, changesToCyan, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "WaveCyanLE"); AddOrder(OrderType.SELL_AUTO, changesToBlue, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "WaveBlueLX");
( at October 1, 2020 8:30 am)
0
I have updated my answer to provide you a complete overview of your attempt, how it went wrong, and why my original solution was the actual solution. I spent way more time on this than I should have but I perceive that you are genuinely trying to learn something here.
( at October 1, 2020 9:25 am)
0
Private answer

The TTM_Wave C has two components, as you have implied with your example code. When you say "Wave C above zero", which of the two components are you talking about?

The best solution I have for you is the previous post for a scan based on TTM_Wave C crossing the zero line:

https://www.hahn-tech.com/ans/scan-and-alert-when-ttm-wave-c-crosses-zero/

 

Edit: I see that there is a desire to learn here. Since you have put forth the effort to try to work this out I will provide something much more valuable than a solution. I will explain what your code is doing in plain English. Then show how to use the solution I provided in the post linked above to get you to an AddOrder() statement that triggers upon the Wave2 plots crossing above zero. Very important that you go back and read the solution I provided in that previous so that you understand exactly what the Wave2 histogram is doing.

Let's see if I can help you understand what you wrote, so you can see the code is doing exactly what you have written. From this, I hope to you assist you in seeing the solution. Let's take a look at two lines of code from the example you provided in the comment section of your question:

def aboveZeroUpper = cWaveUpper > 0;
def aboveZeroLower = cWaveLower > 0;

Each of those two lines result in a boolean output, true or false. If the Wave2High is above zero the return value for the variable named aboveZeroUpper is 1 (true). if the Wave2High is below zero, the return value for the variable named aboveZeroUpper is 0 (false). Likewise for the Wave2Low and the aboveZeroLower.

Those two variables are used in the next line of code from your example:

def cWaveDiff = aboveZeroUpper - aboveZeroLower;

So you are subtracting the boolean output of one variable from the boolean output of the other. Basically what you have there is one of the following combinations:

0 - 0 = 0
1 - 0 = 1
0 - 1 = -1<
/p>

So you take the variable named cWaveDiff and try to use that in the following lines of code (which you then use to generate your orders):

def changesToCyan = cWaveDiff > cWaveDiff[1];
def changesToBlue = cWaveDiff < cWaveDiff[1];

Let's just take the first one, changesToCyan, and see how things play out given the inputs coming from the previous lines:

changesToCyan = 0 > 0
changesToCyan = 1 > 0
changesToCyan = 0 > -1

.... there are more combinations here but by now I hope you get the idea. There is absolutely nothing in the chain of variables that has even the slightest thing to do with either plot from the Wave2 crossing zero.

So what do we have from the previous post I linked above? What does it look like when we test for both plots of the Wave2 crossing zero? I'll just copy and paste that here:

def cWaveUpper = TTM_Wave().Wave2High;
def cWaveLower = TTM_Wave().Wave2Low;
def aboveZero = cWaveUpper > 0 and cWaveLower > 0;
plot scan = aboveZero and !aboveZero[1];

Now, how do we trigger an order when both plots of the Wave2 have first crossed above zero?

AddOrder(OrderType.BUY_AUTO, scan, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = “WaveXaboveLE”);

So by now you should know exactly where you went wrong. But you should also understand that the solution I linked in my original response was the actual solution. You only needed to copy and paste that code and use the scan signal as the condition of your entry order. In order to include the exit for when the Wave2 histogram turns blue, you will be using some of the code you originally provided in your question.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on September 30, 2020 9:55 pm
0
Hi Pete, Appreciate your explanation as this is very valuable. I was able to finish the script. But it buys when both waves cross zero regardless if the color is blue or cyan. I want it to only buy when both waves are above zero and they turn cyan in color. Is there a line of code I can add for cyan above zero? def cWaveUpper = TTM_Wave().Wave2High; def cWaveLower = TTM_Wave().Wave2Low; def aboveZero = cWaveUpper > 0 and cWaveLower > 0; def belowZero = cWaveUpper < 0 and cWaveLower < 0; plot cWaveAbove = aboveZero and !aboveZero[1]; plot cWaveBelow = belowZero and !belowZero[1]; AddOrder(OrderType.BUY_TO_OPEN, cWaveAbove, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = “CWaveaboveLE”); AddOrder(OrderType.SELL_TO_CLOSE, cWaveBelow, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = “CWaveBelowLX”); thank you Mickey
( at October 1, 2020 3:22 pm)
0
So you simply add that component from your original code. AddOrder(OrderType.BUY_AUTO, changesToCyan and scan, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = “WaveXaboveLE”); I do believe this is beyond your current technical skills. If you are new to writing code you should not be trying to construct chart strategies on your own. You are missing very basic details. Yes, everything here is extremely basic, for an advanced software developer. If you are not an advanced software developer you really have no business trying to write custom chart studies. Sorry to be so blunt. Just trying to save you endless amounts of pain and suffering.
( at October 1, 2020 6:11 pm)