NexusFi: Find Your Edge


Home Menu

 





Immediate stop out of position


Discussion in TradeStation

Updated
    1. trending_up 2,501 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 1 attachments




 
Search this Thread

Immediate stop out of position

  #1 (permalink)
Pritch
Denver Colorado
 
Posts: 4 since Aug 2013
Thanks Given: 1
Thanks Received: 0

Hello everyone,

I have a strategy program that stops out of the position as soon as it is entered (Same bar). I know the answer is probably simple but can't figure it out. Please let me know if you have an idea of the problem. I've attached the code and a picture of what's happening. The strange thing is that sometimes it works... Thank you in advance for any advice!


- Pritch

Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	332
Size:	22.0 KB
ID:	120681  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Trade idea based off three indicators.
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
How to apply profiles
Traders Hideout
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

I would suggest printing the components that build the stop price to the output bar. That will give you some insights in what is going on.
Another suggestion would be to post the code within code brackets in the forum. The image looks good, but I doubt anyone would type everything into their Tradestation to help you. When you do that, make sure to include the inputs and variables at least for the code snippet you want to reveal (as I can understand in case someone doesn't want to fully reveal a strategy).

Regards,
ABCTG



Pritch View Post
Hello everyone,

I have a strategy program that stops out of the position as soon as it is entered (Same bar). I know the answer is probably simple but can't figure it out. Please let me know if you have an idea of the problem. I've attached the code and a picture of what's happening. The strange thing is that sometimes it works... Thank you in advance for any advice!

Attachment 120680
Attachment 120681
- Pritch


Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
Pritch
Denver Colorado
 
Posts: 4 since Aug 2013
Thanks Given: 1
Thanks Received: 0


Thank you ABCTG!

I appreciate your comments. I went ahead and changed the code and in doing so I believe I fixed the problem. I'm posting here for viewing. Thanks Again!

I've never printed components to the output bar so will try to figure that out as well for future reference. Thanks again!



 
Code
Inputs: contractsSet(2), atrPeriods(39), stopAtr(2.6), TradesMax(6), Target1(10), Target2(28), Target3(38);

vars: t1(0), t2(0), t3(0), longlimit1(0), longlimit2(0), longlimit3(0), shortlimit1(0), shortlimit2(0), shortlimit3(0), stopBE(0);
vars: stopPrice(0), trailPrice(0), highMark(0), lowMark(0);
vars: atr(0), minTick(0), tradesToday(0);
vars: EntryLongGood(0), EntryShortGood(0);

If (Date <> Date[1]) then
	Begin	
		tradesToday = 0;
	end; 

minTick = MinMove/PriceScale;

t1 = (target1*minTick);
t2 = (target2*minTick);
t3 = (target3*minTick);

atr = average(avgTrueRange(1), atrPeriods);

If average(Close, 9) > average(Close, 18) then
	begin
		EntryLongGood = 1;
	end
	Else begin
		EntryLongGood = 0;
	end;

If average(Close, 9) < average(Close, 18) then
	begin
		EntryShortGood = 1;
	end
	Else begin
		EntryShortGood = 0;
	end;
	
If (Marketposition <> 1) and
tradesToday < TradesMax and
(EntryLongGood = 1) then
		
	Begin			
		Buy ("LE") (contractsSet * 3) contracts next bar on open;	
		stopPrice = Close - (stopAtr * atr);
		trailPrice = Close - (stopAtr * atr);
		Sell (contractsSet * 3) contracts next bar stopPrice stop;
		highMark = high;
		tradesToday = tradesToday + 1;
	end;


If (Marketposition <> -1) and
tradesToday < TradesMax and
(EntryShortGood = 1) then
	
	Begin
		Sell short ("SE") (contractsSet*3) contracts next bar on open;	
		stopPrice = Close + (stopAtr * atr);
		trailPrice = Close + (stopAtr * atr);
		Buytocover (contractsSet*3) contracts next bar stopPrice stop;
		lowMark = low;
		tradesToday = tradesToday + 1;
	end;

	
// Set Stops & Limits
If (Marketposition = 1) then
	Begin
		longlimit1 = Entryprice(0) + t1;
		longlimit2 = Entryprice(0) + t2;
		longlimit3 = Entryprice(0) + t3;
		stopBE = Entryprice(0) + (minTick * 2);
		If High > highMark then
 			begin
 				trailPrice = Close - stopAtr * atr;
 				highMark = High;
 			end;
		If CurrentContracts = (ContractsSet*3) then
			begin
				Sell ("LX1-CS3Target") contractsSet contracts next bar at longlimit1 limit;
				Sell ("LX2-CS3Target") contractsSet contracts next bar at longlimit2 limit;
				Sell ("LX3-CS3Target") contractsSet contracts next bar at longlimit3 limit;
				Sell ("LX3-CS3Stop") (contractsSet*3) contracts next bar at stopPrice stop;
			end;
		If CurrentContracts = (ContractsSet*2) then
			Begin	
				Sell ("LX2-CS2Target") contractsSet contracts next bar at longlimit2 limit;
				Sell ("LX2-CS2Stop") contractsSet contracts next bar at stopBE stop;
				Sell ("LX3-CS2Target") contractsSet contracts next bar at longlimit3 limit;
				Sell ("LX3-CS2Stop") contractsSet contracts next bar at stopBE stop;
			end;
		If CurrentContracts = (ContractsSet) then
			Begin	
				Sell ("LX1-CS1Stop") contractsSet contracts next bar at trailPrice stop;
			end;
	end;

If (Marketposition = -1) then
	Begin
		shortlimit1 = Entryprice(0) - t1;
		shortlimit2 = Entryprice(0) - t2;
		shortlimit3 = Entryprice(0) - t3;
		stopBE = Entryprice(0) - minTick * 2;
		If Low < lowMark then
 			begin
 				trailPrice = Close + stopAtr * atr;
 				lowMark = Low;
 			end;
		If CurrentContracts = (ContractsSet*3) then
			begin
				buytoCover ("SX1-CS3Target") contractsSet contracts next bar at shortlimit1 limit;
				buytoCover ("SX2-CS3Target") contractsSet contracts next bar at shortlimit2 limit;
				buytoCover ("SX3-CS3Target") contractsSet contracts next bar at shortlimit3 limit;
				buytoCover ("SX3-CS3Stop") (contractsSet*3) contracts next bar at stopPrice stop;
			end;
		If CurrentContracts = (ContractsSet*2) then
			Begin	
				buytoCover ("SX2-CS2Target") contractsSet contracts next bar at shortlimit2 limit;
				buytoCover ("SX2-CS2Stop") contractsSet contracts next bar at stopBE stop;
				buytoCover ("SX3-CS2Target") contractsSet contracts next bar at shortlimit2 limit;
				buytoCover ("SX3-CS2Stop") contractsSet contracts next bar at stopBE stop;
			end;
		If CurrentContracts = (ContractsSet) then
			Begin	
				buytoCover ("SX3-CS1Stop") contractsSet contracts next bar at trailPrice stop;
			end;	
	end;

Setexitonclose;

Reply With Quote




Last Updated on August 9, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts