Scan to get First buy signal from a strategy


Category:
0
0

Dear Pete,

Great fan of your work. I’m a newbie to TOS platform (new to trading too).

I’ve watched your videos multiple times and almost went through all the TOS categories in this forum.

I have taken code from one of your replies from the Strategy section and created a scan (& a watchlist) based on it.

<strong><em>Strategy code:</em></strong>
--------------------------------------------------------------------------------------------------------------------
def haclose = (open + high + low + close) / 4;
def haopen = compoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def Yesterday_haclose = (open from 1 bar ago + high from 1 bar ago + low from 1 bar ago + close from 1 bar ago) / 4 ;
def Yesterday_haopen = compoundValue(1, (Yesterday_haopen[1] + Yesterday_haclose[1]) / 2, (open[1] + close[1]) / 2);

def buy = Yesterday_haclose &lt; Yesterday_haopen and haopen &lt; haclose;
def sell = Yesterday_haclose &gt; Yesterday_haopen and haopen &gt; haclose; 

AddOrder(OrderType.BUY_AUTO, buy, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = “Buy”);
AddOrder(OrderType.SELL_AUTO, sell, tickcolor = Color.RED, arrowcolor = Color.RED, name = “Sell”);

——————————————————————————————————————–

<strong><em>Scan code:</em></strong>

——————————————————————————————————————–

def haclose = (open + high + low + close) / 4;
def haopen = compoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);

def Yesterday_haclose = (open from 1 bar ago + high from 1 bar ago + low from 1 bar ago + close from 1 bar ago) / 4 ;
def Yesterday_haopen = compoundValue(1, (Yesterday_haopen[1] + Yesterday_haclose[1]) / 2, (open[1] + close[1]) / 2);
plot habuy = Yesterday_haopen;

——————————————————————————————————————–

I was wondering if it is possible to find in the scan (and thereby in the watchlist) the first buy signal from the strategy code.

The results I get are very inconsistent.

Appreciate your valuable guidance.

Regards,

Jay

 

Marked as spam
Posted by (Questions: 6, Answers: 7)
Asked on May 18, 2020 11:15 am
140 views
0
Also, ideally to have a color coded custom column in the watchlist which indicates a buy signal. Thanks Jay
( at May 18, 2020 11:34 am)
0
Private answer

The answer you seek has a very complicated solution. A chart strategy plots the entry at the first buy signal and ignores any additional buy signals until an exit signal closes that position on the chart. It is not a simple process to convert only those buy and sell orders to a scan. Because the scan will see all of the signals, even the ones the chart strategy skipped because it was already in a position.

So the answer is no. We cannot get there from here. Certainly not within the limited span of time I permit for free solutions in the Q&A forum.

Final note, whatever you need to try to format your code snippets backfired. I'm not sure what you did or how you did that but you can see that it destroyed significant portions of your code.

 

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on May 18, 2020 12:20 pm
0
Thanks Pete for the response, I certainly did not think it was going to be a complicated solution. About the code, I selected it to be as a 'Preformatted' type in the text formatting tool. It certainly destroyed the code. Thanks again!
( at May 18, 2020 12:31 pm)