[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with coding an initial stop loss



PureBytes Links

Trading Reference Links

Hi Bob,

> >If you have decided to code your systems so that you must run Monday's
> >data again on Tuesday to get a value that you had on Monday so that you
> >can start trading on Tuesday with that value then you are correct -  the
> >question is why would you?  The simple way is just pass the value along
> >and not re-run the same data again and again and keep adding to the data
> >that must be run again and again.
> 
> There has to be some misunderstanding here and I cannot figure out
> what it is. When you turn on TradeStation and apply your system, it
> automatically starts running the system from the start of the data
> until the last bar on the chart. So if the last bar on the chart was
> the data from yesterday, you get back to where you were yesterday. It
> takes a fraction of a second. There is nothing you have to do to write
> your system to do this. It happens automatically.

Yes, TS does run all the data on whatever chart you have up. By default
that is what TS does.  TS acts on each bar in the data.  However, your
strategy does not have to.  You can run your strategy on the data that
you chose - and on the date and times that you chose.

I've written a little code that, I hope, will illustrate this:

inputs:whatever1(0),whatever2(0);
var:whatever3(0);

	(Position A)

if BarNumber >=1 then begin
	whatever3=3;
	(Position B)
	(Strategy code)
end;	

This is, I believe, pretty much the way that you are coding? 

This code will run on all data on the chart.  Inserting "Print
(File("c:\tst2\mydata.txt"),date,time,whatever3);" - in Position A will
produce the same information as in Position B. The result of the Print
run will be all the days and times on the chart and whatever3 is always
3. Which means that your Strategy code will run on all data.  The data
that is run is only controlled by the "days back" that you have set.

*****
This code does not run that way:

inputs:StartTradeTime(1000),EndTradeTime(1530);
var:whatever3(0);

	(Position A)

if dayofweek(date) = dayofweek(currentdate) then  
	if currenttime >= StartTradeTime and currenttime <= EndTradeTime then
begin
		whatever3=3;
		(Position B)
 		(Strategy code)
	end;  

Inserting the "Print(File...." into Position A will not produce the same
result as in Position B.  Position A will produce all the days and times
that are on the chart and whatever3 will be 0 until today at 1000 hrs
when it will change to 3.  The Position B run will start today at 1000
and end at 1530 hrs - which means your Strategy code only runs on
today's data from 1000 to 1530.

This code will only run on real time data - it doesn't see any historic
data.  Not even yesterday.	

Very much the same thing can be accomplished by:
if date = StartDay and currenttime >= StartTradeTime and currenttime <=
EndTradeTime then begin
 (Add StartDay to inputs - the date value must be set each day before
trading)


I hope that this clears up the difficulty.  Now - Why would any one want
to do it this way?  There were many reasons that we decided to do it
this way.  Looking forward to hearing from you.

Larry