NexusFi: Find Your Edge


Home Menu

 





Coding a "Highest High of an open position"


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ABCTG with 14 posts (9 thanks)
    2. looks_two djvie11 with 13 posts (0 thanks)
    3. looks_3 SMCJB with 2 posts (4 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 8,932 views
    2. thumb_up 13 thanks given
    3. group 4 followers
    1. forum 29 posts
    2. attach_file 0 attachments




 
Search this Thread

Coding a "Highest High of an open position"

  #21 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1

And if it helps to see what I'm talking about, this is the whole thing. Can you see anywhere it wouldn't be updating properly? Or do you think this is more of a job for a couple Arrays? Thanks for your time again!!

 
Code
Variables:
EnterHighestHigh (0) ,
EnterHighStore   (0) ,
EnterLowestLow   (0) ,
EnterLowStore    (0) ,
ExitHighestHigh  (0) ,
ExitHighStore    (0) ,
ExitLowStore     (0) ,
ExitLowestLow    (0) ;


IF MarketPosition <> 0 THEN BEGIN
EnterHighStore   = 0 ;
EnterLowStore    = 0 ; 
EnterHighestHigh = 0 ;
EnterLowestLow   = 0 ; END ;

If MarketPosition = 0 OR MarketPosition = 1 THEN BEGIN
ExitLowStore =  0 ;
ExitLowestLow = 0 ; END ;

If MarketPosition = 0 OR MarketPosition = -1 THEN BEGIN
ExitHighStore   =  0 ;
ExitHighestHigh =  0 ; END ;


IF MarketPosition = 0 THEN BEGIN
EnterHighStore = H of data2 ;
EnterLowStore  = L of data2 ;
IF H of data1 > EnterHighStore THEN EnterHighStore = H of data1 ;
IF L of data1 < EnterLowStore  THEN EnterLowStore  = L of data1 ; 
EnterHighestHigh = EnterHighStore ;  
EnterLowestLow   = EnterLowStore ; END ;
	

IF MarketPosition = 1 THEN BEGIN 
ExitHighStore = H of data1 ;
IF H of data1 > ExitHighStore THEN ExitHighStore =  H of data1 ;
ExitHighestHigh = ExitHighStore ;  END ;

If MarketPosition = -1 THEN BEGIN
ExitLowStore = L of data1 ;
IF L of data1 < ExitLowStore THEN ExitLowStore  = L of data1 ; 
ExitLowestLow = ExitLowStore ; END ;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
What broker to use for trading palladium futures
Commodities
How to apply profiles
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
  #22 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Brandon,

it appears you have an incorrect understanding of the "maximum number of bars the study will reference" feature.

You can read more here under the two links:
Maximum Number of Bars Study Will Reference Setting
https://www.multicharts.com/trading-software/index.php/Default_Study_Properties

They are just for initial calculations, before your code actually starts displaying/trading.

Regards,

ABCTG


djvie11 View Post
So I've had a new revelation here .. the code below works, and I do "reset" all the variables when "MarketPosition <> 0".....
HOWEVER... I found that the more I increase the "maximum number of bars the study will reference" under the properties tab, the better the strategy performs.

I understand the concept that the strategy will only look back "x amount of bars," but that's why I wanted to create variables so it can "record" information as it happened so I can reference that information PAST the "maximum number of bars the study will reference"

Any ideas? Hopefully you're not getting tired of me yet!!

 
Code
Variables: EnterHighestHigh(0) , EnterHighStore(0) , EnterLowestLow(0) , EnterLowStore(0) ;

IF MarketPosition = 0 THEN BEGIN
EnterHighStore = H of data2 ;
EnterLowStore  = L of data2 ; 
IF H of data1 > EnterHighStore THEN EnterHighStore = H of data1 ;
IF L of data1 < EnterLowStore  THEN EnterLowStore  = L of data1 ; 
EnterHighestHigh = EnterHighStore ; 
EnterLowestLow   = EnterLowStore ; END ;


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


Brandon,

I am sorry, but I don't understand why you do what you do within your code. Why the multiple resets?
Why still resets while in a position?
You might want to add some comments to your code blocks, explaining why you do what you do.

From the code I would say, you are not getting what you have in mind.

I would strongly suggest to use the print reserved word and check when your code resets variables and what happens bar by bar within your code.

Regards,

ABCTG


djvie11 View Post
And if it helps to see what I'm talking about, this is the whole thing. Can you see anywhere it wouldn't be updating properly? Or do you think this is more of a job for a couple Arrays? Thanks for your time again!!

 
Code
Variables:
EnterHighestHigh (0) ,
EnterHighStore   (0) ,
EnterLowestLow   (0) ,
EnterLowStore    (0) ,
ExitHighestHigh  (0) ,
ExitHighStore    (0) ,
ExitLowStore     (0) ,
ExitLowestLow    (0) ;


IF MarketPosition <> 0 THEN BEGIN
EnterHighStore   = 0 ;
EnterLowStore    = 0 ; 
EnterHighestHigh = 0 ;
EnterLowestLow   = 0 ; END ;

If MarketPosition = 0 OR MarketPosition = 1 THEN BEGIN
ExitLowStore =  0 ;
ExitLowestLow = 0 ; END ;

If MarketPosition = 0 OR MarketPosition = -1 THEN BEGIN
ExitHighStore   =  0 ;
ExitHighestHigh =  0 ; END ;


IF MarketPosition = 0 THEN BEGIN
EnterHighStore = H of data2 ;
EnterLowStore  = L of data2 ;
IF H of data1 > EnterHighStore THEN EnterHighStore = H of data1 ;
IF L of data1 < EnterLowStore  THEN EnterLowStore  = L of data1 ; 
EnterHighestHigh = EnterHighStore ;  
EnterLowestLow   = EnterLowStore ; END ;
	

IF MarketPosition = 1 THEN BEGIN 
ExitHighStore = H of data1 ;
IF H of data1 > ExitHighStore THEN ExitHighStore =  H of data1 ;
ExitHighestHigh = ExitHighStore ;  END ;

If MarketPosition = -1 THEN BEGIN
ExitLowStore = L of data1 ;
IF L of data1 < ExitLowStore THEN ExitLowStore  = L of data1 ; 
ExitLowestLow = ExitLowStore ; END ;


Follow me on Twitter Reply With Quote
Thanked by:
  #24 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1


ABCTG View Post
Brandon,

I am sorry, but I don't understand why you do what you do within your code. Why the multiple resets?
Why still resets while in a position?
You might want to add some comments to your code blocks, explaining why you do what you do.

From the code I would say, you are not getting what you have in mind.

I would strongly suggest to use the print reserved word and check when your code resets variables and what happens bar by bar within your code.

Regards,

ABCTG

Hello again, ABCTG!

I am now convinced I need to be using Arrays to capture the data I need so I can retrieve it at a later time in the chart. This is my first time using arrays. I've scoured all the information out there and have come up with the code below. It compiles just fine but when I apply it to the chart it gives me an error message: Message: Error in Study... Array bounds. Wrong index value: 1. Any idea why?

I just want my arrays to do 2 things:
1) capture each new High or Low to use at a later date (either data1 or data2)
2) reset each Array value depending on MarketPosition

As always, your input is greatly appreciated!

 
Code
Array: 
intrabarpersist  HighOfData2[](0) , //Dynamic arrays are the best option as I don't know how many values will be stored
intrabarpersist  LowOfData2 [](0) ,
intrabarpersist  HighofData1[](0) ,
intrabarpersist  LowOfData1 [](0) ;


IF MarketPosition <> 0 THEN BEGIN // I'm trying to reset the Array's value's here 
Array_SetValRange (HighofData2,0 ,0, 0) ; 
Array_SetValRange (LowofData2, 0 ,0, 0); 
END ;

If MarketPosition = 0 OR MarketPosition = -1 THEN BEGIN // I'm trying to reset the Array's value's here 
Array_SetValRange (HighOfData1, 0, 0, 0) ; 
END ;

If MarketPosition = 0 OR MarketPosition = 1 THEN BEGIN // I'm trying to reset the Array's value's here 
Array_SetValRange (LowOfData1, 0, 0, 0 ) ; 
END ; 

HighofData2[0] = H of data2 ; //Looking input each new high (or Low) into the dynamic array
LowofData2 [0] = L of data2 ;
HighofData1[0] = H of data1 ;
LowofData1 [0] = L of data1 ;

Value1 = HighestArray (HighofData2, 0) ; // Looking to pull out the highest high off all the recorded information in this array
Value2 = LowestArray  (LowOfData2,  0) ;
Value3 = HighestArray (HighofData1, 0) ;
Value4 = LowestArray  (LowofData1,  0) ;

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

Brandon,

why are you now convinced that you need to use Arrays? Based on what you wrote before, I don't see the need to make it unnecessarily complex.

What were your findings when you applied the print reserved word to your code to "check when your code resets variables and what happens bar by bar within your code"?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #26 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1

I believe arrays are the way to go because the trades are not adding up with variables. When I manually calculate them they're acting much different - like the variables aren't updating on higher highs/ lower lows (i.e., they only update once throughout each trade).

The print log statement I'm using is "Print( File(“c:\Users\Brandon\Desktop\MyPRINT.txt”),
Date, Time, Close);" - but I'm not getting any useful information from that. To be honest, I haven't used the print function often.

Can you suggest better print parameters that would help me decode this a bit better? Much thanks!
-brandon

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

djvie11,

it matters more where you place the print statements in the code - best at multiple times to "check when your code resets variables and what happens bar by bar within your code".
So you will need something to distinguish between the different print statements (i.e. a string that tells you which print statement was responsible for what print exactly).
Other than that you'll need the time and date as you do it already. You just might want to change the date format to something more user friendly, but if and how you do that is up to you (and the platform you use).

Regards,

ABCTG

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


djvie11 View Post
[...] like the variables aren't updating on higher highs/ lower lows (i.e., they only update once throughout each trade). [...]

Brandon,

that's not a problem of the variables, but because your code tells the platform to do that. The print statements will show you were it goes wrong.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #29 (permalink)
djvie11
Chicago, IL
 
Posts: 52 since Jul 2013
Thanks Given: 29
Thanks Received: 1


ABCTG View Post
Brandon,

that's not a problem of the variables, but because your code tells the platform to do that. The print statements will show you were it goes wrong.

Regards,

ABCTG

Man, the print function is pretty awesome! So my suspicions were correct (it's not working properly). Obviously it's because I have it coded wrong. Below is the code, and I also copy/pasted several instances on why it's not working correctly. Can you see anything I may have missed here?

ex1: [ EnterHigh is only supposed to change with a HIGHER high, EnterLow should only change when LOWER]
EnterHigh 1.3787 / ExitHigh -1000.0000 / EnterLow 1.3683 / ExitLow 1000.0000
EnterHigh 1.3787 / ExitHigh -1000.0000 / EnterLow 1.3640 / ExitLow 1000.0000
EnterHigh 1.3787 / ExitHigh -1000.0000 / EnterLow 1.3683 / ExitLow 1000.0000
EnterHigh 1.3793 / ExitHigh -1000.0000 / EnterLow 1.3640 / ExitLow 1000.0000
EnterHigh 1.3787 / ExitHigh -1000.0000 / EnterLow 1.3683 / ExitLow 1000.0000

ex2: [ If EnterHigh is populated with a number, so should EnterLow ]
EnterHigh 1.3516 / ExitHigh -1000.0000 / EnterLow 0.0000 / ExitLow 1000.0000
EnterHigh 1.3516 / ExitHigh -1000.0000 / EnterLow 0.0000 / ExitLow 1000.0000
EnterHigh 1.3516 / ExitHigh -1000.0000 / EnterLow 0.0000 / ExitLow 1000.0000
EnterHigh 1.3516 / ExitHigh -1000.0000 / EnterLow 0.0000 / ExitLow 1000.0000

ex3: [ExitHigh should only change if it makes a HigherHigh ]
EnterHigh -1000.0000 / ExitHigh 1.3757 / EnterLow 1000.0000 / ExitLow 1000.0000
EnterHigh -1000.0000 / ExitHigh 1.3754 / EnterLow 1000.0000 / ExitLow 1000.0000
EnterHigh -1000.0000 / ExitHigh 1.3728 / EnterLow 1000.0000 / ExitLow 1000.0000
EnterHigh -1000.0000 / ExitHigh 1.3757 / EnterLow 1000.0000 / ExitLow 1000.0000

ex4: [ Example of ExitLow going up instead of only down ]
EnterHigh -1000.0000 / ExitHigh -1000.0000 / EnterLow 1000.0000 / ExitLow 1.3640
EnterHigh -1000.0000 / ExitHigh -1000.0000 / EnterLow 1000.0000 / ExitLow 1.3683


 
Code
Variables:
EnterHighestHigh  (0) ,
EnterLowestLow    (0) ,
ExitHighestHigh   (0) ,
ExitLowestLow     (0) ;

IF MarketPosition <> 0 THEN BEGIN
EnterHighestHigh  = -1000 ;
EnterLowestLow    =  1000 ;  END ; 

If MarketPosition = 0 OR MarketPosition = -1 THEN BEGIN
ExitHighestHigh  =  -1000 ; END ; 


If MarketPosition = 0 OR MarketPosition = 1 THEN BEGIN
ExitLowestLow    = 1000 ; END ; 


IF MarketPosition = 0 THEN BEGIN
IF H of data2 >  EnterHighestHigh THEN EnterHighestHigh = H of data2 ;
IF L of data2 <  EnterLowestLow   THEN EnterLowestLow   = L of data2 ; END ; 


IF MarketPosition = 1 THEN BEGIN 
If H of data1 >  ExitHighestHigh THEN ExitHighestHigh   = H of data1 ; END ;
 
If MarketPosition = -1 THEN BEGIN
IF L of data1 <  ExitLowestLow  THEN ExitLowestLow     =  L of data1 ; END ;

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


Brandon,

I don't know where you put the prints, so I can't tell. However with using the print statement you have a great way of finding out what is going on internally.
Include one at every point in your code where you reset/update your tracking variables. Then look at the results and ask yourself if this update/result is actually occurring where I want it to happen and if this helps you in getting what you want.

One question could be: Does it help me if I reset my tracking variables constantly while I am long or short? Can I track the high/low of a position this way or would I lose the information with every reset?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on June 1, 2017


© 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