# Problem with flags

#### Jompatan

##### New member
Hello, I am new to all this, I have the following problem:
I need that from a certain condition fulfilled (A) I can do an operation only once (in this case add 1 point to the counter), and then do another different operation (in this case add 10 points to the counter).
The problem is that I cannot modify a variable that is used in the IF condition.

def A=1;
def counter;
if A==1 {
counter= 1+counter;
A=0;
}else{
counter= 10+counter;
}
plot prueba= A;

Value never assigned to a at 6:1
Value never assigned to a at 6:1

def counter = if A == 1 then 1 + counter else if a==0 then 10 + counter else 0;
plot prueba = counter;

not a lot of info to go on but try this

Thanks for answering, but actually I need to do many more operations within the true and false condition.

def A = 1;

if A == 1 {
MANY OPERATIONS
A = 0;----------------------->>>> Here I want to change the value of A so that after doing the operations on the true side, it will never enter again.
} else {
MANY OPERATIONS
}

left me confused so think you need to be more specific

It's a secret. Ok, I want to try a strategy with backtesting and as an example I am going to assume the following exercise (remember that it is an example):
I have a starting capital of \$ 1000 and I am going to trade long on all the bars (just to understand it). The first operation will be (1000 / shares purchased) * profit.
From the second my capital will no longer be 1000, and that's where my problem begins to know the new profits according to the new capital.

declare lower;
input investment = 1000;
def profit = close-open;
def A = 1 + A ;
def total;

if A == 1 {
total = round((investment/ open), 0) * profit;
} else {
total = round((total / open), 0) * profit;
}
def totals = total + total;

plot data = totals;

This example doesn't throw any error in the code, but it doesn't show results, so there is something wrong.

### Not the exact question you're looking for?

87k+ Posts
195 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?