Help - Code to trade between specified time. - futures io
futures io futures trading



Help - Code to trade between specified time.


Discussion in EasyLanguage Programming

Updated by ABCTG
      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 520 views
    2. thumb_up 6 thanks given
    3. group 3 followers
    1. forum 8 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Help - Code to trade between specified time.

(login for full post details)
  #1 (permalink)
Scotland
 
 
Posts: 27 since May 2019
Thanks: 11 given, 3 received

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 futures io?
THINKorSWIM Scripting
ThinkOrSwim
Degiro Negative Balance Advice
Traders Hideout
QDEL
Stocks and ETFs
Macros for flatten and reverse
TradeStation
3x Fangdango
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on futures io
VWAP for stock index futures trading?
57 thanks
Coronavirus COVID-19
19 thanks
Price Action Kewltech Style
19 thanks
Trying to locate prop firm that purchased my automated trading system
11 thanks
Margins for MES
10 thanks
 
(login for full post details)
  #3 (permalink)
Hamburg Germany
 
Experience: Advanced
Platform: Multicharts, Tradestation
Broker: DTN IQ
Trading: ES
 
Posts: 2,198 since Apr 2013
Thanks: 386 given, 1,432 received


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 Visit my Facebook Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
(login for full post details)
  #4 (permalink)
Scotland
 
 
Posts: 27 since May 2019
Thanks: 11 given, 3 received

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
 
(login for full post details)
  #5 (permalink)
Agoura Hills, CA USA
 
Experience: Advanced
Platform: Tradestation&Multicharts
Broker: TradeStation
Trading: Futures & Equities
 
numberjuani's Avatar
 
Posts: 127 since Apr 2019
Thanks: 9 given, 94 received


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 futures.io mobile app

Reply With Quote
The following 2 users say Thank You to numberjuani for this post:
 
(login for full post details)
  #6 (permalink)
Scotland
 
 
Posts: 27 since May 2019
Thanks: 11 given, 3 received

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
 
(login for full post details)
  #7 (permalink)
Hamburg Germany
 
Experience: Advanced
Platform: Multicharts, Tradestation
Broker: DTN IQ
Trading: ES
 
Posts: 2,198 since Apr 2013
Thanks: 386 given, 1,432 received

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 Visit my Facebook Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #8 (permalink)
Scotland
 
 
Posts: 27 since May 2019
Thanks: 11 given, 3 received

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
 
(login for full post details)
  #9 (permalink)
Hamburg Germany
 
Experience: Advanced
Platform: Multicharts, Tradestation
Broker: DTN IQ
Trading: ES
 
Posts: 2,198 since Apr 2013
Thanks: 386 given, 1,432 received

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 Visit my Facebook Reply With Quote
The following user says Thank You to ABCTG for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Help - Code to trade between specified time.


November 25, 2019


Upcoming Webinars and Events
 

An Afternoon With futures io member TropicalTrader

Elite only
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts