NexusFi: Find Your Edge


Home Menu

 





Help - Code to trade between specified time.


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Edwin Lefevre with 4 posts (0 thanks)
    2. looks_two ABCTG with 3 posts (4 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 numberjuani with 1 posts (2 thanks)
    1. trending_up 1,576 views
    2. thumb_up 6 thanks given
    3. group 3 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread

Help - Code to trade between specified time.

  #1 (permalink)
Edwin Lefevre
Scotland
 
Posts: 27 since May 2019
Thanks Given: 11
Thanks Received: 4

I'm trying to set my strategy to trade between 1705 and 1505.

When i put the following code in the backtest results show 0 - the strategy is not running.

if time >= 1705 and time <= 1505 then
begin;

without this line of code the strategy runs as intended. So I'm guessing I am putting it wrong or missing something else?

Help much appreciated, thanks!

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
67 thanks
Battlestations: Show us your trading desks!
48 thanks
NexusFi site changelog and issues/problem reporting
47 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623


Edwin Lefevre,

welcome to futures.IO. The time can't be later than 1700 and at the same time be earlier than 1500, that's why your condition will never be evaluated to true. Using the logical OR instead of AND will do what you have in mind as the time can be later than 1700 or before 1505. When the time is between 1505 and 1700 neither of the two checks would evaluate to true and the condition would be false.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
  #4 (permalink)
Edwin Lefevre
Scotland
 
Posts: 27 since May 2019
Thanks Given: 11
Thanks Received: 4

Very simple answer - I would have kept struggling for hours. Just started coding and although easier than I thought, I still make simple mistakes.

Thanks!

Reply With Quote
  #5 (permalink)
 
numberjuani's Avatar
 numberjuani 
Agoura Hills, CA USA
 
Experience: Advanced
Platform: Tradestation&Multicharts
Broker: TradeStation
Trading: Futures & Equities
Posts: 128 since Apr 2019
Thanks Given: 9
Thanks Received: 102


Edwin Lefevre View Post
Very simple answer - I would have kept struggling for hours. Just started coding and although easier than I thought, I still make simple mistakes.



Thanks!



Edwin you could also tag your first bar and then count bars from it. You would do
If time = 1700 then firstbar = barnumber;
If barnumber < firstbar + (your counter) then begin



Sent using the NexusFi mobile app

Reply With Quote
The following 2 users say Thank You to numberjuani for this post:
  #6 (permalink)
Edwin Lefevre
Scotland
 
Posts: 27 since May 2019
Thanks Given: 11
Thanks Received: 4

Hi guys I have a follow up question from this. I have been struglinng with getting my strategy to stop early on specified (holidays) days.

I have the following so far:


if date <= 1191127 and time <= 1455 or time >= 1705 then

if date = 1191128 and time <= 1145 or time >= 1705 then
if date = 1191129 and time <= 1145 or time >= 1705 then

if date >= 1191130 and time <= 1455 or time >= 1705 then
begin;

{entry orders}

....

{Holiday close orders}

If MarketPosition >0 and date = 1191128 and time = 1150 then
sell("Cover Long") next bar at open;

If MarketPosition <0 and date = 1191128 and time = 1150 then
buytocover ("Cover Short") next bar at open;

{Holiday close order}

If MarketPosition >0 and date = 1191129 and time = 1150 then
sell("Cover Long") next bar at open;

If MarketPosition <0 and date = 1191129 and time = 1150 then
buytocover ("Cover Short") next bar at open;


**edit**

Think I potentially solved my problem.

Var:
closing_time (0);

if date = 1191128 then
closing_time = 1155 else
closing_time = 1455;

if date = 1191129 then
closing_time = 1155 else
closing_time = 1455;

if time <= closing_time or time >= 1705 then
begin;

Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

Edwin Lefevre,

when you are combining AND and OR in a condition it can make sense to use brackets to ensure that the code is evaluated in the order that you want.
 
Code
if date <= 1191127 and ( time <= 1455 or time >= 1705 ) then
Regards,

ABCTG



Edwin Lefevre View Post
Hi guys I have a follow up question from this. I have been struglinng with getting my strategy to stop early on specified (holidays) days.

I have the following so far:


if date <= 1191127 and time <= 1455 or time >= 1705 then

if date = 1191128 and time <= 1145 or time >= 1705 then
if date = 1191129 and time <= 1145 or time >= 1705 then

if date >= 1191130 and time <= 1455 or time >= 1705 then
begin;

{entry orders}

....

{Holiday close orders}

If MarketPosition >0 and date = 1191128 and time = 1150 then
sell("Cover Long") next bar at open;

If MarketPosition <0 and date = 1191128 and time = 1150 then
buytocover ("Cover Short") next bar at open;

{Holiday close order}

If MarketPosition >0 and date = 1191129 and time = 1150 then
sell("Cover Long") next bar at open;

If MarketPosition <0 and date = 1191129 and time = 1150 then
buytocover ("Cover Short") next bar at open;


**edit**

Think I potentially solved my problem.

Var:
closing_time (0);

if date = 1191128 then
closing_time = 1155 else
closing_time = 1455;

if date = 1191129 then
closing_time = 1155 else
closing_time = 1455;

if time <= closing_time or time >= 1705 then
begin;


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:
  #8 (permalink)
Edwin Lefevre
Scotland
 
Posts: 27 since May 2019
Thanks Given: 11
Thanks Received: 4

Hey Abctg, thanks for the tip.

Can I ask if my code makes sense to you? Using an if, then, else, statement to change a variable.

closing_time (0);

if date = 1191128 then
closing_time = 1155 else
closing_time = 1455;

Reply With Quote
  #9 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

Edwin Lefevre,

using different values for variables according to the outcome of other checks (like dates in your case) is perfectly fine.

Regards,

ABCTG


Edwin Lefevre View Post
Hey Abctg, thanks for the tip.

Can I ask if my code makes sense to you? Using an if, then, else, statement to change a variable.

closing_time (0);

if date = 1191128 then
closing_time = 1155 else
closing_time = 1455;


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:





Last Updated on November 25, 2019


© 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