NexusFi: Find Your Edge


Home Menu

 





Buy/Sell when price crosses high/low for the day


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one jessehhhh with 6 posts (0 thanks)
    2. looks_two loantelligence with 4 posts (0 thanks)
    3. looks_3 demccarthy with 1 posts (0 thanks)
    4. looks_4 Bietto with 1 posts (0 thanks)
    1. trending_up 4,951 views
    2. thumb_up 0 thanks given
    3. group 6 followers
    1. forum 14 posts
    2. attach_file 2 attachments




 
Search this Thread

Buy/Sell when price crosses high/low for the day

  #1 (permalink)
jessehhhh
Montclair
 
Posts: 17 since Nov 2018
Thanks Given: 0
Thanks Received: 0

I'm trying to write a strategy that looks at the first hour of trading and then buys or sells short based on the price after that hour. if the price moves under the low of the hour I want to sellshort, and vice versa for the high. intrabar order generation is true as I want to enter the trade as soon as the price crosses one of the thresholds.

My code looks something like

Value1 = lowd(0)
Value2 = highd(0)


If time>1030 and close>value2 then buy next bar at market

else

if time <1030 and close<value1 then sellshort next bar at market
End;

For some reason this isn't working as looking back over years of data generates 0 trades.

Appreciate anyone who can help!

Thanks

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
Quant vue
Trading Reviews and Vendors
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
 
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


jessehhhh,

Your variables Value1 and Value2 keep getting updated with every new bar. They will always hold the current high and low of the day and therefore your condition basically states close > highd(0) and close < lowd(0) which will never evaluate to true.
You can for example only update variable values until a certain time using conditional branching i.e. "if Time <= 1030 then begin...".

Apart from that I would suggest using meaningful variable names instead of the generic ones as this will help you in creating code that is easier to read and understand and in turn might say for sometime the future.

Regards,

ABCTG


jessehhhh View Post
I'm trying to write a strategy that looks at the first hour of trading and then buys or sells short based on the price after that hour. if the price moves under the low of the hour I want to sellshort, and vice versa for the high. intrabar order generation is true as I want to enter the trade as soon as the price crosses one of the thresholds.

My code looks something like

Value1 = lowd(0)
Value2 = highd(0)


If time>1030 and close>value2 then buy next bar at market

else

if time <1030 and close<value1 then sellshort next bar at market
End;

For some reason this isn't working as looking back over years of data generates 0 trades.

Appreciate anyone who can help!

Thanks


Follow me on Twitter Reply With Quote
  #4 (permalink)
jessehhhh
Montclair
 
Posts: 17 since Nov 2018
Thanks Given: 0
Thanks Received: 0

Thank you ABCTG! that makes sense.

Would you be able to point me in the direction of how to calculate the high and low from the first hour and store that value?

I'm not sure i understood your branching part of that was trying to explain how to do it.

Thanks!

Reply With Quote
  #5 (permalink)
 loantelligence 
Syracuse, NY
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures/Zen-Fire
Trading: NQ
Posts: 218 since Jan 2011
Thanks Given: 31
Thanks Received: 189

These are instructions are for Strategy Analyzer....or a programmer

both comparisons for High and Low breakouts should be greater than or equal to 1030....your current low is checking for less than 1030????...when looking for your breakout both times should be greater than or equal to 1030....

so you can start by setting your high value and low value on your first tab...and only execute that once...set a switch to never execute it again....

and on tab2 check every subsequent bar check to see if the high is greater than the high value and time is less than 1030 then if so update the high value...do the same for the low value...if the low is less than low value and time is less than 1030 update the low value.....
next tab ...if time is equal to or greater than 1030 and high is greater than high value...go long...set variable1 =1....same for low if time is greater than or equal to 1030 and low is less than low value ...go short...set variable2 =1. set a switch so this only executes once otherwise you will be going long/short on every bar....by using two variables you can satisfy both long and short...happening at different times...so you may go long at one time and short at another

setting a switch would be like variable0 equal 1.....so when you want to execute something only once...your first stmt would be if variable0 not equal 1...execute the tab....and then set variable0 = 1 the tab will only execute when variable0 not equal 1.....
so when you find your breakout....just use variable1 as a switch for high value and variable2 for low....anytime you turn off your switch....you can check for high or low again...


Something to think about......why use any times at all.....as the market goes higher you go long....if it goes lower...you go short....follow it up or follow it down.....Hmmmmm….as you go long you continue to update your high value....as well as doing the same for low...

Reply With Quote
  #6 (permalink)
jessehhhh
Montclair
 
Posts: 17 since Nov 2018
Thanks Given: 0
Thanks Received: 0

Thanks Loantelligence!

The <1030 was a type should have been greater!

I'm very new to this so is there any sort of example somewhere of that sort of setup or something similar I can work through? I've been trying to teach myself easylanguage but I wouldn't say i'm proficient enough to take create what you mentionedso easily.

Also just want to thank you for taking the time!

Reply With Quote
  #7 (permalink)
 loantelligence 
Syracuse, NY
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures/Zen-Fire
Trading: NQ
Posts: 218 since Jan 2011
Thanks Given: 31
Thanks Received: 189

are you using NT7 or NT8......the Strategy Analyzer in NT7 is very easy to use.....and learn you could be writing strategies in no time....with no programming...

Reply With Quote
  #8 (permalink)
jessehhhh
Montclair
 
Posts: 17 since Nov 2018
Thanks Given: 0
Thanks Received: 0

Im actually using tradestation.

I also don't understand the part of your post about using times at all? I pretty much want the dust to settle and use the hour bar range as the breakout decision maker.

Reply With Quote
  #9 (permalink)
 loantelligence 
Syracuse, NY
 
Experience: Intermediate
Platform: Ninja Trader
Broker: Mirus Futures/Zen-Fire
Trading: NQ
Posts: 218 since Jan 2011
Thanks Given: 31
Thanks Received: 189

set your breakout time to be a variable....and you can look at 5 min, or 10 min or 15 mins or an hour....anytime..... you may be pleasantly surprised....

by not setting any time variable....you are always looking for the next breakout....and once you go long or short you keep updating you high value or low value...…...then when I breaks it again... you go long or short again...basically following the market down or up....

Reply With Quote
  #10 (permalink)
jessehhhh
Montclair
 
Posts: 17 since Nov 2018
Thanks Given: 0
Thanks Received: 0


Thanks loantelligence.

I know this is probably very simple but I don't think im following. is there any sort of preexisting code that creates the breakout into a variable and then maybe from that I can understand the second part as well. I learn better that way.

still very new so apologies for not understanding everything.
Thanks

Reply With Quote




Last Updated on May 24, 2021


© 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