NexusFi: Find Your Edge


Home Menu

 





How to avoid more than one entry position per week


Discussion in TradeStation

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




 
Search this Thread

How to avoid more than one entry position per week

  #1 (permalink)
auato
Bradenton
 
Posts: 30 since May 2016
Thanks Given: 6
Thanks Received: 4

Hi all,

Please could you recommend me a solution to avoid more than one entry in the same week? I explain better...
I am trying to build a TS. This TS is a statistical trading system with two levels per week to enter and exit into/from the position. For example, if it enters at the beginning of the week but after a while it exits due to a stop loss triggering I don't desire it enters a second time in the same week (it can may be in the next week but not in the same). I already tried by the difference between ELDateToDateTime(0) - PosTradeExitDateTime(1,0)) <= 4.35 but it doesn't work and anyway I am searching for a better (smarter and simplier solution).

Can you help me please?

Thaank you very much

auato

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
What broker to use for trading palladium futures
Commodities
Quantum physics & Trading dynamics
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Hi auato,

you could for example modify the EntriesToday function to work on weeks or set a flag when you enter a trade. This flag could then be checked as part of your entry condition, if the flag is true then no more entries. Now you only have to reset the flag back to false at the end of the week.

The latter idea is probably simpler than modifying the EntriesToday function.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
auato
Bradenton
 
Posts: 30 since May 2016
Thanks Given: 6
Thanks Received: 4



ABCTG View Post
Hi auato,

you could for example modify the EntriesToday function to work on weeks or set a flag when you enter a trade. This flag could then be checked as part of your entry condition, if the flag is true then no more entries. Now you only have to reset the flag back to false at the end of the week.

The latter idea is probably simpler than modifying the EntriesToday function.

Regards,

ABCTG

Thank you ABCTG,

for example in this entry condition:
 
Code
IF INSDBAR=0 AND Direction=2 AND close this bar <= FinalMin AND dayofweek(date) <> 5 AND flag=0 then buy ("LIN") 1 contracts next bar at open
How can add also the setting of a flag just it entered? Could you kindly help me to make this line completing the setting after the buy with "flag=1"?

Then, if I got you, at a subsequent line I could write:

 
Code
IF dayofweek(date) = 1, flag=0
in which flag is reset at 0 only on monday and it means that it is ready to enter. flag=1 means it is already entered a trade (but this part is missing because I don't know how to set flag=1 when it enters)

BR,
auato

Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

auato,

you are welcome.

You can for example set the flag to +1 when your entry conditions are true, although this wouldn't guarantee that you got a fill. So you probably want to either check for a change in the market position or if you are pyramiding check if the number of shares/contracts (using the CurrentContracts reserved word for example) is bigger than on the previous code computation.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #5 (permalink)
auato
Bradenton
 
Posts: 30 since May 2016
Thanks Given: 6
Thanks Received: 4


ABCTG View Post
auato,

you are welcome.

You can for example set the flag to +1 when your entry conditions are true, although this wouldn't guarantee that you got a fill. So you probably want to either check for a change in the market position or if you are pyramiding check if the number of shares/contracts (using the CurrentContracts reserved word for example) is bigger than on the previous code computation.

Regards,

ABCTG

Thanks, I am trying without success

flag=0 allows to enter
flag=1 does not allow to enter

every monday I reset flag to 0 to enter.

In the middle of week if I exit for a stoploss, everytime the next bar checks currentcontracts, it realizes that currentcontract is 0 and accordingly the falg will be reset and the next bar is ready to enter.


In an IF condition after then I have the order execution command (buy). In addition to the execution statment can I also insert after then the setting of the flag to 1? In this way I avoid the check every time with currentcontracts.

A sort of "IF condition 1 AND condition 2 then buy next bar at market AND flag=1"

Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

auato,

it's hard to guess for me where the problem could be without knowing the code. You don't have to reveal anything you consider proprietary (you could for example exchange those parts with standard open source codes, as long as the new code is still able to demonstrate the issues), but the more information you provide the easier and more likely it will be for someone to help you.

The "if ... then..." statement in your pseudo code won't work, as the "then" only includes the next code statement. You can however use the "if... then begin.... end ;" statement that will include everything within the "begin... end" in your conditional check.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #7 (permalink)
auato
Bradenton
 
Posts: 30 since May 2016
Thanks Given: 6
Thanks Received: 4


ABCTG View Post
auato,

it's hard to guess for me where the problem could be without knowing the code. You don't have to reveal anything you consider proprietary (you could for example exchange those parts with standard open source codes, as long as the new code is still able to demonstrate the issues), but the more information you provide the easier and more likely it will be for someone to help you.

The "if ... then..." statement in your pseudo code won't work, as the "then" only includes the next code statement. You can however use the "if... then begin.... end ;" statement that will include everything within the "begin... end" in your conditional check.

Regards,

ABCTG

Hi ABCTG, thank you again.

I report below the code. Omitted only the definition of variables (all set 0 at the beginning of the code) and the calculation of Min and Max which represent the levels to enter and exit for the week. If in the week the TS enters but then it is not able to exit because doesn't touch the other level, a forced exit will be applied on Friday. To limit the bad trades I introduced STPLVL to reduce the losses @2%. STPLVL works well but as the two levels Min and Max are the same for the entire week after an exit our to STPLVL, it unfortunately enters again because there are the seme conditions to enter again. On the other hand, I would like to stop all operations if in that week SPTLVL forces the exit. I work with a time frame 5 minutes.
Maybe as you write, the statement if...then... begin ...end is the correct solution for me because I can set a flag to avoid other entries and to reset that flag the monday morning.


 
Code
IF closeW(1)<openW(1) Then Direction=1 Else Direction=2; //it sets Direction=1 to be short and 2 to be long (Direction=0 is defaulf to be flat)
 

//start the ordering to enter position
 
IF Direction=2 AND close this bar <= Min AND dayofweek(date) <> 5  then buy 1 contracts next bar at open 
       else if Direction=1 AND close this bar >= Max AND dayofweek(date) <> 5  then sellshort 1 contracts next bar at open; 
      
      
//start the ordering to exit position
 
IF marketposition=1 or marketposition=-1 then STPLVL=(Close this bar/entryprice-1); 
 
IF marketposition=1 AND close this bar >=Max OR STPLVL<= -0.02 then
              Sell next bar from Entry at open
              Else
IF marketposition=-1 AND close this bar <=Min OR STPLVL>= 0.02 then
             Buytocover next bar from Entry at open;
 
             
 
//apply the weekly stops

 
IF dayofweek(date) = 5 and time > 1700 AND marketposition=1 then Sell next bar at market
Else
IF dayofweek(date) = 5 and time > 1700 AND marketposition=-1 then buytocover next bar at market;

Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Hi auato,

I am a bit puzzled, you wrote:

Quoting 
Thanks, I am trying without success

flag=0 allows to enter
flag=1 does not allow to enter

every monday I reset flag to 0 to enter.

In the middle of week if I exit for a stoploss, everytime the next bar checks currentcontracts, it realizes that currentcontract is 0 and accordingly the falg will be reset and the next bar is ready to enter.

This part doesn't seem to exist in the code you posted (at least I don't see it):

 
Code
IF closeW(1)<openW(1) Then Direction=1 Else Direction=2; //it sets Direction=1 to be short and 2 to be long (Direction=0 is defaulf to be flat)
 

//start the ordering to enter position
 
IF Direction=2 AND close this bar <= Min AND dayofweek(date) <> 5  then buy 1 contracts next bar at open 
       else if Direction=1 AND close this bar >= Max AND dayofweek(date) <> 5  then sellshort 1 contracts next bar at open; 
      
      
//start the ordering to exit position
 
IF marketposition=1 or marketposition=-1 then STPLVL=(Close this bar/entryprice-1); 
 
IF marketposition=1 AND close this bar >=Max OR STPLVL<= -0.02 then
              Sell next bar from Entry at open
              Else
IF marketposition=-1 AND close this bar <=Min OR STPLVL>= 0.02 then
             Buytocover next bar from Entry at open;
 
             
 
//apply the weekly stops

 
IF dayofweek(date) = 5 and time > 1700 AND marketposition=1 then Sell next bar at market
Else
IF dayofweek(date) = 5 and time > 1700 AND marketposition=-1 then buytocover next bar at market;
I will gladly steer you in the right direction and help you, but I can't tell you where it goes wrong from the above code.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #9 (permalink)
auato
Bradenton
 
Posts: 30 since May 2016
Thanks Given: 6
Thanks Received: 4

that is the original code, I tried in a second moment to insert a flag and to discuss about this solution as you recommended me but unsuccessfully. So I came back to the original code with no flag

Reply With Quote




Last Updated on August 2, 2016


© 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