NexusFi: Find Your Edge


Home Menu

 





Way to Execute Something *Once,* Then Move On?


Discussion in EasyLanguage Programming

Updated
    1. trending_up 6,756 views
    2. thumb_up 4 thanks given
    3. group 2 followers
    1. forum 12 posts
    2. attach_file 0 attachments




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

Hi Guys

For the life of me I can't figure this out. I have a couple of Variables that update continously. When the MarketPosition goes <> 0, I'd like to reset one of the Variables once, then start updating again. Example:

 
Code
Vars:
CurrentHigh (-1000 ) ,
CurrentLow  ( 1000 ) ;

IF H > CurrentHigh THEN H = CurrentHigh ;
IF L <  CurrentLow  THEN L = CurrentLow  ;

IF MarketPosition = -1 THEN "Reset CurrentLow" = 1000 ( <--reset ONCE ) and begin: 
                                                     IF L <  CurrentLow  THEN L = CurrentLow  ;

IF MarketPosition = 1 THEN "Reset CurrentHigh" = -1000 ( <--reset ONCE ) and begin: 
                                                     IF H >  CurrentHigh  THEN H = CurrentHigh  ;
Any ideas would be greatly appreciated!!!

-Brandon


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Hormuz Surges From 14% to 26.5% Intraday as Irans Answer …
Prediction Markets & Event Contracts
GDP Day: The First Economic Reckoning -- Pahlavi at 6.55 …
Prediction Markets & Event Contracts
Iran Airspace Collapses 18 Points to 15.5% While Hormuz …
Prediction Markets & Event Contracts
Warsh Opens Today, Hormuz June 19 -- WTI Below $80, Fran …
Prediction Markets & Event Contracts
Memorandum Watch: How the 60-Day MOU Framework Makes May …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
15 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643


Hi Brandon,

there are several ways to accomplish that. For example using a variable to store the market position and monitoring for changes in this variable, so you can detect if the last bar's value (or even last ticks value) of the market position was different.

Regards,

ABCTG


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


ABCTG View Post
Hi Brandon,

there are several ways to accomplish that. For example using a variable to store the market position and monitoring for changes in this variable, so you can detect if the last bar's value (or even last ticks value) of the market position was different.

Regards,

ABCTG

Thank you, ABCTG.

So basically it would say

 
Code
"If Last bar = TRUE and CurrentBar = FALSE THEN RESET"
I know how to reference the previous bar when referencing H/L
 
Code
H[1] / L[1]
And the current bar
 
Code
H[0] / L[0]
but how do you reference the last bar when pertaining to TRUE/FALSE statements?


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

I see the reserved word "LastBarOnChart" which is useful (references the currentBar).... but I can't seem to find something the references something like "PreviousBar."


Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Brandon,

I am afraid I am not following you. You don't need the last bar nor the current bar, just a variable to store the market position in. Something along the lines of the below code should get you going:
 
Code
Variables: oldMarketPosition(0);

if MarketPosition = 1 then
begin

   if oldMarketPosition <> MarketPosition then
  begin
       //this block will only be entered on the bar where the market position changed
  end ;
end ;

//update the variable after your checks
oldMarketPosition = MarketPosition;
Regards,

ABCTG


djvie11 View Post
Thank you, ABCTG.

So basically it would say

 
Code
"If Last bar = TRUE and CurrentBar = FALSE THEN RESET"
I know how to reference the previous bar when referencing H/L
 
Code
H[1] / L[1]
And the current bar
 
Code
H[0] / L[0]
but how do you reference the last bar when pertaining to TRUE/FALSE statements?


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

I guess what I'm trying to say is, I need a variable to "Turn ON for a bar, then OFF, then stay OFF." I.e, only reset it once when MarketPosition goes from 0 to <> 0 .

While that Variable is "ON" I'd reset it, then start to recalculate again once it turns off. Or you're saying that's what the below code does?


ABCTG View Post
Brandon,

I am afraid I am not following you. You don't need the last bar nor the current bar, just a variable to store the market position in. Something along the lines of the below code should get you going:
 
Code
Variables: oldMarketPosition(0);

if MarketPosition = 1 then
begin

   if oldMarketPosition <> MarketPosition then
  begin
       //this block will only be entered on the bar where the market position changed
  end ;
end ;

//update the variable after your checks
oldMarketPosition = MarketPosition;
Regards,

ABCTG


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

WAIT, I think I have it:


 
Code
Vars:
oldMarketPosition (0) ; 

IF MarketPosition = 1 THEN BEGIN
   oldMarketPosition    = 1 ;
   IF oldMarketPosition = 1 THEN Reset ;
   oldMarketPosition    = 0 ; 
END ;


Reply With Quote
  #9 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

Hi Brandon,

I would suggest testing both codes and using the print reserved word to check when the reset block is executed.

Regards,

ABCTG


djvie11 View Post
WAIT, I think I have it:


 
Code
Vars:
oldMarketPosition (0) ; 

IF MarketPosition = 1 THEN BEGIN
   oldMarketPosition    = 1 ;
   IF oldMarketPosition = 1 THEN Reset ;
   oldMarketPosition    = 0 ; 
END ;


Follow me on X Reply With Quote
  #10 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643


If you actually only want to do it once and not once per trade, you could also look at the reserved word "once" or simply initialize your variable with the reset value. However from your code it looks more like you are trying to track the high while you are in a position, which will likely mean you want to reset the variable at the beginning of every trade.

Regards,

ABCTG


djvie11 View Post
I guess what I'm trying to say is, I need a variable to "Turn ON for a bar, then OFF, then stay OFF." I.e, only reset it once when MarketPosition goes from 0 to <> 0 .


Follow me on X Reply With Quote
Thanked by:




Last Updated on August 3, 2018


© 2026 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 - Downloads - Top
no new posts