TS2000i code question

lamog7

Junior member
Messages
11
Likes
0
Below is code auto-generated by Price Action Lab:

input: ptarget(7), stopl(7);
variables: profitprice(0), stopprice(0);

if h[2] > h[0] AND h[0] > h[1] AND h[1] > c[0] AND c[0] > l[0] AND l[0] > l[2] AND l[2] > l[1] then begin
Buy Next Bar on the open;
if Marketposition = 0 then begin
profitprice = O of tomorrow * (1+ptarget/100);
stopprice = O of tomorrow * (1-stopl/100);
exitlong next bar at profitprice limit;
exitlong next bar at stopprice stop;
end;
end;

if marketposition= 1 then begin
profitprice= entryprice * (1 + ptarget/100);
stopprice= entryprice * (1 - stopl/100);
exitlong at profitprice limit;
exitlong at stopprice stop;
end;


Could anyone tell what the first check of Marketposition = 0 does exactly? Thanks.
 
it queries to see if the platform returns an open position or not.

If the code has generated a long or short, then MarketPosition will = 1 or -1 and therefore this part of the code will not run until you are flat again (when marketposition will =0).
 
Hi,
The first check of Market Position = 0 is to trigger the Exit Orders when there is no Open Position.

This in turn will allow the system to exit the Positions on the same bars. But this is not the right way to do. Don't know much about the Price Action Lab.

Note:- We can use Intrabar Order generation in Tradestation to get this done.

Good Luck.
 
Re: I’m New To TRADING – Where Do I Start?

I am trying to understand Easy Language in TradeStation - it is pretty intuitive so far, but I cannot figure out how to write code to determine how many contracts I have open in the market at a given time. For example:

[based on criteria already in play], if I have only [bought or sold] 2 contracts, then I want to place a protective stop at a specific place, but if I have [bought or sold] 4 contracts, then I want a stop at a different place.

How can I do an if statement for the number of contracts I have in the market? Any help would be appreciated.
 
Hi Addison,

Try this,

If Marketposition <> 0 and CurrentContracts = 4 then "your stop here" Stop;

Good Luck,
Mani.
 
Top