How can i make signals based on the shapes of bars?


0
0

I trade based on bars that close within a certain percentage of the close of the bar in relation to its position on the chart.  How can i make automated trades based on the shapes of bars and their relationship to previous bars?

I trade spikes such that the bar opens in the top 1/2 of the bar and closes in the top 1/3 of the bar with alot of space to the left.  how can i create such an alert/scan/autotrade?

Marked as spam
Posted by (Questions: 1, Answers: 4)
Asked on March 5, 2017 6:15 pm
99 views
0

Please include a screenshot or two, so I can be sure I understand the specifications. I understand you have specified a candle where the open occurs in the top 1/2 and the close occurs in the top 1/3. This specification allows for an open at the high and a lower close within the top 1/3 of the candle (otherwise known as a hammer). Assuming we are including the wicks of the candle. Your phrase ”a lot of space to the left” is wide open to interpretation. Are you saying the OHLC of the candle should be higher than the highest high, several bars to it’s left? Or just the high? Or just the close….? How many bars to the left?

( at March 5, 2017 8:52 pm)
1
Private answer

Since this was posted in the “Alerts and Notifications” topic, I will post the solution using the Study Alert tool, found in the MarketWatch tab in Thinkorswim. The same logic works in the Conditional Order Wizard and this code can be used to execute trades automatically using that tool.

CAUTION!

BEFORE APPLYING THIS TO A LIVE TRADE IT IS HIGHLY RECOMMENDED THAT YOU THROUGHLY TEST THIS USING THE STUDY ALERT. THEN PRACTICE APPLYING IT TO CONDITIONAL ORDERS IN PAPERMONEY. 

Ok, I have to say that for the sake of everyone who encounters this post in the future. Please be careful. Use of this code is at your own risk and subject to our terms and conditions: https://www.hahn-tech.com/terms-and-conditions/

Now we have that out of the way, let’s proceed. The screenshot below shows a few examples of this signal being triggered. The code is included below. I used variable names that should make it pretty easy to understand what is being done in each line. I you need adjustments or explanation just post a comment and I’ll do my best to answer. Don’t forget to up-vote any answers that best solve your question!

def rangeOfBar = high - low;
def diffCloseFromHigh = high - close;
def diffOpenFromHigh = high - open;
def closeTopThird = (diffCloseFromHigh / rangeOfBar) <= 0.3333;
def openTopHalf = (diffOpenFromHigh / rangeOfBar) <= 0.5; def lowestInPreviousFour = Lowest(low[1], 4) >= low;
def qualifiedCandle = closeTopThird and openTopHalf and lowestInPreviousFour;
plot trigger = qualifiedCandle[1] and high > high[1] + 3 * TickSize() ;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 8, 2017 9:53 am
0

Hi Pete,
i noticed that the bar on 10/26 is a signal but the Alert bar doesnt show one. Would you clarify what i might be missing?

( at March 9, 2017 10:36 pm)
0

Also, you were mentioning that this was a Hammer. Is the code you created above done by adjusting the hammer strategy in the ToS platform?

( at March 9, 2017 11:08 pm)
0

In reply to both comments. The signal on 10/26, did you check if there was a lower low in the previous 4 bars?
I did not even look at any other code when I wrote this. You gave pretty clear specifications so I wrote it directly from scratch.

( at March 10, 2017 8:25 am)
0
Private answer

Thanks for the quick reply.  Yeah, I guess it would be a hammer.  I include the wicks.  I know that there is a Hammer Strategy on the ToS platform, but i cant seem to make it give me a signal. 1. adjust the parameters to my 1/2 and 1/3 specifications,  2. ignore the signal unless the low of the bar is lower or equal to 4 bars of space to the left, 3. make it so the entry is a few cents above the high of the bar.  I hope that is a better explanation.

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 4)
Answered on March 7, 2017 10:15 pm
0

Ok, thanks for this clarification. I’ll take a look at this in the morning with a fresh set of eyes.

( at March 7, 2017 10:23 pm)
0
Private answer

Wow!  great!  Ill see what i can do with it in conjunction to your other videos on how to use this kind of code.  ill let you know how it goes.

Marked as spam
Posted by (Questions: 1, Answers: 4)
Answered on March 8, 2017 10:52 pm
0

Hi there, Im sorry to ask all sorts of questions but Im having some trouble. So, i took the code above and inserted it into the code you provided on the https://www.hahn-tech.com/thinkorswim-autotrade-almost/ video to get the signal graph at the bottom and nothing happens. Do i just copy/paste it into the ”0” on this part?:

plot signal = 0;

Im kinda confused on how to use the code.

( at March 9, 2017 11:23 pm)
0

To plot the code I provided as a lower study, nothing is needed other than to add a line that says: declare lower;
I just tested it and it plots the spikes correctly. No need to use anything from that AutoTrade Video.

( at March 10, 2017 8:30 am)