Posted By: dr_panther
Strange behavior assigning dayHigh / dayLow - 09/11/16 21:28
Post Edit:
The title should be: Strange behavior assigning dayHigh / dayLow
I try to get the daily high/low for a defined open range of the New York session for a stock. When assigning the dayLow(ET,0) to a static variable I get other values then assigning is to a local variable in the same code block. What is the reason for that?
writes into the log: please see that DH and dh_1 are different.
DH is a static variable.
*** Debug INSIDE market open range: Bar Date 21.01.15 15:35:00
DH: 110.050003,dh_1 110.139999, DL: 108.269997, dayLow(ET,0) 108.269997, ,StartMarket 830, EndMarket 1030
When I move the DH variable assignment below the DL, the values for DH and dh_1 are correct but the value for the daily low get incorrect.
returns: here the daily highs (DH, dh_1) are correct but the
daily lows (DH and dayLow(ET,0) ) are incorrect.
*** Debug INSIDE market open range: Bar Date 21.01.15 15:35:00
DH: 110.139999,dh_1 110.139999, DL: 109.900002, dayLow(ET,0) 108.269997, ,StartMarket 830, EndMarket 1030
So literally by just moving the position of the line of code in the same block changes the value, how is this possible?
Full working script:
The title should be: Strange behavior assigning dayHigh / dayLow
I try to get the daily high/low for a defined open range of the New York session for a stock. When assigning the dayLow(ET,0) to a static variable I get other values then assigning is to a local variable in the same code block. What is the reason for that?
Code:
if( !is_after_or and ltod(ET,0) > EndMarket ) { DH = dayHigh(ET,0); // <---- DL = dayLow(ET,0); double dh_1 = dayHigh(ET,0); // <---- is_new_day = 0; is_after_or = true; string msg_text = strf( "\n*** Debug INSIDE market open range: Bar Date %s \nDH: %f,dh_1 %f, DL: %f, dayLow(ET,0) %f, ,StartMarket %d, EndMarket %d ", datetime(), DH,dh_1 ,DL, dayLow(ET,0), StartMarket, EndMarket ); if( debug ) print(TO_LOG,msg_text); }
writes into the log: please see that DH and dh_1 are different.
DH is a static variable.
*** Debug INSIDE market open range: Bar Date 21.01.15 15:35:00
DH: 110.050003,dh_1 110.139999, DL: 108.269997, dayLow(ET,0) 108.269997, ,StartMarket 830, EndMarket 1030
When I move the DH variable assignment below the DL, the values for DH and dh_1 are correct but the value for the daily low get incorrect.
Code:
// DH = dayHigh(ET,0); commented DL = dayLow(ET,0); DH = dayHigh(ET,0); // moved here from above
returns: here the daily highs (DH, dh_1) are correct but the
daily lows (DH and dayLow(ET,0) ) are incorrect.
*** Debug INSIDE market open range: Bar Date 21.01.15 15:35:00
DH: 110.139999,dh_1 110.139999, DL: 109.900002, dayLow(ET,0) 108.269997, ,StartMarket 830, EndMarket 1030
So literally by just moving the position of the line of code in the same block changes the value, how is this possible?
Full working script:
Code:
#include <profile.c> int debug = 1; function run() { set(LOGFILE); BarPeriod =5; LookBack = 60;//40*24+1; UnstablePeriod=10; Hedge = 0; //Stop = 15 * PIP; //Trail = 10 * PIP; Spread=0.0; Lots=100; StartDate = 20150101; EndDate = 20150202; /////////////////////////////////////////////////////////////////////////////////////////////////////// int marketstart = 930; int marketend=1600; vars Price = series(priceClose()); StartMarket = 830; // open_range_start EndMarket = 1030; // end static int cur_day = 0 ,is_new_day = 1; static double DH , DL ,atr_avg; static bool is_after_or; bool is_week_day=ldow(ET,0) <= FRIDAY; vars crosses = series(0); /// EVERY RUN // asset("APPL"); TimeFrame=24; atr_avg = (0.05 *((ATR(10) + ATR(30))/2)); TimeFrame=1; /////////////////// / N E W - D A Y ////////////////////////////////////////////////////// if ( is_week_day && day(0) != cur_day){ // new day cur_day = day(0); is_new_day = 1; is_after_or = false; } ////////////////////// Market Open range///////////////////////////////////////////////////////////////////////////////// if( !is_after_or and ltod(ET,0) > EndMarket ) { DL = dayLow(ET,0); DL = dayLow(ET,0); DH = dayHigh(ET,0); double dh_1 = dayHigh(ET,0); is_new_day = 0; is_after_or = true; string msg_text = strf( "\n*** Debug INSIDE market open range: Bar Date %s \nDH: %f,dh_1 %f, DL: %f, dayLow(ET,0) %f, ,StartMarket %d, EndMarket %d ", datetime(), DH,dh_1 ,DL, dayLow(ET,0), StartMarket, EndMarket ); if( debug ) print(TO_LOG,msg_text); } }