NexusFi: Find Your Edge


Home Menu

 





having trouble restricting to one trade per session


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one gonzofist with 3 posts (0 thanks)
    2. looks_two phantomtrader with 2 posts (2 thanks)
    3. looks_3 BlackSwan04 with 2 posts (2 thanks)
    4. looks_4 sptrader with 1 posts (1 thanks)
    1. trending_up 5,438 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread

having trouble restricting to one trade per session

  #1 (permalink)
 gonzofist 
PORTLAND, OR
 
Experience: None
Platform: NinjaTrader
Trading: Futures
Posts: 185 since Jul 2011
Thanks Given: 74
Thanks Received: 168

I am having trouble restricting my program to 1 trade per session. I am using it for an overnight session so a lot of the standard "per day" reserved words don't apply unfortunately. I am very new to EZL so my code is probably a little messy...

It works in restricting it to one entry but once that entry closes it opens another and usually closes it immediately since my exit conditions are still in effect and does that until the end of my session.

Below is the snippets of code that apply directly to this problem.

 
Code
if ( ( T > EndTime and T < ( StartTime + 5 ) ) = FALSE ) and ( ry_Upper10NBand <> 0 ) and ( ry_Upper20NBand <> 0 ) and ( OneADay = 0 ) and Date > 1120305 then
	begin
	if ( ry_Upper10NBand > ry_Upper20NBand ) and ( C >= ( ry_Upper10NBand + ( EnterDistance * 0.0001 ) ) ) and ( marketposition = 0 ) then
		begin
		Buy ( "NoiseLong1" ) next bar at ( ry_Upper10NBand + ( ( EnterDistance + 1 ) * 0.0001 ) ) stop ;
		OneADay = OneADay + 1 ;
		end ;
	if ( ry_Upper20NBand > ry_Lower10NBand ) and ( C >= ( ry_Upper20NBand + ( EnterDistance * 0.0001 ) ) ) and ( marketposition = 0 ) then
		begin
		Buy ( "NoiseLong2" ) next bar at ( ry_Upper20NBand + ( ( EnterDistance + 1 ) * 0.0001 ) ) stop ;
		OneADay = OneADay + 1 ;
		end ;
	end ;
and

 
Code
if T = EndTime then OneADay = 0 ;
anything you guys can do to help is much appreciated!

Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Trade idea based off three indicators.
Traders Hideout
 
  #3 (permalink)
 
sptrader's Avatar
 sptrader 
Colorado
 
Experience: Advanced
Platform: MultiCharts
Broker: IB & Iqfeed
Trading: ES , CL
Posts: 535 since Apr 2010
Thanks Given: 1,097
Thanks Received: 701


When I used Tradestation several years ago, I remember they had a function called "Tradestoday" ..
So I would write : if tradestoday = 0 then begin (If I only wanted 1 trade/day)..
It's an easy way to limit the number of trades allowed per day.

Reply With Quote
Thanked by:
  #4 (permalink)
 gonzofist 
PORTLAND, OR
 
Experience: None
Platform: NinjaTrader
Trading: Futures
Posts: 185 since Jul 2011
Thanks Given: 74
Thanks Received: 168

Unfortunately, since my session covers multiple days ( 11:00 PM - 9:00 AM ) the tradestoday function doesn't really work for me, I haven't been able to find something similarly simple that works for session that covers multiple days.

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
BlackSwan04
Boise Idaho/US
 
Posts: 49 since Mar 2012
Thanks Given: 63
Thanks Received: 60

I played around with Ninjatrader automated strategies for awhile. The way I would tell it to stop trading is at the beginning of the session I'd set "variable x = 0". Add an "if variable x == 0" argument to your trade premise. As part of the command that sets off the trade, also set variable x = 1. This should stop any other trades from happening until the next session.
Not sure if that's possible in tradestation but it worked for me on Ninjatrader.

Pseudocode example (All additions in Blue/be sure to scroll over to the right to see them all):
 
Code
if ( ( T > EndTime and T < ( StartTime + 5 ) ) = FALSE ) and ( ry_Upper10NBand <> 0 ) and ( ry_Upper20NBand <> 0 ) and ( OneADay = 0 ) and Date > 1120305 then
	SET VARIABLE "X=0";
        begin
	if ( ry_Upper10NBand > ry_Upper20NBand ) and ( C >= ( ry_Upper10NBand + ( EnterDistance * 0.0001 ) ) and (VARIABLE "X==0") ) and ( marketposition = 0 ) then
		begin
		Buy ( "NoiseLong1" ) next bar at ( ry_Upper10NBand + ( ( EnterDistance + 1 ) * 0.0001 ) ) stop ;
		OneADay = OneADay + 1 ;
                SET VARIABLE "X=1" ;
		end ;
	if ( ry_Upper20NBand > ry_Lower10NBand ) and ( C >= ( ry_Upper20NBand + ( EnterDistance * 0.0001 ) ) and (VARIABLE "X==0") ) and ( marketposition = 0 ) then
		begin
		Buy ( "NoiseLong2" ) next bar at ( ry_Upper20NBand + ( ( EnterDistance + 1 ) * 0.0001 ) ) stop ;
		OneADay = OneADay + 1 ;
                SET VARIABLE "X=1";
		end ;
	end ;

Reply With Quote
Thanked by:
  #6 (permalink)
 
phantomtrader's Avatar
 phantomtrader 
Reno, Nevada
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Trading: ZN, ZB, CL
Frequency: Daily
Duration: Minutes
Posts: 588 since May 2011
Thanks Given: 217
Thanks Received: 990

Hi: I do something similar and use the following code setup:

Inputs: Time1(100), Time2(2400), Amount(1) .........


Then undernearth your variables put in:

If time >= time1 and time <= time2 then begin

If TradesToday(Date) < (amount) then
begin


It will require an "end", "end" somewhere and can be tricky - I write my codes as individual conditions and one "end" goes after the conditions and the other at the bottom after the execution trigger code. You might have to play with the placement of "end" if it doesn't trigger.

You would have to remove your "StartTime" code to use this or it will conflict.

This should trigger a single trade per day within a 24 hour period.

Let me know if it works.

Reply With Quote
Thanked by:
  #7 (permalink)
 gonzofist 
PORTLAND, OR
 
Experience: None
Platform: NinjaTrader
Trading: Futures
Posts: 185 since Jul 2011
Thanks Given: 74
Thanks Received: 168

BlackSwan :Thanks for the help, this is essentially what my code is already attempting to do. The "OneADay" variable is intended to stop the "if" statement from executing. My placement within the code is slightly different than what you suggest here so I'll give it a try in the spot you have it and see how it goes.

Phantomtrader : I really like this way of doing it and will attempt to apply it to my code, I'm trying to think of a way to restrict my trades to the 11:00 PM to 9:00 AM (PST) custom session and still use your 1 trade every 24 hours code.

Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #8 (permalink)
 
phantomtrader's Avatar
 phantomtrader 
Reno, Nevada
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Trading: ZN, ZB, CL
Frequency: Daily
Duration: Minutes
Posts: 588 since May 2011
Thanks Given: 217
Thanks Received: 990


gonzofist View Post
BlackSwan :Thanks for the help, this is essentially what my code is already attempting to do. The "OneADay" variable is intended to stop the "if" statement from executing. My placement within the code is slightly different than what you suggest here so I'll give it a try in the spot you have it and see how it goes.

Phantomtrader : I really like this way of doing it and will attempt to apply it to my code, I'm trying to think of a way to restrict my trades to the 11:00 PM to 9:00 AM (PST) custom session and still use your 1 trade every 24 hours code.

I may have an idea about that - let me look in my code library and I'll get back to you.

Reply With Quote
Thanked by:
  #9 (permalink)
BlackSwan04
Boise Idaho/US
 
Posts: 49 since Mar 2012
Thanks Given: 63
Thanks Received: 60


gonzofist View Post
BlackSwan :Thanks for the help, this is essentially what my code is already attempting to do. The "OneADay" variable is intended to stop the "if" statement from executing. My placement within the code is slightly different than what you suggest here so I'll give it a try in the spot you have it and see how it goes.

Phantomtrader : I really like this way of doing it and will attempt to apply it to my code, I'm trying to think of a way to restrict my trades to the 11:00 PM to 9:00 AM (PST) custom session and still use your 1 trade every 24 hours code.

Hi Gonzofist,

If the OneADay feature restricts 1 trade to a 24 hour period, you may run into missing a setup in the next session, say if your trade goes off at 12:30am, and your next signal hits the next night at 12:15 it could conceivably skip it since it would still have 15 more minutes on its "clock".
Just speculating. I have no experience with trade station and the little experience I have with Ninja automated was more for backtesting than anything else.
Backstory: I was looking for a mechanical strategy that I could manually trade, so I had a pretty tight session limit (12am - 2am at the time). However, I had to have bars on the chart before the session so that the indicators would work. As I wasn't limiting my trades to 1 a day but configuring to have them not trade outside those hours, that variable did the trick.
That said, good luck in your search. The automated road is a hard one.

Regards,
BlackSwan

Reply With Quote
Thanked by:




Last Updated on January 18, 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