Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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:
Any ideas would be greatly appreciated!!!
-Brandon
Can you help answer these questions from other members on NexusFi?
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.
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."
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:
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
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:
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;
Vars:
oldMarketPosition (0) ;
IF MarketPosition = 1 THEN BEGIN
oldMarketPosition = 1 ;
IF oldMarketPosition = 1 THEN Reset ;
oldMarketPosition = 0 ;
END ;
I would suggest testing both codes and using the print reserved word to check when the reset block is executed.
Regards,
ABCTG
djvie11
WAIT, I think I have it:
Vars:
oldMarketPosition (0) ;
IF MarketPosition = 1 THEN BEGIN
oldMarketPosition = 1 ;
IF oldMarketPosition = 1 THEN Reset ;
oldMarketPosition = 0 ;
END ;
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
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 .