NexusFi: Find Your Edge


Home Menu

 





Cross Over Cross Under


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Joe50 with 4 posts (0 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 SMCJB with 1 posts (0 thanks)
    4. looks_4 ABCTG with 1 posts (1 thanks)
    1. trending_up 3,034 views
    2. thumb_up 2 thanks given
    3. group 5 followers
    1. forum 8 posts
    2. attach_file 0 attachments




 
Search this Thread

Cross Over Cross Under

  #1 (permalink)
Joe50
HONOLULU
 
Posts: 23 since Feb 2019
Thanks Given: 6
Thanks Received: 3

Hello to all and thankyou for reading this;

I am trying to get this code to work using 5 minute bars:

If Low Crosses below Value1 and High Crosses above Value 2 then
Buy Next Bar at stop;

My problem is that the Low cross and the High cross do not occur at the same time

What I do not know how to do is to say is is the high crosses Value 2 , lets say at 10:55 then sell next bar if Low crosses below Value 1. So , let's say Value 2 occurs at 10:55 and value 1 occurs at 11:45; how is this coded ?

The key is that Value 2 must occur before value 1 is activated.

Thankyou

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
Quantum physics & Trading dynamics
The Elite Circle
 
  #3 (permalink)
 
SMCJB's Avatar
 SMCJB 
Houston TX
Legendary Market Wizard
 
Experience: Advanced
Platform: TT and Stellar
Broker: Advantage Futures
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
Frequency: Many times daily
Duration: Never
Posts: 5,049 since Dec 2013
Thanks Given: 4,388
Thanks Received: 10,207



Joe50 View Post
Hello to all and thankyou for reading this;

I am trying to get this code to work using 5 minute bars:

If Low Crosses below Value1 and High Crosses above Value 2 then
Buy Next Bar at stop;

My problem is that the Low cross and the High cross do not occur at the same time

What I do not know how to do is to say is is the high crosses Value 2 , lets say at 10:55 then sell next bar if Low crosses below Value 1. So , let's say Value 2 occurs at 10:55 and value 1 occurs at 11:45; how is this coded ?

The key is that Value 2 must occur before value 1 is activated.

Thankyou

Calculations are performed every bar, so if the two conditions don't occur on the same bar they will never trigger. So you need to keep a track of this occurring on previous bars. There's many different ways you can do this depending upon how recently/close together you want the two conditions to happen. One way would be to use the mro function for example
Value3 = MRO(Low crosses below value1, 10, 1);
Value4 = MRO(High crosses above value2, 10, 1);

If value3 > -1 and value4 > -1 then buy next bar at market;
will issue a buy if order if both conditions have been met in the last 10 bars.

Reply With Quote
  #4 (permalink)
 SidewalkAerobics 
Los Angels
 
Experience: Intermediate
Platform: MultiChart
Trading: Emini ES
Posts: 115 since Aug 2018
Thanks Given: 173
Thanks Received: 71


Joe50 View Post
Hello to all and thankyou for reading this;

I am trying to get this code to work using 5 minute bars:

If Low Crosses below Value1 and High Crosses above Value 2 then
Buy Next Bar at stop;

My problem is that the Low cross and the High cross do not occur at the same time

What I do not know how to do is to say is is the high crosses Value 2 , lets say at 10:55 then sell next bar if Low crosses below Value 1. So , let's say Value 2 occurs at 10:55 and value 1 occurs at 11:45; how is this coded ?

The key is that Value 2 must occur before value 1 is activated.

Thankyou

You can create a variable, Keep2, to store a value. Clear it before 1055, then set it at 1055 if your condition occurs. At 1145, you will know if the condition occurred at 1055. Perhaps this could be done with less lines of code, but it will work.

Var: Keep2(0);

if time=1050 then Keep2=0; //reset Keep2

if time=1055 and high[0] crosses over Value2
then Keep2 =1; //set Keep2 if condition 1 occurs

if time=1145 and low[0] crosses Value1 and Keep2=1
then Buy 1 contract next bar at market;// enter if condition 1 and condition 2 both occurred

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

Hi Joe50,

as the other posts indicate you will likely have to split your condition into separate checks. One idea could be to store the value of CurrentBar each time the High crosses Value2. At the moment the low crosses Value1 you can check the value of CurrentBar agains the value stored in that variable and allow the entry if the cross occurred within X bars ago.

Regards,

ABCTG


Joe50 View Post
Hello to all and thankyou for reading this;

I am trying to get this code to work using 5 minute bars:

If Low Crosses below Value1 and High Crosses above Value 2 then
Buy Next Bar at stop;

My problem is that the Low cross and the High cross do not occur at the same time

What I do not know how to do is to say is is the high crosses Value 2 , lets say at 10:55 then sell next bar if Low crosses below Value 1. So , let's say Value 2 occurs at 10:55 and value 1 occurs at 11:45; how is this coded ?

The key is that Value 2 must occur before value 1 is activated.

Thankyou


Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
Joe50
HONOLULU
 
Posts: 23 since Feb 2019
Thanks Given: 6
Thanks Received: 3


ABCTG View Post
Hi Joe50,

as the other posts indicate you will likely have to split your condition into separate checks. One idea could be to store the value of CurrentBar each time the High crosses Value2. At the moment the low crosses Value1 you can check the value of CurrentBar agains the value stored in that variable and allow the entry if the cross occurred within X bars ago.

Regards,

ABCTG


Thankyou for you input, it is greatly appreciated I am still reviewing it.

Reply With Quote
  #7 (permalink)
Joe50
HONOLULU
 
Posts: 23 since Feb 2019
Thanks Given: 6
Thanks Received: 3

Still looking at it.

Thankyou for everyone's reply.

Reply With Quote
  #8 (permalink)
Joe50
HONOLULU
 
Posts: 23 since Feb 2019
Thanks Given: 6
Thanks Received: 3

It works after a few minor adjustments on my end. The code is perfect.

Thankyou !

Reply With Quote
  #9 (permalink)
Feazy
Zug, Switzerland
 
Posts: 4 since Jul 2020
Thanks Given: 0
Thanks Received: 0

Hi Joe,

how did u manage to solve your problem at the end? Would be interesting to see how u managed to adjust to code

F

Reply With Quote




Last Updated on August 31, 2020


© 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